Skip to content
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

JSON not a valid type for parameterized query #1320

Closed
Sese-Schneider opened this issue Dec 20, 2023 · 0 comments · Fixed by #1329
Closed

JSON not a valid type for parameterized query #1320

Sese-Schneider opened this issue Dec 20, 2023 · 0 comments · Fixed by #1329
Assignees
Labels
api: bigquery Issues related to the googleapis/nodejs-bigquery API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@Sese-Schneider
Copy link

Sese-Schneider commented Dec 20, 2023

Summary

When using parameterized queries with NULLABLE values one has to provide the types field in case a parameter is null.
The check getTypeDescriptorFromProvidedType_ fails with Invalid type provided: "JSON".

Stacktrace
>  Error: Invalid type provided: "JSON"
>      at BigQuery.getTypeDescriptorFromProvidedType_ (Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\build\src\bigquery.js:741:19)
>      at BigQuery.valueToQueryParameter_ (Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\build\src\bigquery.js:851:38)
>      at BigQuery.createQueryJob (Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\build\src\bigquery.js:968:55)
>      at BigQuery.wrapper (Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\node_modules\@google-cloud\promisify\build\src\index.js:30:35)
>      at BigQuery.query (Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\build\src\bigquery.js:1218:14)     
>      at Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\node_modules\@google-cloud\promisify\build\src\index.js:57:28
>      at new Promise (<anonymous>)
>      at BigQuery.wrapper (Y:\[REDACTED]\backend\functions\node_modules\@google-cloud\bigquery\node_modules\@google-cloud\promisify\build\src\index.js:42:16)
>      at Y:\[REDACTED]\backend\functions\lib\[REDACTED]\import.js:40:50
>      at Array.map (<anonymous>)

Looking at the sourcecode it looks like the type JSON was not implemented.

static getTypeDescriptorFromProvidedType_(
providedType: string | ProvidedTypeStruct | ProvidedTypeArray
): ValueType {
// The list of types can be found in src/types.d.ts
const VALID_TYPES = [
'DATE',
'DATETIME',
'TIME',
'TIMESTAMP',
'BYTES',
'NUMERIC',
'BIGNUMERIC',
'BOOL',
'INT64',
'FLOAT64',
'STRING',
'GEOGRAPHY',
'ARRAY',
'STRUCT',
];

even though it should have been according to the comment

// The list of types can be found in src/types.d.ts

where it actually can be found:

nodejs-bigquery/src/types.d.ts

Lines 3592 to 3611 in 4ebe5da

typeKind?:
| 'TYPE_KIND_UNSPECIFIED'
| 'INT64'
| 'BOOL'
| 'FLOAT64'
| 'STRING'
| 'BYTES'
| 'TIMESTAMP'
| 'DATE'
| 'TIME'
| 'DATETIME'
| 'INTERVAL'
| 'GEOGRAPHY'
| 'NUMERIC'
| 'BIGNUMERIC'
| 'JSON'
| 'ARRAY'
| 'STRUCT'
| 'RANGE';
};

Steps to reproduce

Run a parameterized query with a column of datatype JSON/NULLABLE

new BigQuery().query({
  query: `
    INSERT INTO
      database.table (data)
    VALUES
     (@data)
  `,
  params:  { data: null },
  types: { data: "JSON" },
})
Environment
- OS: Windows
- Node.js version: 18.13.0
- npm version: 9.8.1
- `@google-cloud/bigquery` version: 7.3.0

Sidenote: Same is true for the new datatype RANGE

@Sese-Schneider Sese-Schneider added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 20, 2023
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/nodejs-bigquery API. label Dec 20, 2023
@alvarowolfx alvarowolfx self-assigned this Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/nodejs-bigquery API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants