mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-24 00:47:50 +01:00
Add a better test
This commit is contained in:
parent
50572087ff
commit
d31e887f57
@ -219,3 +219,29 @@
|
||||
max_bytes_before_external_group_by=0
|
||||
'''
|
||||
# ---
|
||||
# name: TestTrendsDataWarehouseQuery.test_trends_with_multiple_property_types
|
||||
'''
|
||||
SELECT arrayMap(number -> plus(toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2023-01-01 00:00:00', 6, 'UTC'))), toIntervalDay(number)), range(0, plus(coalesce(dateDiff('day', toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2023-01-01 00:00:00', 6, 'UTC'))), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2023-01-07 23:59:59', 6, 'UTC'))))), 1))) AS date,
|
||||
arrayMap(_match_date -> arraySum(arraySlice(groupArray(ifNull(count, 0)), indexOf(groupArray(day_start) AS _days_for_count, _match_date) AS _index, plus(minus(arrayLastIndex(x -> ifNull(equals(x, _match_date), isNull(x)
|
||||
and isNull(_match_date)), _days_for_count), _index), 1))), date) AS total
|
||||
FROM
|
||||
(SELECT sum(total) AS count,
|
||||
day_start AS day_start
|
||||
FROM
|
||||
(SELECT count() AS total,
|
||||
toStartOfDay(toTimeZone(e.created, 'UTC')) AS day_start
|
||||
FROM s3('http://host.docker.internal:19000/posthog/test_storage_bucket-posthog.hogql.datawarehouse.trendquery/*.parquet', 'object_storage_root_user', 'object_storage_root_password', 'Parquet', '`id` String, `prop_1` String, `prop_2` String, `created` DateTime64(3, \'UTC\')') AS e
|
||||
WHERE and(ifNull(greaterOrEquals(toTimeZone(e.created, 'UTC'), toStartOfDay(assumeNotNull(parseDateTime64BestEffortOrNull('2023-01-01 00:00:00', 6, 'UTC')))), 0), ifNull(lessOrEquals(toTimeZone(e.created, 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2023-01-07 23:59:59', 6, 'UTC'))), 0), and(equals(e.prop_1, 'a'), equals(e.prop_2, 'e')))
|
||||
GROUP BY day_start)
|
||||
GROUP BY day_start
|
||||
ORDER BY day_start ASC)
|
||||
ORDER BY arraySum(total) DESC
|
||||
LIMIT 100 SETTINGS readonly=2,
|
||||
max_execution_time=60,
|
||||
allow_experimental_object_type=1,
|
||||
format_csv_allow_double_quotes=0,
|
||||
max_ast_elements=4000000,
|
||||
max_expanded_ast_elements=4000000,
|
||||
max_bytes_before_external_group_by=0
|
||||
'''
|
||||
# ---
|
||||
|
@ -453,3 +453,49 @@ class TestTrendsDataWarehouseQuery(ClickhouseTestMixin, BaseTest):
|
||||
self.assert_column_names_with_display_type(ChartDisplayType.BOLD_NUMBER)
|
||||
self.assert_column_names_with_display_type(ChartDisplayType.WORLD_MAP)
|
||||
self.assert_column_names_with_display_type(ChartDisplayType.ACTIONS_LINE_GRAPH_CUMULATIVE)
|
||||
|
||||
@snapshot_clickhouse_queries
|
||||
def test_trends_with_multiple_property_types(self):
|
||||
table_name = self.create_parquet_file()
|
||||
|
||||
_create_event(
|
||||
distinct_id="1",
|
||||
event="a",
|
||||
properties={"prop_1": "a"},
|
||||
timestamp="2023-01-02 00:00:00",
|
||||
team=self.team,
|
||||
)
|
||||
|
||||
trends_query = TrendsQuery(
|
||||
kind="TrendsQuery",
|
||||
dateRange=InsightDateRange(date_from="2023-01-01"),
|
||||
series=[
|
||||
DataWarehouseNode(
|
||||
id=table_name,
|
||||
table_name=table_name,
|
||||
id_field="id",
|
||||
distinct_id_field="customer_email",
|
||||
timestamp_field="created",
|
||||
)
|
||||
],
|
||||
properties=clean_entity_properties(
|
||||
[
|
||||
{"key": "prop_1", "value": "a", "operator": "exact", "type": "data_warehouse"},
|
||||
{"key": "prop_2", "value": "e", "operator": "exact", "type": "data_warehouse"},
|
||||
{
|
||||
"key": "prop_1",
|
||||
"value": "a",
|
||||
"operator": "exact",
|
||||
"type": "event",
|
||||
}, # This should be ignored for DW queries
|
||||
]
|
||||
),
|
||||
)
|
||||
|
||||
with freeze_time("2023-01-07"):
|
||||
response = self.get_response(trends_query=trends_query)
|
||||
|
||||
assert response.columns is not None
|
||||
assert set(response.columns).issubset({"date", "total"})
|
||||
# Should only match the row where both prop_1='a' AND prop_2='e'
|
||||
assert response.results[0][1] == [1, 0, 0, 0, 0, 0, 0]
|
||||
|
Loading…
Reference in New Issue
Block a user