-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify code path for json value translation with variables (#267)
### What Rather than having two different ways to translate values (depending on whether they are literals or variables) we instead use the same method in both cases. ### How As a consequence we need to have the `State` available in literal value translation as well as in variable translation, which requires some follow-up changes in the various other translation functions. We also duplicate the test of nested array types from the variables-case to the literal values-case.
- Loading branch information
Showing
16 changed files
with
401 additions
and
67 deletions.
There are no files selected for viewing
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
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
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
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
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
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
81 changes: 81 additions & 0 deletions
81
.../query-engine/translation/tests/goldenfiles/select_array_column_nested_types/request.json
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,81 @@ | ||
{ | ||
"collection": "summarize_organizations", | ||
"query": { | ||
"fields": { | ||
"result": { | ||
"type": "column", | ||
"column": "result", | ||
"arguments": {} | ||
} | ||
} | ||
}, | ||
"arguments": { | ||
"organizations": { | ||
"type": "literal", | ||
"value": [ | ||
{ | ||
"name": "RC Model Airplane Enthusiasts", | ||
"committees": [ | ||
{ | ||
"name": "Founders", | ||
"members": [ | ||
{ | ||
"first_name": "Orville", | ||
"last_name": "Wright" | ||
}, | ||
{ | ||
"first_name": "Wilbur", | ||
"last_name": "Wright" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "Parts supply management", | ||
"members": [ | ||
{ | ||
"first_name": "Orville", | ||
"last_name": "Wright" | ||
}, | ||
{ | ||
"first_name": "Wilbur", | ||
"last_name": "Wright" | ||
}, | ||
{ | ||
"first_name": "Guybrush", | ||
"last_name": "Threepwood" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "Argonauts' Alumni Association", | ||
"committees": [ | ||
{ | ||
"name": "Crew", | ||
"members": [ | ||
{ | ||
"first_name": "Jason", | ||
"last_name": "(The)" | ||
}, | ||
{ | ||
"first_name": "Heracles", | ||
"last_name": "(The)" | ||
}, | ||
{ | ||
"first_name": "Castor", | ||
"last_name": "(The)" | ||
}, | ||
{ | ||
"first_name": "Polydeuces", | ||
"last_name": "(The)" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"collection_relationships": {} | ||
} |
86 changes: 86 additions & 0 deletions
86
...s/query-engine/translation/tests/goldenfiles/select_array_column_nested_types/tables.json
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,86 @@ | ||
{ | ||
"compositeTypes": { | ||
"person_name": { | ||
"name": "person_name", | ||
"fields": { | ||
"first_name": { | ||
"name": "first_name", | ||
"type": { | ||
"scalarType": "text" | ||
} | ||
}, | ||
"last_name": { | ||
"name": "last_name", | ||
"type": { | ||
"scalarType": "text" | ||
} | ||
} | ||
} | ||
}, | ||
"committee": { | ||
"name": "committee", | ||
"fields": { | ||
"name": { | ||
"name": "name", | ||
"type": { | ||
"scalarType": "text" | ||
} | ||
}, | ||
"members": { | ||
"name": "members", | ||
"type": { | ||
"arrayType": { | ||
"scalarType": "text" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"organization": { | ||
"name": "organization", | ||
"fields": { | ||
"name": { | ||
"name": "name", | ||
"type": { | ||
"scalarType": "text" | ||
} | ||
}, | ||
"members": { | ||
"name": "committees", | ||
"type": { | ||
"arrayType": { | ||
"compositeType": "committee" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"nativeQueries": { | ||
"summarize_organizations": { | ||
"sql": "SELECT 'The organization ' || org.name || ' has ' || no_committees::text || ' committees, ' || 'the largest of which has ' || max_members || ' members.' AS result FROM (SELECT orgs.* FROM unnest({{organizations}}) as orgs) AS org JOIN LATERAL ( SELECT count(committee.*) AS no_committees, max(members_agg.no_members) AS max_members FROM unnest(org.committees) AS committee JOIN LATERAL ( SELECT count(*) as no_members FROM unnest(committee.members) AS members) AS members_agg ON true) AS coms ON true", | ||
"columns": { | ||
"result": { | ||
"name": "result", | ||
"type": { | ||
"scalarType": "text" | ||
}, | ||
"nullable": "nullable", | ||
"description": null | ||
} | ||
}, | ||
"arguments": { | ||
"organizations": { | ||
"name": "organizations", | ||
"type": { | ||
"arrayType": { | ||
"compositeType": "organization" | ||
} | ||
}, | ||
"nullable": "nullable" | ||
} | ||
}, | ||
"description": "A native query used to test support array-valued variables" | ||
} | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
crates/query-engine/translation/tests/snapshots/tests__select_array_column_nested_types.snap
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,58 @@ | ||
--- | ||
source: crates/query-engine/translation/tests/tests.rs | ||
expression: result | ||
--- | ||
WITH "%1_NATIVE_QUERY_summarize_organizations" AS ( | ||
SELECT | ||
'The organization ' || org.name || ' has ' || no_committees :: text || ' committees, ' || 'the largest of which has ' || max_members || ' members.' AS result | ||
FROM | ||
( | ||
SELECT | ||
orgs.* | ||
FROM | ||
unnest( | ||
( | ||
SELECT | ||
array_agg( | ||
jsonb_populate_record(cast(null as organization), "%0_array"."element") | ||
) AS "element" | ||
FROM | ||
jsonb_array_elements($1) AS "%0_array"("element") | ||
) | ||
) as orgs | ||
) AS org | ||
JOIN LATERAL ( | ||
SELECT | ||
count(committee.*) AS no_committees, | ||
max(members_agg.no_members) AS max_members | ||
FROM | ||
unnest(org.committees) AS committee | ||
JOIN LATERAL ( | ||
SELECT | ||
count(*) as no_members | ||
FROM | ||
unnest(committee.members) AS members | ||
) AS members_agg ON true | ||
) AS coms ON true | ||
) | ||
SELECT | ||
coalesce(json_agg(row_to_json("%2_universe")), '[]') AS "universe" | ||
FROM | ||
( | ||
SELECT | ||
* | ||
FROM | ||
( | ||
SELECT | ||
coalesce(json_agg(row_to_json("%3_rows")), '[]') AS "rows" | ||
FROM | ||
( | ||
SELECT | ||
"%0_summarize_organizations"."result" AS "result" | ||
FROM | ||
"%1_NATIVE_QUERY_summarize_organizations" AS "%0_summarize_organizations" | ||
) AS "%3_rows" | ||
) AS "%3_rows" | ||
) AS "%2_universe" | ||
|
||
[(1, Value(Array [Object {"name": String("RC Model Airplane Enthusiasts"), "committees": Array [Object {"name": String("Founders"), "members": Array [Object {"first_name": String("Orville"), "last_name": String("Wright")}, Object {"first_name": String("Wilbur"), "last_name": String("Wright")}]}, Object {"name": String("Parts supply management"), "members": Array [Object {"first_name": String("Orville"), "last_name": String("Wright")}, Object {"first_name": String("Wilbur"), "last_name": String("Wright")}, Object {"first_name": String("Guybrush"), "last_name": String("Threepwood")}]}]}, Object {"name": String("Argonauts' Alumni Association"), "committees": Array [Object {"name": String("Crew"), "members": Array [Object {"first_name": String("Jason"), "last_name": String("(The)")}, Object {"first_name": String("Heracles"), "last_name": String("(The)")}, Object {"first_name": String("Castor"), "last_name": String("(The)")}, Object {"first_name": String("Polydeuces"), "last_name": String("(The)")}]}]}]))] |
Oops, something went wrong.