diff --git a/posthog/hogql/test/__snapshots__/test_resolver.ambr b/posthog/hogql/test/__snapshots__/test_resolver.ambr index f0ae317ac0843..a9f111071fbd1 100644 --- a/posthog/hogql/test/__snapshots__/test_resolver.ambr +++ b/posthog/hogql/test/__snapshots__/test_resolver.ambr @@ -2065,360 +2065,936 @@ ] select_from: { table: { - select: [ - { - alias: "uuid" - expr: { - chain: [ - "uuid" - ] + initial_select_query: { + select: [ + { + alias: "uuid" + expr: { + chain: [ + "uuid" + ] + type: + } + hidden: True type: - } - hidden: True - type: - }, - { - alias: "event" - expr: { - chain: [ - "event" - ] + }, + { + alias: "event" + expr: { + chain: [ + "event" + ] + type: + } + hidden: True type: - } - hidden: True - type: - }, - { - alias: "properties" - expr: { - chain: [ - "properties" - ] + }, + { + alias: "properties" + expr: { + chain: [ + "properties" + ] + type: + } + hidden: True type: - } - hidden: True - type: - }, - { - alias: "timestamp" - expr: { - chain: [ - "timestamp" - ] + }, + { + alias: "timestamp" + expr: { + chain: [ + "timestamp" + ] + type: + } + hidden: True type: - } - hidden: True - type: - }, - { - alias: "distinct_id" - expr: { - chain: [ - "distinct_id" - ] + }, + { + alias: "distinct_id" + expr: { + chain: [ + "distinct_id" + ] + type: + } + hidden: True type: - } - hidden: True - type: - }, - { - alias: "elements_chain" - expr: { - chain: [ - "elements_chain" - ] + }, + { + alias: "elements_chain" + expr: { + chain: [ + "elements_chain" + ] + type: + } + hidden: True + type: + }, + { + alias: "created_at" + expr: { + chain: [ + "created_at" + ] + type: + } + hidden: True + type: + }, + { + alias: "$session_id" + expr: { + chain: [ + "$session_id" + ] + type: + } + hidden: True + type: + }, + { + alias: "$window_id" + expr: { + chain: [ + "$window_id" + ] + type: + } + hidden: True + type: + }, + { + alias: "person_id" + expr: { + args: [ + { + args: [ + { + args: [ + { + alias: "distinct_id" + expr: { + chain: [ + "override", + "distinct_id" + ] + type: { + name: "distinct_id" + table_type: { + field: "override" + lazy_join: { + from_field: [ + "distinct_id" + ], + join_function: , + join_table: { + fields: { + distinct_id: {}, + person: {}, + person_id: {}, + team_id: {} + } + }, + to_field: None + } + table_type: + } + } + } + hidden: True + type: { + alias: "distinct_id" + type: + } + } + ] + distinct: False + name: "empty" + type: { + arg_types: [ + { + data_type: "str" + nullable: False + } + ] + name: "empty" + return_type: { + data_type: "unknown" + nullable: True + } + } + } + ] + distinct: False + name: "not" + type: { + arg_types: [ + + ] + name: "not" + return_type: + } + }, + { + alias: "person_id" + expr: { + chain: [ + "override", + "person_id" + ] + type: { + name: "person_id" + table_type: { + field: "override" + lazy_join: { + from_field: [ + "distinct_id" + ], + join_function: , + join_table: { + fields: { + distinct_id: {}, + person: {}, + person_id: {}, + team_id: {} + } + }, + to_field: None + } + table_type: + } + } + } + hidden: True + type: { + alias: "person_id" + type: + } + }, + { + alias: "event_person_id" + expr: { + chain: [ + "event_person_id" + ] + type: { + name: "event_person_id" + table_type: + } + } + hidden: True + type: { + alias: "event_person_id" + type: + } + } + ] + distinct: False + name: "if" + type: + } + hidden: True + type: + }, + { + alias: "$group_0" + expr: { + chain: [ + "$group_0" + ] + type: + } + hidden: True + type: + }, + { + alias: "$group_1" + expr: { + chain: [ + "$group_1" + ] + type: + } + hidden: True + type: + }, + { + alias: "$group_2" + expr: { + chain: [ + "$group_2" + ] + type: + } + hidden: True + type: + }, + { + alias: "$group_3" + expr: { + chain: [ + "$group_3" + ] + type: + } + hidden: True + type: + }, + { + alias: "$group_4" + expr: { + chain: [ + "$group_4" + ] + type: + } + hidden: True + type: + }, + { + alias: "elements_chain_href" + expr: { + chain: [ + "elements_chain_href" + ] + type: + } + hidden: True + type: + }, + { + alias: "elements_chain_texts" + expr: { + chain: [ + "elements_chain_texts" + ] + type: + } + hidden: True + type: + }, + { + alias: "elements_chain_ids" + expr: { + chain: [ + "elements_chain_ids" + ] + type: + } + hidden: True type: - } - hidden: True - type: - }, - { - alias: "created_at" - expr: { - chain: [ - "created_at" - ] + }, + { + alias: "elements_chain_elements" + expr: { + chain: [ + "elements_chain_elements" + ] + type: + } + hidden: True type: - } - hidden: True - type: - }, - { - alias: "$session_id" - expr: { - chain: [ - "$session_id" - ] + }, + { + alias: "event_person_id" + expr: { + chain: [ + "event_person_id" + ] + type: + } + hidden: True type: } - hidden: True - type: - }, - { - alias: "$window_id" - expr: { + ] + select_from: { + table: { chain: [ - "$window_id" + "events" ] type: } - hidden: True type: - }, + } + type: + } + subsequent_select_queries: [ { - alias: "person_id" - expr: { - args: [ + select_query: { + select: [ { - args: [ - { - args: [ - { - alias: "distinct_id" - expr: { - chain: [ - "override", - "distinct_id" - ] - type: { - name: "distinct_id" - table_type: { - field: "override" - lazy_join: { - from_field: [ + alias: "uuid" + expr: { + chain: [ + "uuid" + ] + type: { + name: "uuid" + table_type: { + table: { + fields: { + $group_0: {}, + $group_1: {}, + $group_2: {}, + $group_3: {}, + $group_4: {}, + $session_id: {}, + $window_id: {}, + created_at: {}, + distinct_id: {}, + elements_chain: {}, + elements_chain_elements: {}, + elements_chain_href: {}, + elements_chain_ids: {}, + elements_chain_texts: {}, + event: {}, + event_person_id: {}, + goe_0: {}, + goe_1: {}, + goe_2: {}, + goe_3: {}, + goe_4: {}, + group_0: {}, + group_1: {}, + group_2: {}, + group_3: {}, + group_4: {}, + override: {}, + pdi: {}, + person: {}, + person_id: {}, + poe: {}, + properties: {}, + session: {}, + team_id: {}, + timestamp: {}, + uuid: {} + } + } + } + } + } + hidden: True + type: { + alias: "uuid" + type: + } + }, + { + alias: "event" + expr: { + chain: [ + "event" + ] + type: { + name: "event" + table_type: + } + } + hidden: True + type: { + alias: "event" + type: + } + }, + { + alias: "properties" + expr: { + chain: [ + "properties" + ] + type: { + name: "properties" + table_type: + } + } + hidden: True + type: { + alias: "properties" + type: + } + }, + { + alias: "timestamp" + expr: { + chain: [ + "timestamp" + ] + type: { + name: "timestamp" + table_type: + } + } + hidden: True + type: { + alias: "timestamp" + type: + } + }, + { + alias: "distinct_id" + expr: { + chain: [ + "distinct_id" + ] + type: { + name: "distinct_id" + table_type: + } + } + hidden: True + type: { + alias: "distinct_id" + type: + } + }, + { + alias: "elements_chain" + expr: { + chain: [ + "elements_chain" + ] + type: { + name: "elements_chain" + table_type: + } + } + hidden: True + type: { + alias: "elements_chain" + type: + } + }, + { + alias: "created_at" + expr: { + chain: [ + "created_at" + ] + type: { + name: "created_at" + table_type: + } + } + hidden: True + type: { + alias: "created_at" + type: + } + }, + { + alias: "$session_id" + expr: { + chain: [ + "$session_id" + ] + type: { + name: "$session_id" + table_type: + } + } + hidden: True + type: { + alias: "$session_id" + type: + } + }, + { + alias: "$window_id" + expr: { + chain: [ + "$window_id" + ] + type: { + name: "$window_id" + table_type: + } + } + hidden: True + type: { + alias: "$window_id" + type: + } + }, + { + alias: "person_id" + expr: { + args: [ + { + args: [ + { + args: [ + { + alias: "distinct_id" + expr: { + chain: [ + "override", "distinct_id" - ], - join_function: , - join_table: { - fields: { - distinct_id: {}, - person: {}, - person_id: {}, - team_id: {} + ] + type: { + name: "distinct_id" + table_type: { + field: "override" + lazy_join: { + from_field: [ + "distinct_id" + ], + join_function: , + join_table: { + fields: { + distinct_id: {}, + person: {}, + person_id: {}, + team_id: {} + } + }, + to_field: None + } + table_type: } - }, - to_field: None + } } - table_type: + hidden: True + type: { + alias: "distinct_id" + type: + } + } + ] + distinct: False + name: "empty" + type: { + arg_types: [ + { + data_type: "str" + nullable: False + } + ] + name: "empty" + return_type: { + data_type: "unknown" + nullable: True } } } - hidden: True - type: { - alias: "distinct_id" - type: + ] + distinct: False + name: "not" + type: { + arg_types: [ + + ] + name: "not" + return_type: { + data_type: "unknown" + nullable: True } } - ] - distinct: False - name: "empty" - type: { - arg_types: [ - { - data_type: "str" - nullable: False + }, + { + alias: "person_id" + expr: { + chain: [ + "override", + "person_id" + ] + type: { + name: "person_id" + table_type: { + field: "override" + lazy_join: { + from_field: [ + "distinct_id" + ], + join_function: , + join_table: { + fields: { + distinct_id: {}, + person: {}, + person_id: {}, + team_id: {} + } + }, + to_field: None + } + table_type: + } } - ] - name: "empty" - return_type: { - data_type: "unknown" - nullable: True } + hidden: True + type: { + alias: "person_id" + type: + } + }, + { + alias: "event_person_id" + expr: { + chain: [ + "event_person_id" + ] + type: { + name: "event_person_id" + table_type: + } + } + hidden: True + type: { + alias: "event_person_id" + type: + } + } + ] + distinct: False + name: "if" + type: { + arg_types: [ + , + { + data_type: "str" + nullable: False + }, + { + data_type: "str" + nullable: False + } + ] + name: "if" + return_type: { + data_type: "unknown" + nullable: True } } - ] - distinct: False - name: "not" + } + hidden: True type: { - arg_types: [ - + alias: "person_id" + type: + } + }, + { + alias: "$group_0" + expr: { + chain: [ + "$group_0" ] - name: "not" - return_type: + type: { + name: "$group_0" + table_type: + } + } + hidden: True + type: { + alias: "$group_0" + type: } }, { - alias: "person_id" + alias: "$group_1" expr: { chain: [ - "override", - "person_id" + "$group_1" ] type: { - name: "person_id" - table_type: { - field: "override" - lazy_join: { - from_field: [ - "distinct_id" - ], - join_function: , - join_table: { - fields: { - distinct_id: {}, - person: {}, - person_id: {}, - team_id: {} - } - }, - to_field: None - } - table_type: - } + name: "$group_1" + table_type: } } hidden: True type: { - alias: "person_id" + alias: "$group_1" type: } }, { - alias: "event_person_id" + alias: "$group_2" expr: { chain: [ - "event_person_id" + "$group_2" ] type: { - name: "event_person_id" + name: "$group_2" table_type: } } hidden: True type: { - alias: "event_person_id" + alias: "$group_2" type: } - } - ] - distinct: False - name: "if" - type: - } - hidden: True - type: - }, - { - alias: "$group_0" - expr: { - chain: [ - "$group_0" - ] - type: - } - hidden: True - type: - }, - { - alias: "$group_1" - expr: { - chain: [ - "$group_1" - ] - type: - } - hidden: True - type: - }, - { - alias: "$group_2" - expr: { - chain: [ - "$group_2" - ] - type: - } - hidden: True - type: - }, - { - alias: "$group_3" - expr: { - chain: [ - "$group_3" - ] - type: - } - hidden: True - type: - }, - { - alias: "$group_4" - expr: { - chain: [ - "$group_4" - ] - type: - } - hidden: True - type: - }, - { - alias: "elements_chain_href" - expr: { - chain: [ - "elements_chain_href" - ] - type: - } - hidden: True - type: - }, - { - alias: "elements_chain_texts" - expr: { - chain: [ - "elements_chain_texts" - ] - type: - } - hidden: True - type: - }, - { - alias: "elements_chain_ids" - expr: { - chain: [ - "elements_chain_ids" - ] - type: - } - hidden: True - type: - }, - { - alias: "elements_chain_elements" - expr: { - chain: [ - "elements_chain_elements" - ] - type: - } - hidden: True - type: - }, - { - alias: "event_person_id" - expr: { - chain: [ - "event_person_id" + }, + { + alias: "$group_3" + expr: { + chain: [ + "$group_3" + ] + type: { + name: "$group_3" + table_type: + } + } + hidden: True + type: { + alias: "$group_3" + type: + } + }, + { + alias: "$group_4" + expr: { + chain: [ + "$group_4" + ] + type: { + name: "$group_4" + table_type: + } + } + hidden: True + type: { + alias: "$group_4" + type: + } + }, + { + alias: "elements_chain_href" + expr: { + chain: [ + "elements_chain_href" + ] + type: { + name: "elements_chain_href" + table_type: + } + } + hidden: True + type: { + alias: "elements_chain_href" + type: + } + }, + { + alias: "elements_chain_texts" + expr: { + chain: [ + "elements_chain_texts" + ] + type: { + name: "elements_chain_texts" + table_type: + } + } + hidden: True + type: { + alias: "elements_chain_texts" + type: + } + }, + { + alias: "elements_chain_ids" + expr: { + chain: [ + "elements_chain_ids" + ] + type: { + name: "elements_chain_ids" + table_type: + } + } + hidden: True + type: { + alias: "elements_chain_ids" + type: + } + }, + { + alias: "elements_chain_elements" + expr: { + chain: [ + "elements_chain_elements" + ] + type: { + name: "elements_chain_elements" + table_type: + } + } + hidden: True + type: { + alias: "elements_chain_elements" + type: + } + }, + { + alias: "event_person_id" + expr: { + chain: [ + "event_person_id" + ] + type: { + name: "event_person_id" + table_type: + } + } + hidden: True + type: { + alias: "event_person_id" + type: + } + } ] - type: + select_from: { + table: { + chain: [ + "events" + ] + type: + } + type: + } + type: { + aliases: {} + anonymous_tables: [] + columns: { + $group_0: , + $group_1: , + $group_2: , + $group_3: , + $group_4: , + $session_id: , + $window_id: , + created_at: , + distinct_id: , + elements_chain: , + elements_chain_elements: , + elements_chain_href: , + elements_chain_ids: , + elements_chain_texts: , + event: , + event_person_id: , + person_id: , + properties: , + timestamp: , + uuid: + } + ctes: {} + tables: { + events: + } + } } - hidden: True - type: + union_type: "UNION ALL" } ] - select_from: { - table: { - chain: [ - "events" - ] - type: - } - type: + type: { + types: [ + , + + ] } - type: } type: } @@ -5555,103 +6131,216 @@ # name: TestResolver.test_resolve_union_all ''' { - select: [ - { - alias: "event" - expr: { - chain: [ - "event" - ] - type: { - name: "event" - table_type: { - table: { - fields: { - $group_0: {}, - $group_1: {}, - $group_2: {}, - $group_3: {}, - $group_4: {}, - $session_id: {}, - $window_id: {}, - created_at: {}, - distinct_id: {}, - elements_chain: {}, - elements_chain_elements: {}, - elements_chain_href: {}, - elements_chain_ids: {}, - elements_chain_texts: {}, - event: {}, - event_person_id: {}, - goe_0: {}, - goe_1: {}, - goe_2: {}, - goe_3: {}, - goe_4: {}, - group_0: {}, - group_1: {}, - group_2: {}, - group_3: {}, - group_4: {}, - override: {}, - pdi: {}, - person: {}, - person_id: {}, - poe: {}, - properties: {}, - session: {}, - team_id: {}, - timestamp: {}, - uuid: {} + initial_select_query: { + select: [ + { + alias: "event" + expr: { + chain: [ + "event" + ] + type: { + name: "event" + table_type: { + table: { + fields: { + $group_0: {}, + $group_1: {}, + $group_2: {}, + $group_3: {}, + $group_4: {}, + $session_id: {}, + $window_id: {}, + created_at: {}, + distinct_id: {}, + elements_chain: {}, + elements_chain_elements: {}, + elements_chain_href: {}, + elements_chain_ids: {}, + elements_chain_texts: {}, + event: {}, + event_person_id: {}, + goe_0: {}, + goe_1: {}, + goe_2: {}, + goe_3: {}, + goe_4: {}, + group_0: {}, + group_1: {}, + group_2: {}, + group_3: {}, + group_4: {}, + override: {}, + pdi: {}, + person: {}, + person_id: {}, + poe: {}, + properties: {}, + session: {}, + team_id: {}, + timestamp: {}, + uuid: {} + } } } } } + hidden: True + type: { + alias: "event" + type: + } + }, + { + alias: "timestamp" + expr: { + chain: [ + "timestamp" + ] + type: { + name: "timestamp" + table_type: + } + } + hidden: True + type: { + alias: "timestamp" + type: + } } - hidden: True - type: { - alias: "event" + ] + select_from: { + table: { + chain: [ + "events" + ] type: } - }, + type: + } + type: { + aliases: {} + anonymous_tables: [] + columns: { + event: , + timestamp: + } + ctes: {} + tables: { + events: + } + } + } + subsequent_select_queries: [ { - alias: "timestamp" - expr: { - chain: [ - "timestamp" + select_query: { + select: [ + { + alias: "event" + expr: { + chain: [ + "event" + ] + type: { + name: "event" + table_type: { + table: { + fields: { + $group_0: {}, + $group_1: {}, + $group_2: {}, + $group_3: {}, + $group_4: {}, + $session_id: {}, + $window_id: {}, + created_at: {}, + distinct_id: {}, + elements_chain: {}, + elements_chain_elements: {}, + elements_chain_href: {}, + elements_chain_ids: {}, + elements_chain_texts: {}, + event: {}, + event_person_id: {}, + goe_0: {}, + goe_1: {}, + goe_2: {}, + goe_3: {}, + goe_4: {}, + group_0: {}, + group_1: {}, + group_2: {}, + group_3: {}, + group_4: {}, + override: {}, + pdi: {}, + person: {}, + person_id: {}, + poe: {}, + properties: {}, + session: {}, + team_id: {}, + timestamp: {}, + uuid: {} + } + } + } + } + } + hidden: True + type: { + alias: "event" + type: + } + }, + { + alias: "timestamp" + expr: { + chain: [ + "timestamp" + ] + type: { + name: "timestamp" + table_type: + } + } + hidden: True + type: { + alias: "timestamp" + type: + } + } ] + select_from: { + table: { + chain: [ + "events" + ] + type: + } + type: + } type: { - name: "timestamp" - table_type: + aliases: {} + anonymous_tables: [] + columns: { + event: , + timestamp: + } + ctes: {} + tables: { + events: + } } } - hidden: True - type: { - alias: "timestamp" - type: - } + union_type: "UNION ALL" } ] - select_from: { - table: { - chain: [ - "events" - ] - type: - } - type: - } type: { - aliases: {} - anonymous_tables: [] - columns: { - event: , - timestamp: - } - ctes: {} - tables: { - events: - } + types: [ + , + + ] } } '''