-
Notifications
You must be signed in to change notification settings - Fork 603
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
bigquery: support SQL parameters #1854
Conversation
@blowmage shout out for your system tests, which helped me a lot while putting this together. Did you ever find a good query for structs? |
|
||
if (type === 'TIMESTAMP') { | ||
// @TODO - Not sure why .toJSON() doesn't just work. | ||
value = new Date(value).toJSON().replace(/(.*)T(.*)Z$/, '$1 $2'); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@stephenplusplus Not yet. We are looking for one though. |
}); | ||
}); | ||
|
||
it.skip('should work with structs', function(done) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@stephenplusplus should I wait to merge for the struct stuff? Everything else looks good. |
Probably worth noting that there are more types that can be supported. Our initial implementation missed DATETIME, TIME, and BYTES. (See googleapis/google-cloud-ruby#1100) |
Thanks for the heads up! |
@stephenplusplus do you want to get those other types in before merge? |
Yeah, I'll have a PR soon for them. In the testing phase now. |
2c4b37e
to
e027f03
Compare
Alright, ready for another look @callmehiphop |
* } | ||
* }, callback); | ||
* | ||
* //- |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
}); | ||
}); | ||
|
||
it.skip('should work with DATETIME types', function(done) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
/** | ||
* A `DATETIME` data type represents a point in time. Unlike a `TIMESTAMP`, a | ||
* this does not refer to an absolute instance in time. Instead, it is the civil |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return 'STRUCT'; | ||
} | ||
|
||
return 'STRING'; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
* @param {object|*[]} options.params - For positional SQL parameters, provide | ||
* an array of values. For named SQL parameters, provide an object which | ||
* maps each named parameter to its value. The supported types are integers, | ||
* floats, Date objects, Strings, Booleans, and Objects. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -450,6 +724,39 @@ BigQuery.prototype.job = function(id) { | |||
* }); | |||
* | |||
* //- | |||
* // Positional and named SQL parameters are supported. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
27, | ||
28, | ||
29 | ||
] |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Changes made! |
*/ | ||
BigQuery.valueToQueryParameter_ = function(value) { | ||
if (is.date(value)) { | ||
value = this.timestamp(value); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
is there anyway to file an issue to BigQuery design? my app use both BigQuery and Datastore, and Datastore's DATETIME apprarently accepts RFC3339 format; there is no reason BigQuery server side can't accept this ISO standard format |
@c0b I am unable to answer that, clients like google-cloud-node consume the API and we don't have access to the design decisions behind it. We don't have access to Google's internal bug tracker. |
@c0b @blowmage BigQuery uses a public issue tracker. I have filed an issue for this. https://code.google.com/p/google-bigquery/issues/detail?id=842 Please "star" the issue to show your support and receive status updates. |
Great. Thanks @tswast! |
Can you be more specific about where you'd like this format to be accepted? It's already accepted for load jobs with JSON or CSV, for example. |
Ah, never mind, just noticed this is in query parameters. |
value = value || new Date(); | ||
|
||
if (is.date(value)) { | ||
value = value.toJSON().replace(/^(.*)T(.*)Z$/, '$1 $2'); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Fixes #1787
To Dos
This introduces a nice wrapper around SQL parameter queries, allowing positional and named parameters:
Helpful resources: