-
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.
Support variables of array type (#263)
### What This PR extends the support for query variables to include arrays. ### How We need to go a bit out of our way to be able to translate JSON arrays to Postgres arrays, since there is no single builtin function that does this. As an example taken from the tests, a variable of type array-of-`organization` gets translated to the below SQL: ``` ( SELECT array_agg( jsonb_populate_record(cast(null as organization), "%0_arr"."elem") ) AS "elem" FROM jsonb_array_elements(("%0_%variables_table"."%variables" -> $2)) AS "%0_arr"("elem") ) ``` Which, being a single-element set-returning expression, can feature both in a `FROM` clause and in a select-list or other expression. --------- Co-authored-by: Gil Mizrahi <[email protected]>
- Loading branch information
Showing
42 changed files
with
1,604 additions
and
103 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
27 changes: 27 additions & 0 deletions
27
crates/query-engine/translation/tests/goldenfiles/select_array_variable/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,27 @@ | ||
{ | ||
"collection": "count_elements", | ||
"query": { | ||
"fields": { | ||
"result": { | ||
"type": "column", | ||
"column": "result", | ||
"arguments": {} | ||
} | ||
} | ||
}, | ||
"arguments": { | ||
"array_argument": { | ||
"type": "variable", | ||
"name": "variable_array_argument" | ||
} | ||
}, | ||
"collection_relationships": {}, | ||
"variables": [ | ||
{ | ||
"variable_array_argument": ["one", "two"] | ||
}, | ||
{ | ||
"variable_array_argument": ["one", "two", "three"] | ||
} | ||
] | ||
} |
27 changes: 27 additions & 0 deletions
27
crates/query-engine/translation/tests/goldenfiles/select_array_variable/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,27 @@ | ||
{ | ||
"nativeQueries": { | ||
"count_elements": { | ||
"sql": "SELECT array_length({{array_argument}}, 1) as result", | ||
"columns": { | ||
"result": { | ||
"name": "result", | ||
"type": { | ||
"scalarType": "int4" | ||
}, | ||
"nullable": "nullable", | ||
"description": null | ||
} | ||
}, | ||
"arguments": { | ||
"array_argument": { | ||
"name": "array_argument", | ||
"type": { | ||
"arrayType": { "scalarType": "text" } | ||
}, | ||
"nullable": "nullable" | ||
} | ||
}, | ||
"description": "A native query used to test support array-valued variables" | ||
} | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...uery-engine/translation/tests/goldenfiles/select_array_variable_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,107 @@ | ||
{ | ||
"collection": "summarize_organizations", | ||
"query": { | ||
"fields": { | ||
"result": { | ||
"type": "column", | ||
"column": "result", | ||
"arguments": {} | ||
} | ||
} | ||
}, | ||
"arguments": { | ||
"organizations": { | ||
"type": "variable", | ||
"name": "variable_organizations" | ||
} | ||
}, | ||
"collection_relationships": {}, | ||
"variables": [ | ||
{ | ||
"variable_organizations": [] | ||
}, | ||
{ | ||
"variable_organizations": [ | ||
{ | ||
"name": "Federation of United Solipsists", | ||
"committees": [ | ||
{ | ||
"name": "Positively existing entities", | ||
"members": [ | ||
{ | ||
"first_name": "Yo", | ||
"last_name": "El mismo" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"variable_organizations": [ | ||
{ | ||
"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)" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.