-
Notifications
You must be signed in to change notification settings - Fork 119
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
fix: add support for repeated record query parameters #2698
Conversation
Add support for array of struct query parameters which are used to query repeated record fields
typePb.setArrayType(arrayTypePb); | ||
if (getArrayType() == StandardSQLTypeName.STRUCT) { | ||
List<QueryParameterValue> values = | ||
Objects.requireNonNull(getArrayValues(), "Array of struct cannot be empty"); |
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.array
method, 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 to QueryParameterValue.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.
@@ -4062,6 +4062,47 @@ public void testStructNamedQueryParameters() throws InterruptedException { | |||
} | |||
} | |||
|
|||
@Test | |||
public void testRepeatedRecordNamedQueryParameters() throws InterruptedException { |
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.
Can you also write a test with UNNEST option, since that is the particular use case the customer is using?
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.
Sure, will work on it
…don't exist Make the toTypePb method produce an empty 'ARRAY<STRUCT<>>' type when no values exist an an array of struct, which was the original behaviour. Add IT tests for UNNESTing struct array and creating empty struct array query parameters.
@Neenu1995 I've made some changes:
Also there's something to note: the |
This is the exact statement we want to verify. Verify if a named parameter type of Array of struct exists in a struct field. |
QueryParameterValue zipValue = QueryParameterValue.string("1h2j34"); | ||
QueryParameterValue numberOfYearsValue = QueryParameterValue.string("3"); | ||
|
||
Map<String, QueryParameterValue> struct = new HashMap<>(); |
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.
The order of fields inside structs matters when doing comparisons, and HashMap
does not maintain insertion order. Because of these reasons, the IN UNNEST(addresses)
query doesn't return any results.
I tried replacing HashMap
with a LinkedHashMap
and using ImmutableMap.of
, both options made the IN UNNEST(addresses)
query work as intended and return the correct row.
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
🤖 I have created a release *beep* *boop* --- ## [2.27.0](https://togithub.com/googleapis/java-bigquery/compare/v2.26.1...v2.27.0) (2023-05-30) ### Features * Add support for session id on TableDataWriteChannel ([#2715](https://togithub.com/googleapis/java-bigquery/issues/2715)) ([42851d8](https://togithub.com/googleapis/java-bigquery/commit/42851d818ee825d7c4141d40d116e1da43c11f14)) ### Bug Fixes * Add support for repeated record query parameters ([#2698](https://togithub.com/googleapis/java-bigquery/issues/2698)) ([51aff50](https://togithub.com/googleapis/java-bigquery/commit/51aff502215d69bd0151030421cd18646c6ead36)) ### Dependencies * Update dependency com.google.api.grpc:proto-google-cloud-bigqueryconnection-v1 to v2.20.0 ([#2720](https://togithub.com/googleapis/java-bigquery/issues/2720)) ([4962cac](https://togithub.com/googleapis/java-bigquery/commit/4962cac8fb3fe8d77a136eaf1b579cd79304acfb)) * Update dependency com.google.apis:google-api-services-bigquery to v2-rev20230506-2.0.0 ([#2707](https://togithub.com/googleapis/java-bigquery/issues/2707)) ([4d2ec07](https://togithub.com/googleapis/java-bigquery/commit/4d2ec0716287e9624949cbcdf6605c127c209be4)) * Update dependency com.google.apis:google-api-services-bigquery to v2-rev20230520-2.0.0 ([#2723](https://togithub.com/googleapis/java-bigquery/issues/2723)) ([5c64797](https://togithub.com/googleapis/java-bigquery/commit/5c64797c603343408849535b2dbf8080cd11ca32)) * Update dependency com.google.cloud:google-cloud-bigquerystorage-bom to v2.37.2 ([#2726](https://togithub.com/googleapis/java-bigquery/issues/2726)) ([052c47a](https://togithub.com/googleapis/java-bigquery/commit/052c47aa43b0f50414db3031914e8a775ae98925)) * Update dependency com.google.cloud:google-cloud-datacatalog-bom to v1.24.0 ([#2721](https://togithub.com/googleapis/java-bigquery/issues/2721)) ([7c357fb](https://togithub.com/googleapis/java-bigquery/commit/7c357fb414d45fde734c09c88ee3023d8d8f5822)) * Update dependency com.google.cloud:google-cloud-shared-dependencies to v3.10.1 ([#2713](https://togithub.com/googleapis/java-bigquery/issues/2713)) ([744e83a](https://togithub.com/googleapis/java-bigquery/commit/744e83a3da5323bc2cff2bcc6368a3eec39f392e)) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
Add support for array of struct query parameters which are used to query repeated record fields
Fixes #2485 ☕️