PostHog / posthog

🦔 PostHog provides open-source web & product analytics, session recording, feature flagging and A/B testing that you can self-host. Get started - free.
https://posthog.com
Other
22.05k stars 1.33k forks source link

fix(hogql): Support parsing dw properties with nested values #26321

Closed danielbachhuber closed 1 day ago

danielbachhuber commented 1 day ago

Changes

Updates property_to_expr() to handle data warehouse properties with nested values, e.g.:

 prepared_count_query.properties = [
    DataWarehousePropertyFilter(
        key=f"{column_name}.event",
        value="$feature_flag_called",
        operator=PropertyOperator.EXACT,
        type="data_warehouse",
    ),
    DataWarehousePropertyFilter(
        key=f"{column_name}.properties.{self.breakdown_key}",
        value=self.variants,
        operator=PropertyOperator.EXACT,
        type="data_warehouse",
    ),
]

Without the patch, the properties evaluate to:

sql(and(equals(events.event, '$feature_flag_called'), or(equals(`$feature/dw-trends-nov-14-v2`, 'control'), equals(`$feature/dw-trends-nov-14-v2`, 'test'))))

With the patch, the properties evaluate to:

sql(and(equals(events.event, '$feature_flag_called'), or(equals(events.properties.`$feature/dw-trends-nov-14-v2`, 'control'), equals(events.properties.`$feature/dw-trends-nov-14-v2`, 'test'))))

From https://github.com/PostHog/posthog/pull/26301

How did you test this code?

Tests should pass

Also verified that https://github.com/PostHog/posthog/pull/26301 works as expected with this patch