diff --git a/frontend/src/scenes/debug/DebugScene.tsx b/frontend/src/scenes/debug/DebugScene.tsx index 723a132162b6d..19cba38cb9d5e 100644 --- a/frontend/src/scenes/debug/DebugScene.tsx +++ b/frontend/src/scenes/debug/DebugScene.tsx @@ -35,11 +35,7 @@ function QueryDebug({ query, setQuery, queryKey }: QueryDebugProps): JSX.Element query={query} setQuery={(query) => setQuery(JSON.stringify(query, null, 2))} context={{ - showQueryEditor: - parsed && - parsed.kind == 'DataTableNode' && - parsed.source.kind == 'HogQLQuery' && - (parsed.full || parsed.showHogQLEditor), + showQueryEditor: true, }} /> )} diff --git a/posthog/hogql_queries/insights/lifecycle_query_runner.py b/posthog/hogql_queries/insights/lifecycle_query_runner.py index 307f508ebd39c..da088f11daac7 100644 --- a/posthog/hogql_queries/insights/lifecycle_query_runner.py +++ b/posthog/hogql_queries/insights/lifecycle_query_runner.py @@ -41,16 +41,29 @@ def __init__( super().__init__(query, team, timings, in_export_context) def to_query(self) -> ast.SelectQuery | ast.SelectUnionQuery: + if self.query.samplingFactor == 0: + counts_with_sampling = ast.Constant(value=0) + elif self.query.samplingFactor is not None and self.query.samplingFactor != 1: + counts_with_sampling = parse_expr( + "round(counts * (1 / {sampling_factor}))", + { + "sampling_factor": ast.Constant(value=self.query.samplingFactor), + }, + ) + else: + counts_with_sampling = parse_expr("counts") + placeholders = { **self.query_date_range.to_placeholders(), "events_query": self.events_query, "periods_query": self.periods_query, + "counts_with_sampling": counts_with_sampling, } with self.timings.measure("lifecycle_query"): lifecycle_query = parse_select( """ SELECT groupArray(start_of_period) AS date, - groupArray(counts) AS total, + groupArray({counts_with_sampling}) AS total, status FROM ( SELECT @@ -161,10 +174,11 @@ def calculate(self) -> LifecycleQueryResponse: "math": "total", } elif isinstance(self.query.series[0], EventsNode): - label = "{} - {}".format(self.query.series[0].event, val[2]) + event = self.query.series[0].event + label = "{} - {}".format("All events" if event is None else event, val[2]) action_object = { - "id": self.query.series[0].event, - "name": self.query.series[0].event, + "id": event, + "name": "All events" if event is None else event, "type": "events", "order": 0, "math": "total", diff --git a/posthog/hogql_queries/insights/test/__snapshots__/test_lifecycle_query_runner.ambr b/posthog/hogql_queries/insights/test/__snapshots__/test_lifecycle_query_runner.ambr index 962c5eecbee98..883cc0d0f3491 100644 --- a/posthog/hogql_queries/insights/test/__snapshots__/test_lifecycle_query_runner.ambr +++ b/posthog/hogql_queries/insights/test/__snapshots__/test_lifecycle_query_runner.ambr @@ -1,7 +1,7 @@ # name: TestLifecycleQueryRunner.test_sampling ' SELECT groupArray(start_of_period) AS date, - groupArray(counts) AS total, + groupArray(round(multiply(counts, divide(1, 0.1)))) AS total, status FROM (SELECT if(ifNull(equals(status, 'dormant'), 0), negate(sum(counts)), negate(negate(sum(counts)))) AS counts, diff --git a/posthog/hogql_queries/insights/test/test_lifecycle_query_runner.py b/posthog/hogql_queries/insights/test/test_lifecycle_query_runner.py index 35bfa4499119f..21e14e8596a4c 100644 --- a/posthog/hogql_queries/insights/test/test_lifecycle_query_runner.py +++ b/posthog/hogql_queries/insights/test/test_lifecycle_query_runner.py @@ -426,6 +426,7 @@ def test_lifecycle_trend(self): .calculate() .results ) + assert result[0]["label"] == "$pageview - new" assertLifecycleResults( result, @@ -437,7 +438,7 @@ def test_lifecycle_trend(self): ], ) - def test_lifecycle_trend_any_event(self): + def test_lifecycle_trend_all_events(self): self._create_events( event="$pageview", data=[ @@ -476,6 +477,8 @@ def test_lifecycle_trend_any_event(self): .results ) + assert result[0]["label"] == "All events - new" + assertLifecycleResults( result, [