-
Notifications
You must be signed in to change notification settings - Fork 213
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: return extra args when autoPaginate is on #1365
Changes from 3 commits
f0db3ec
d4f6723
add2823
bef5262
efc3636
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,15 +80,18 @@ | |
maxApiCalls?: number; | ||
}; | ||
|
||
export type QueryResultsResponse = bigquery.IGetQueryResultsResponse & | ||
bigquery.IQueryResponse; | ||
|
||
export type QueryRowsResponse = PagedResponse< | ||
RowMetadata, | ||
Query, | ||
bigquery.IGetQueryResultsResponse | ||
QueryResultsResponse | ||
>; | ||
export type QueryRowsCallback = PagedCallback< | ||
RowMetadata, | ||
Query, | ||
bigquery.IGetQueryResultsResponse | ||
QueryResultsResponse | ||
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. @leahecole do you think this is a breaking change ? I feel like is fine because it still compatible with the previous type, I'm just enhancing to cover other response types when getting query results, which can come as 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. ooo this is such a good question. I thought about it for a bit and I think you're right - it is backwards compatible - I think it does merit a minor release and not just a patch release though because you are adding functionality - you're just doing so in a way that is backwards compatible. |
||
>; | ||
|
||
export type SimpleQueryRowsResponse = [RowMetadata[], bigquery.IJob]; | ||
|
@@ -165,8 +168,8 @@ | |
bigquery.IJobList | ||
>; | ||
|
||
export type JobsQueryResponse = [Job, bigquery.IQueryResponse]; | ||
export type JobsQueryCallback = ResourceCallback<Job, bigquery.IQueryResponse>; | ||
export type JobsQueryResponse = [Job, QueryResultsResponse]; | ||
export type JobsQueryCallback = ResourceCallback<Job, QueryResultsResponse>; | ||
|
||
export interface BigQueryTimeOptions { | ||
hours?: number | string; | ||
|
@@ -336,17 +339,17 @@ | |
private _universeDomain: string; | ||
private _enableQueryPreview: boolean; | ||
|
||
createQueryStream(options?: Query | string): ResourceStream<RowMetadata> { | ||
// placeholder body, overwritten in constructor | ||
return new ResourceStream<RowMetadata>({}, () => {}); | ||
} | ||
|
||
getDatasetsStream(options?: GetDatasetsOptions): ResourceStream<Dataset> { | ||
// placeholder body, overwritten in constructor | ||
return new ResourceStream<Dataset>({}, () => {}); | ||
} | ||
|
||
getJobsStream(options?: GetJobsOptions): ResourceStream<Job> { | ||
// placeholder body, overwritten in constructor | ||
return new ResourceStream<Job>({}, () => {}); | ||
} | ||
|
@@ -1533,7 +1536,7 @@ | |
const parameterMode = is.array(params) ? 'positional' : 'named'; | ||
const queryParameters: bigquery.IQueryParameter[] = []; | ||
if (parameterMode === 'named') { | ||
const namedParams = params as {[param: string]: any}; | ||
for (const namedParameter of Object.getOwnPropertyNames(namedParams)) { | ||
const value = namedParams[namedParameter]; | ||
let queryParameter; | ||
|
@@ -2113,7 +2116,10 @@ | |
* ``` | ||
*/ | ||
query(query: string, options?: QueryOptions): Promise<QueryRowsResponse>; | ||
query(query: Query, options?: QueryOptions): Promise<SimpleQueryRowsResponse>; | ||
query( | ||
query: Query, | ||
options?: QueryOptions | ||
): Promise<SimpleQueryRowsResponse> | Promise<QueryRowsResponse>; | ||
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. Do you need to also update the docstring to have an example of this? Or is it going to be the same? 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. I removed this signature change as was not needed. So I think we don't need updates to the docstring, this is just to fix a behavior that users were already expecting from that method. |
||
query( | ||
query: string, | ||
options: QueryOptions, | ||
|
@@ -2176,7 +2182,7 @@ | |
|
||
options = extend({job}, queryOpts, options); | ||
if (res && res.jobComplete) { | ||
let rows: any = []; | ||
if (res.schema && res.rows) { | ||
rows = BigQuery.mergeSchemaWithRows_(res.schema, res.rows, { | ||
wrapIntegers: options.wrapIntegers || false, | ||
|
@@ -2185,6 +2191,7 @@ | |
} | ||
this.trace_('[runJobsQuery] job complete'); | ||
options._cachedRows = rows; | ||
options._cachedResponse = res; | ||
if (res.pageToken) { | ||
this.trace_('[runJobsQuery] has more pages'); | ||
options.pageToken = res.pageToken; | ||
|
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.
this syntax feels absolutely wild to me, a concrete type made from ANDing two interfaces? Should it be IQueryResultsResponse?
Does this blow up if you have fields with equal names but varying types?
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 changed it to be an
or
, so it's more accurate. When using the.query
method, the return can be either aIQueryResultsResponse
orIQueryResponse
, this way all common fields are gonna be in that type by default and if you need an specific type, you can create a type coercion like I show in the system-tests:nodejs-bigquery/system-test/bigquery.ts
Line 346 in bef5262
nodejs-bigquery/system-test/bigquery.ts
Line 357 in bef5262
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.
"this syntax feels absolutely wild to me" that's because it is - you can do some wild and wacky things with typescript 😆
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.
Re Alvaro, I think the OR is probably a better choice