-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat(bigquery): add support for explicit query parameter type #6596
feat(bigquery): add support for explicit query parameter type #6596
Conversation
I changed to a slight different approach, having some specific struct and interface that can be used explicitly or with the current QueryParameter struct.
|
bigquery/params.go
Outdated
func (p QueryParameter) toBQ() (*bq.QueryParameter, error) { | ||
// QueryParameterValue is a go type for representing a explicit typed BigQuery Query Parameter. | ||
type QueryParameterValue struct { | ||
Type StandardSQLDataType |
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.
Document these fields as appropriate.
bigquery/params.go
Outdated
@@ -129,12 +139,57 @@ type QueryParameter struct { | |||
Value interface{} | |||
} | |||
|
|||
func (p QueryParameter) toBQ() (*bq.QueryParameter, error) { | |||
// QueryParameterValue is a go type for representing a explicit typed BigQuery Query Parameter. |
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.
I'm still on the fence about the name due to the collision with the API, but it's a reasonable name otherwise.
Should we document the behavior for nested types as part of the type description? Specifically that you need to fully specify types and values for complex params?
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.
I think the only work remaining is to flesh out the documentation for QueryParameterValue (and it's fields) and ship it. Approving contingent on that.
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.
Looks good, and I like the explicit examples of usage. Thanks for putting this together!
🤖 I have created a release *beep* *boop* --- ## [1.42.0](bigquery/v1.41.0...bigquery/v1.42.0) (2022-09-21) ### Features * **bigquery/analyticshub:** Start generating apiv1 ([#6707](#6707)) ([feb7d7d](feb7d7d)) * **bigquery/datapolicies:** Start generating apiv1beta1 ([#6697](#6697)) ([f5443e8](f5443e8)) * **bigquery/reservation/apiv1beta1:** add REST transport ([f7b0822](f7b0822)) * **bigquery/storage/managedwriter:** Define append retry predicate ([#6650](#6650)) ([478b8dd](478b8dd)) * **bigquery/storage:** add proto annotation for non-ascii field mapping ([ec1a190](ec1a190)) * **bigquery:** Add reference file schema option for federated formats ([#6693](#6693)) ([3d26091](3d26091)) * **bigquery:** Add support for explicit query parameter type ([#6596](#6596)) ([d59b5b2](d59b5b2)), refs [#4704](#4704) ### Bug Fixes * **bigquery/connection:** integrate gapic-generator-python-1.4.1 and enable more py_test targets ([ec1a190](ec1a190)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Allow users to pass query parameter with an explicit data types instead of relying just on reflection of Go types. Right now the data type that is affect by this change is
*big.Rat
, which before was only converted toNUMERIC
with 9 digits, and now can be send as aBIGNUMERIC
.This adds two methods:
NewScalarQueryParameter(name string, paramType FieldType, value interface{}) QueryParameter
NewArrayQueryParameter(name string, paramType FieldType, value interface{}) QueryParameter
Example usage:
I'm still evaluating if we need something like
NewStructQueryParameter
to pass a list of QueryParameters with explicit data types for each field.Most of this was inspired by the Python implementation that has the same kind of methods for creating query parameters.
Resolves #4704