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

Coerce BigQuery types when inserting #129

Open
1 task
poundifdef opened this issue Mar 20, 2024 · 5 comments
Open
1 task

Coerce BigQuery types when inserting #129

poundifdef opened this issue Mar 20, 2024 · 5 comments
Labels

Comments

@poundifdef
Copy link
Contributor

The following inserts into bigquery will fail:

{"x": "y"}
{"x": true}
googleapi: Error 400: Invalid schema update. Field x has changed type from STRING to BOOLEAN, invalid

This is because when the table is first created, column x is a string. When the second JSON is inserted, x is a bool. We want to try and coerce data to match the column type if possible, otherwise use a null value. This will prevent inserts from failing outright.

BigQuery lists conversion rules here which may be helpful: https://cloud.google.com/bigquery/docs/reference/standard-sql/conversion_rules

  • Create new configuration option big BigQuery: strict_types bool. If it is set to true, then do not do any type conversion. If it is false, then do some sort of type conversion (either in SQL or on the go side) when inserting data.
@mohanish2504
Copy link
Contributor

Hey @poundifdef is it okay if I look this over the weekend?

@poundifdef
Copy link
Contributor Author

Hey @poundifdef is it okay if I look this over the weekend?

Feel free to make a PR. Just a heads-up, there is not a bounty on this one. (If you're looking for a bounty, #126 is available.)

@mohanish2504
Copy link
Contributor

mohanish2504 commented Mar 20, 2024

I am aware of it, I will look into this over weekend

@mohanish2504
Copy link
Contributor

Not sure how this will be handled during LOAD function.

Need to check each column being entered, if doesnot match the value then do conversion on go itself?

Does this logic looks good?

@poundifdef
Copy link
Contributor Author

Could you CAST data in sql?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants