-
Notifications
You must be signed in to change notification settings - Fork 211
feat: allow to skip wrapping data into custom types #1490
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
Draft
alvarowolfx
wants to merge
1
commit into
main
Choose a base branch
from
feat-skip-wrap-custom-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,7 @@ | |
| pageToken?: string; | ||
| wrapIntegers?: boolean | IntegerTypeCastOptions; | ||
| parseJSON?: boolean; | ||
| skipWrapCustomTypes?: boolean; | ||
| // Overrides default job creation mode set on the client. | ||
| jobCreationMode?: JobCreationMode; | ||
| }; | ||
|
|
@@ -141,6 +142,8 @@ | |
| export type QueryOptions = QueryResultsOptions; | ||
| export type QueryStreamOptions = { | ||
| wrapIntegers?: boolean | IntegerTypeCastOptions; | ||
| skipWrapBig?: boolean; | ||
| skipWrapBigQueryCustomTypes?: boolean; | ||
| parseJSON?: boolean; | ||
| }; | ||
| export type DatasetResource = bigquery.IDataset & { | ||
|
|
@@ -369,17 +372,17 @@ | |
| private _universeDomain: string; | ||
| private _defaultJobCreationMode: JobCreationMode; | ||
|
|
||
| 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>({}, () => {}); | ||
| } | ||
|
|
@@ -579,14 +582,16 @@ | |
| * Please see {@link IntegerTypeCastOptions} for options descriptions. | ||
| * @param {array} options.selectedFields List of fields to return. | ||
| * If unspecified, all fields are returned. | ||
| * @param {array} options.parseJSON parse a 'JSON' field into a JSON object. | ||
| * @param {boolean} options.parseJSON parse a 'JSON' field into a JSON object. | ||
| * @param {boolean} options.skipWrapCustomTypes skip converting values into BigQuery custom types. | ||
| * @returns Fields using their matching names from the table's schema. | ||
| */ | ||
| static mergeSchemaWithRows_( | ||
| schema: TableSchema | TableField | undefined, | ||
| rows: TableRow[], | ||
| options: { | ||
| wrapIntegers: boolean | IntegerTypeCastOptions; | ||
| skipWrapCustomTypes?: boolean; | ||
| selectedFields?: string[]; | ||
| parseJSON?: boolean; | ||
| }, | ||
|
|
@@ -1429,6 +1434,7 @@ | |
| * @param {boolean} [options.wrapIntegers] Optionally wrap INT64 in BigQueryInt | ||
| * or custom INT64 value type. | ||
| * @param {boolean} [options.parseJSON] Optionally parse JSON as a JSON Object. | ||
| * @param {boolean} [options.skipWrapCustomTypes] Optionally skip wrapping values into BigQuery Custom Types. | ||
| * @param {object|array} [options.params] Option to provide query prarameters. | ||
| * @param {JobCallback} [callback] The callback function. | ||
| * @param {?error} callback.err An error returned while making this request. | ||
|
|
@@ -1589,7 +1595,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; | ||
|
|
@@ -2202,6 +2208,7 @@ | |
| ? { | ||
| wrapIntegers: query.wrapIntegers, | ||
| parseJSON: query.parseJSON, | ||
| skipWrapCustomTypes: query.skipWrapCustomTypes, | ||
| } | ||
| : {}; | ||
| const callback = | ||
|
|
@@ -2237,10 +2244,11 @@ | |
|
|
||
| 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, | ||
| skipWrapCustomTypes: options.skipWrapCustomTypes, | ||
| parseJSON: options.parseJSON, | ||
| }); | ||
| delete res.rows; | ||
|
|
@@ -2408,13 +2416,21 @@ | |
| return; | ||
| } | ||
|
|
||
| const {location, maxResults, pageToken, wrapIntegers, parseJSON} = query; | ||
| const { | ||
| location, | ||
| maxResults, | ||
| pageToken, | ||
| wrapIntegers, | ||
| parseJSON, | ||
| skipWrapCustomTypes, | ||
| } = query; | ||
|
|
||
| const opts = { | ||
| location, | ||
| maxResults, | ||
| pageToken, | ||
| wrapIntegers, | ||
| skipWrapCustomTypes, | ||
| parseJSON, | ||
| autoPaginate: false, | ||
| }; | ||
|
|
@@ -2423,6 +2439,7 @@ | |
| delete query.maxResults; | ||
| delete query.pageToken; | ||
| delete query.wrapIntegers; | ||
| delete query.skipWrapCustomTypes; | ||
| delete query.parseJSON; | ||
|
|
||
| this.query(query, opts, callback); | ||
|
|
@@ -2462,14 +2479,18 @@ | |
| value: any, | ||
| options: { | ||
| wrapIntegers: boolean | IntegerTypeCastOptions; | ||
| skipWrapCustomTypes?: boolean; | ||
|
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. same note about order of options |
||
| selectedFields?: string[]; | ||
| parseJSON?: boolean; | ||
| }, | ||
| ) { | ||
| if (is.null(value)) { | ||
| return value; | ||
| } | ||
|
|
||
| let {skipWrapCustomTypes, wrapIntegers, parseJSON} = options; | ||
|
Check failure on line 2490 in src/bigquery.ts
|
||
| if (skipWrapCustomTypes) { | ||
| wrapIntegers = false; | ||
| } | ||
| switch (schemaField.type) { | ||
| case 'BOOLEAN': | ||
| case 'BOOL': { | ||
|
|
@@ -2487,7 +2508,6 @@ | |
| } | ||
| case 'INTEGER': | ||
| case 'INT64': { | ||
| const {wrapIntegers} = options; | ||
| value = wrapIntegers | ||
| ? typeof wrapIntegers === 'object' | ||
| ? BigQuery.int( | ||
|
|
@@ -2498,12 +2518,12 @@ | |
| : Number(value); | ||
| break; | ||
| } | ||
| case 'BIGNUMERIC': | ||
| case 'NUMERIC': { | ||
| value = new Big(value); | ||
| break; | ||
| } | ||
| case 'BIGNUMERIC': { | ||
| value = new Big(value); | ||
| if (skipWrapCustomTypes) { | ||
| value = value.toFixed(); | ||
| } | ||
| break; | ||
| } | ||
| case 'RECORD': { | ||
|
|
@@ -2512,36 +2532,52 @@ | |
| } | ||
| case 'DATE': { | ||
| value = BigQuery.date(value); | ||
| if (skipWrapCustomTypes) { | ||
| value = value.value; | ||
| } | ||
| break; | ||
| } | ||
| case 'DATETIME': { | ||
| value = BigQuery.datetime(value); | ||
| if (skipWrapCustomTypes) { | ||
| value = value.value; | ||
| } | ||
| break; | ||
| } | ||
| case 'TIME': { | ||
| value = BigQuery.time(value); | ||
| if (skipWrapCustomTypes) { | ||
| value = value.value; | ||
| } | ||
| break; | ||
| } | ||
| case 'TIMESTAMP': { | ||
| const pd = new PreciseDate(); | ||
| pd.setFullTime(PreciseDate.parseFull(BigInt(value) * BigInt(1000))); | ||
| value = BigQuery.timestamp(pd); | ||
| if (skipWrapCustomTypes) { | ||
| value = value.value; | ||
| } | ||
| break; | ||
| } | ||
| case 'GEOGRAPHY': { | ||
| value = BigQuery.geography(value); | ||
| if (skipWrapCustomTypes) { | ||
| value = value.value; | ||
| } | ||
| break; | ||
| } | ||
| case 'JSON': { | ||
| const {parseJSON} = options; | ||
| value = parseJSON ? JSON.parse(value) : value; | ||
| break; | ||
| } | ||
| case 'RANGE': { | ||
| value = BigQueryRange.fromSchemaValue_( | ||
| value, | ||
| schemaField.rangeElementType!.type!, | ||
| ); | ||
| value = skipWrapCustomTypes | ||
| ? value | ||
| : BigQueryRange.fromSchemaValue_( | ||
| value, | ||
| schemaField.rangeElementType!.type!, | ||
| ); | ||
| break; | ||
| } | ||
| default: | ||
|
|
@@ -2645,6 +2681,7 @@ | |
| } | ||
| return convertSchemaFieldValue({type: elementType}, value, { | ||
| wrapIntegers: false, | ||
| skipWrapCustomTypes: false, | ||
| }); | ||
| }; | ||
| return BigQuery.range( | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
nit - can this be the last option? I know order isn't necessarily preserved but I feel like we should have these options in the order in which we have added them
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.
additional comment on this line - Any reason why we can't call this wrapCustomTypes? I know it would flip the boolean logic later on, but it would be in line with the wrapIntegers naming scheme