bigquery loadJob of a json - forcing a field to be String in the schema auto-detect

Viewed 1635

if in the beginning the json contains

"label": "foo"

and later it is

"label": "123"

bigquery returns

Invalid schema update. Field label has changed type from STRING to INTEGER 

although it is "123" and not 123.

file is being loaded with

autodetect: true

is there a way to force bigquery to make any field as string when it applies its auto-detect, or the only way is using csv instead ?

1 Answers

The auto-detection is based on the best effort to recognize the data type by scanning up to 100 rows of data to use as a representative sample. There is no way to give insight about which kind of type it is. You may consider to specify manually the schema for your use case.

UDATE:

I have tested to load a file with only {"label" : "123"} and it is recognized as INTEGER. Therefore, the auto detection recognizes "123" as INGETER no matter if there are quotes or not. For your case, you may consider to export the schema from the existent table as explained in the documentation:

Note: You can view the schema of an existing table in JSON format by entering the following command: bq show --format=prettyjson [DATASET].[TABLE].

and use it for further dynamic loads

Related