-
Notifications
You must be signed in to change notification settings - Fork 129
fix: add support for repeated record query parameters #2698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2c891e7
fix: add support for repeated record query parameters
obada-ab eefcdae
fix: set the query parameter type to an empty struct array if values …
obada-ab f8e36ce
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 8deb47a
Merge branch 'main' into struct-array
obada-ab f15630a
chore: add test for a real dataset
Neenu1995 6fc4085
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 0353c4e
chore: set up repeated record test to run in service account
obada-ab b5ac4af
doc: create and query repeated record sample
obada-ab 49fa251
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 746db7a
refactor: reformat repeated record sample
obada-ab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4062,6 +4062,47 @@ public void testStructNamedQueryParameters() throws InterruptedException { | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testRepeatedRecordNamedQueryParameters() throws InterruptedException { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also write a test with UNNEST option, since that is the particular use case the customer is using?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, will work on it |
||
| String[] stringValues = new String[] {"test-stringField", "test-stringField2"}; | ||
| List<QueryParameterValue> tuples = new ArrayList<>(); | ||
| for (int i = 0; i < 2; i++) { | ||
| QueryParameterValue stringValue = QueryParameterValue.string(stringValues[i]); | ||
| Map<String, QueryParameterValue> struct = new HashMap<>(); | ||
| struct.put("stringField", stringValue); | ||
| QueryParameterValue recordValue = QueryParameterValue.struct(struct); | ||
| tuples.add(recordValue); | ||
| } | ||
|
|
||
| QueryParameterValue repeatedRecord = | ||
| QueryParameterValue.array(tuples.toArray(), StandardSQLTypeName.STRUCT); | ||
| String query = "SELECT @repeatedRecordField AS repeatedRecord"; | ||
| QueryJobConfiguration config = | ||
| QueryJobConfiguration.newBuilder(query) | ||
| .setDefaultDataset(DATASET) | ||
| .setUseLegacySql(false) | ||
| .addNamedParameter("repeatedRecordField", repeatedRecord) | ||
| .build(); | ||
| TableResult result = bigquery.query(config); | ||
| assertEquals(1, Iterables.size(result.getValues())); | ||
|
|
||
| FieldList subSchema = result.getSchema().getFields().get("repeatedRecord").getSubFields(); | ||
| for (FieldValueList values : result.iterateAll()) { | ||
| for (FieldValue value : values) { | ||
| assertEquals(FieldValue.Attribute.REPEATED, value.getAttribute()); | ||
| assertEquals(2, value.getRepeatedValue().size()); | ||
| for (int i = 0; i < 2; i++) { | ||
| FieldValue record = value.getRepeatedValue().get(i); | ||
| assertEquals(FieldValue.Attribute.RECORD, record.getAttribute()); | ||
| FieldValueList recordValue = record.getRecordValue(); | ||
| assertEquals( | ||
| stringValues[i], | ||
| FieldValueList.of(recordValue, subSchema).get("stringField").getValue()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testStructQuery() throws InterruptedException { | ||
| // query into a table | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this restriction coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is currently no way for users to supply detailed struct types (including the fields) when creating an array of struct query parameter using the
QueryParameterValue.arraymethod, which would limit us to the option of peeking at the first record to figure out the struct fields.Ideally, query parameter types should not be limited to primitives and
StandardSQLTypeName, users should create more general/nested types and supply them toQueryParameterValue.array, but this would be a much bigger change.I think this fix with the limitation would solve most/all use cases until the changes mentioned are made.