I am using \N for null either for INTEGER or DATETIME data types in the JSON table definition(nullMarker:"\N") for external tables but then also BigQuery is not able to parse it and throwing the below error:
error message: Could not parse '\N' as int for field [Field Name](position 2)
starting at location 0
Could anyone please help me, what can be the possible fix?
I am using the BigQuery Cloud SDK CLI to attempt to do the same. I am utilizing the flag
--null_marker="\N"and--source_format NEWLINE_DELIMITED_JSONto load data. Here is the error message I get:BigQuery error in load operation: Only CSV imports may specify a null marker.So it appears that null markers are not supported for BigQuery imports in JSON format. Pretty disappointing for me.
Here is the exact code and sample I used to test and verify this:
this is a file called
example.jsonwhere I want the\Ncharacter to represent the NULL marker.this is the command to make the table (my dataset is temp14):
and here is the command to load the data which did not work :(
I can replace the
\Nin the JSON with the empty string likeand it will load if I remove the flag:
But the strings load into the table as "" instead of
nulland I need them to be NULL. The FLOAT field correctly assigns NULL, but the STRING does not.My work around is to pre-process the empty strings out of my dataset in a staging area which is kind of like a scratch space, then have my final table represent that data with something like this:
I cannot use CSV for my data sadly and need JSON to work but also need NULL values to be represented correctly.
EDIT: After coming back to this I did discover that JSON formatted data will allow for NULLs, but not with a null marker. You simply need to omit the key/value pair for JSON data to load to BigQuery as NULL. So the
example.jsonshould look like this to nullify those above fields where the\Nused to be.And I verified that the above does work with no additional flags required, as well as with external tables.