:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(hogql): make funnel trends work with quarter and year intervals (#124346)
Sam Pennington75a960959879
diff --git a/posthog/hogql/functions/clickhouse/datetime.py b/posthog/hogql/functions/clickhouse/datetime.pyindex a47a52af3dfb..98625b9e8791 100644--- a/posthog/hogql/functions/clickhouse/datetime.py+++ b/posthog/hogql/functions/clickhouse/datetime.py@@ -39,9 +39,30 @@ DATETIME_FUNCTIONS: dict[str, HogQLFunctionMeta] = {((DateTimeType(), IntervalType(), DateTimeType()), DateTimeType()),],),- "toStartOfYear": HogQLFunctionMeta("toStartOfYear", 1, 1),- "toStartOfISOYear": HogQLFunctionMeta("toStartOfISOYear", 1, 1),- "toStartOfQuarter": HogQLFunctionMeta("toStartOfQuarter", 1, 1),+ "toStartOfYear": HogQLFunctionMeta(+ "toStartOfYear",+ 1,+ 1,+ signatures=[+ ((UnknownType(),), DateType()),+ ],+ ),+ "toStartOfISOYear": HogQLFunctionMeta(+ "toStartOfISOYear",+ 1,+ 1,+ signatures=[+ ((UnknownType(),), DateType()),+ ],+ ),+ "toStartOfQuarter": HogQLFunctionMeta(+ "toStartOfQuarter",+ 1,+ 1,+ signatures=[+ ((UnknownType(),), DateType()),+ ],+ ),"toStartOfMonth": HogQLFunctionMeta("toStartOfMonth",1,diff --git a/posthog/hogql/printer/test/test_printer.py b/posthog/hogql/printer/test/test_printer.pyindex 1073e403e7e2..b63317264bc7 100644--- a/posthog/hogql/printer/test/test_printer.py+++ b/posthog/hogql/printer/test/test_printer.py@@ -3331,6 +3331,24 @@ class TestPrinter(BaseTest):printed = self._select(query)assert expected in printed, printed+ @parameterized.expand(+ [+ ("toStartOfMinute",),+ ("toStartOfHour",),+ ("toStartOfDay",),+ ("toStartOfWeek",),+ ("toStartOfMonth",),+ ("toStartOfQuarter",),+ ("toStartOfYear",),+ ("toStartOfISOYear",),+ ]+ )+ def test_to_datetime_of_start_of_interval_uses_the_plain_constructor(self, trunc_func: str):+ # Funnel trends wrap the interval bucket in toDateTime, and the parser rejects a Date (code 43).+ printed = self._expr(f"toDateTime({trunc_func}(timestamp))")+ assert "parseDateTime64BestEffort" not in printed, printed+ assert printed.startswith(f"toDateTime({trunc_func}("), printed+def test_window_functions(self):self.assertEqual(self._select(