-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1aa9cd1
commit fe648b7
Showing
2 changed files
with
258 additions
and
114 deletions.
There are no files selected for viewing
221 changes: 221 additions & 0 deletions
221
posthog/hogql/transforms/test/__snapshots__/test_lazy_tables.ambr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
# name: TestLazyJoins.test_resolve_lazy_table_as_select_table | ||
' | ||
|
||
SELECT persons.id, persons.properties___email, persons.`properties___$browser` | ||
FROM ( | ||
SELECT person.id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___email, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_1)s), ''), 'null'), '^"|"$', '') AS `properties___$browser` | ||
FROM person | ||
WHERE and(equals(person.team_id, 5), ifNull(in(tuple(person.id, person.version), ( | ||
SELECT person.id, max(person.version) AS version | ||
FROM person | ||
WHERE equals(person.team_id, 5) | ||
GROUP BY person.id | ||
HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0))), 0)) | ||
SETTINGS optimize_aggregation_in_order=1) AS persons | ||
LIMIT 10000 | ||
' | ||
--- | ||
# name: TestLazyJoins.test_resolve_lazy_table_as_table_in_join | ||
' | ||
|
||
SELECT events.event, events.distinct_id, events__pdi.person_id, persons.properties___email | ||
FROM events INNER JOIN ( | ||
SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id | ||
FROM person_distinct_id2 | ||
WHERE equals(person_distinct_id2.team_id, 5) | ||
GROUP BY person_distinct_id2.distinct_id | ||
HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0)) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id) LEFT JOIN ( | ||
SELECT person.id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___email | ||
FROM person | ||
WHERE and(equals(person.team_id, 5), ifNull(in(tuple(person.id, person.version), ( | ||
SELECT person.id, max(person.version) AS version | ||
FROM person | ||
WHERE equals(person.team_id, 5) | ||
GROUP BY person.id | ||
HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0))), 0)) | ||
SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, events__pdi.person_id) | ||
WHERE equals(events.team_id, 5) | ||
LIMIT 10 | ||
' | ||
--- | ||
# name: TestLazyJoins.test_resolve_lazy_tables | ||
' | ||
|
||
SELECT events.event, events__pdi.person_id | ||
FROM events INNER JOIN ( | ||
SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id | ||
FROM person_distinct_id2 | ||
WHERE equals(person_distinct_id2.team_id, 5) | ||
GROUP BY person_distinct_id2.distinct_id | ||
HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0)) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id) | ||
WHERE equals(events.team_id, 5) | ||
LIMIT 10000 | ||
' | ||
--- | ||
# name: TestLazyJoins.test_resolve_lazy_tables_one_level_properties | ||
' | ||
|
||
SELECT person_distinct_ids__person.`properties___$browser` | ||
FROM ( | ||
SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id | ||
FROM person_distinct_id2 | ||
WHERE equals(person_distinct_id2.team_id, 5) | ||
GROUP BY person_distinct_id2.distinct_id | ||
HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0)) AS person_distinct_ids INNER JOIN ( | ||
SELECT person.id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS `properties___$browser` | ||
FROM person | ||
WHERE and(equals(person.team_id, 5), ifNull(in(tuple(person.id, person.version), ( | ||
SELECT person.id, max(person.version) AS version | ||
FROM person | ||
WHERE equals(person.team_id, 5) | ||
GROUP BY person.id | ||
HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0))), 0)) | ||
SETTINGS optimize_aggregation_in_order=1) AS person_distinct_ids__person ON equals(person_distinct_ids.person_id, person_distinct_ids__person.id) | ||
LIMIT 10000 | ||
' | ||
--- | ||
# name: TestLazyJoins.test_resolve_lazy_tables_one_level_properties_deep | ||
' | ||
|
||
SELECT person_distinct_ids__person.`properties___$browser___in___json` | ||
FROM ( | ||
SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id | ||
FROM person_distinct_id2 | ||
WHERE equals(person_distinct_id2.team_id, 5) | ||
GROUP BY person_distinct_id2.distinct_id | ||
HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0)) AS person_distinct_ids INNER JOIN ( | ||
SELECT person.id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s, %(hogql_val_1)s, %(hogql_val_2)s), ''), 'null'), '^"|"$', '') AS `properties___$browser___in___json` | ||
FROM person | ||
WHERE and(equals(person.team_id, 5), ifNull(in(tuple(person.id, person.version), ( | ||
SELECT person.id, max(person.version) AS version | ||
FROM person | ||
WHERE equals(person.team_id, 5) | ||
GROUP BY person.id | ||
HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0))), 0)) | ||
SETTINGS optimize_aggregation_in_order=1) AS person_distinct_ids__person ON equals(person_distinct_ids.person_id, person_distinct_ids__person.id) | ||
LIMIT 10000 | ||
' | ||
--- | ||
# name: TestLazyJoins.test_resolve_lazy_tables_traversed_fields | ||
' | ||
|
||
SELECT events.event, events__pdi.person_id | ||
FROM events INNER JOIN ( | ||
SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id | ||
FROM person_distinct_id2 | ||
WHERE equals(person_distinct_id2.team_id, 5) | ||
GROUP BY person_distinct_id2.distinct_id | ||
HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0)) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id) | ||
WHERE equals(events.team_id, 5) | ||
LIMIT 10000 | ||
' | ||
--- | ||
# name: TestLazyJoins.test_resolve_lazy_tables_two_levels | ||
' | ||
|
||
SELECT events.event, events__pdi__person.id | ||
FROM events INNER JOIN ( | ||
SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id | ||
FROM person_distinct_id2 | ||
WHERE equals(person_distinct_id2.team_id, 5) | ||
GROUP BY person_distinct_id2.distinct_id | ||
HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0)) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id) INNER JOIN ( | ||
SELECT person.id | ||
FROM person | ||
WHERE and(equals(person.team_id, 5), ifNull(in(tuple(person.id, person.version), ( | ||
SELECT person.id, max(person.version) AS version | ||
FROM person | ||
WHERE equals(person.team_id, 5) | ||
GROUP BY person.id | ||
HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0))), 0)) | ||
SETTINGS optimize_aggregation_in_order=1) AS events__pdi__person ON equals(events__pdi.person_id, events__pdi__person.id) | ||
WHERE equals(events.team_id, 5) | ||
LIMIT 10000 | ||
' | ||
--- | ||
# name: TestLazyJoins.test_resolve_lazy_tables_two_levels_properties | ||
' | ||
|
||
SELECT events.event, events__pdi__person.`properties___$browser` | ||
FROM events INNER JOIN ( | ||
SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id | ||
FROM person_distinct_id2 | ||
WHERE equals(person_distinct_id2.team_id, 5) | ||
GROUP BY person_distinct_id2.distinct_id | ||
HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0)) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id) INNER JOIN ( | ||
SELECT person.id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS `properties___$browser` | ||
FROM person | ||
WHERE and(equals(person.team_id, 5), ifNull(in(tuple(person.id, person.version), ( | ||
SELECT person.id, max(person.version) AS version | ||
FROM person | ||
WHERE equals(person.team_id, 5) | ||
GROUP BY person.id | ||
HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0))), 0)) | ||
SETTINGS optimize_aggregation_in_order=1) AS events__pdi__person ON equals(events__pdi.person_id, events__pdi__person.id) | ||
WHERE equals(events.team_id, 5) | ||
LIMIT 10000 | ||
' | ||
--- | ||
# name: TestLazyJoins.test_resolve_lazy_tables_two_levels_properties_duplicate | ||
' | ||
|
||
SELECT events.event, events__pdi__person.properties, events__pdi__person.properties___name | ||
FROM events INNER JOIN ( | ||
SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id | ||
FROM person_distinct_id2 | ||
WHERE equals(person_distinct_id2.team_id, 5) | ||
GROUP BY person_distinct_id2.distinct_id | ||
HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0)) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id) INNER JOIN ( | ||
SELECT person.id, replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', '') AS properties___name, person.properties AS properties | ||
FROM person | ||
WHERE and(equals(person.team_id, 5), ifNull(in(tuple(person.id, person.version), ( | ||
SELECT person.id, max(person.version) AS version | ||
FROM person | ||
WHERE equals(person.team_id, 5) | ||
GROUP BY person.id | ||
HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0))), 0)) | ||
SETTINGS optimize_aggregation_in_order=1) AS events__pdi__person ON equals(events__pdi.person_id, events__pdi__person.id) | ||
WHERE equals(events.team_id, 5) | ||
LIMIT 10000 | ||
' | ||
--- | ||
# name: TestLazyJoins.test_resolve_lazy_tables_two_levels_traversed | ||
' | ||
|
||
SELECT events.event, events__pdi__person.id | ||
FROM events INNER JOIN ( | ||
SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS person_id, person_distinct_id2.distinct_id AS distinct_id | ||
FROM person_distinct_id2 | ||
WHERE equals(person_distinct_id2.team_id, 5) | ||
GROUP BY person_distinct_id2.distinct_id | ||
HAVING ifNull(equals(argMax(person_distinct_id2.is_deleted, person_distinct_id2.version), 0), 0)) AS events__pdi ON equals(events.distinct_id, events__pdi.distinct_id) INNER JOIN ( | ||
SELECT person.id | ||
FROM person | ||
WHERE and(equals(person.team_id, 5), ifNull(in(tuple(person.id, person.version), ( | ||
SELECT person.id, max(person.version) AS version | ||
FROM person | ||
WHERE equals(person.team_id, 5) | ||
GROUP BY person.id | ||
HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0))), 0)) | ||
SETTINGS optimize_aggregation_in_order=1) AS events__pdi__person ON equals(events__pdi.person_id, events__pdi__person.id) | ||
WHERE equals(events.team_id, 5) | ||
LIMIT 10000 | ||
' | ||
--- | ||
# name: TestLazyJoins.test_select_count_from_lazy_table | ||
' | ||
|
||
SELECT count() | ||
FROM ( | ||
SELECT person.id | ||
FROM person | ||
WHERE and(equals(person.team_id, 5), ifNull(in(tuple(person.id, person.version), ( | ||
SELECT person.id, max(person.version) AS version | ||
FROM person | ||
WHERE equals(person.team_id, 5) | ||
GROUP BY person.id | ||
HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0))), 0)) | ||
SETTINGS optimize_aggregation_in_order=1) AS persons | ||
LIMIT 10000 | ||
' | ||
--- |
Oops, something went wrong.