-
Notifications
You must be signed in to change notification settings - Fork 293
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
Cannot load_table_from_dataframe when BigQuery table has a JSON column. #1405
Comments
Same issue here :( |
Same here. Any workaround? |
So my issue was that when a JSON column is loaded to a DF column, the dataframe changes the format. For example, it changes double quotes to single quotes. To remedy, I do this sanitization step before writing to BQ. Let me know it that works!
PS: Also, when I set up the BQ table, I used the STRING data type to collect the JSON column and then use json_extract_scalar() to pull data out of it. I don't know if that's a good practice, but it works very well for me! |
Setting this to P3: there appears to be a workaround and due to limits on manpower and scheduling. |
After some investigation, I've determined that this particular issue appears to be resolved. I tested it using a specific example below and found that the issue stemmed from the nested JSON being automatically converted into a dictionary during the DataFrame creation process. Following this conversion, the client successfully loaded the example. I hope this insight might be helpful for anyone who encounters a similar situation in the future. Looking for another issue to be my first open source contribution 😅 Environment details json_data = [
{
"id": 1,
"name": "Alice",
"age": 30,
"address": {
"street": "123 Apple St",
"city": "New York",
"state": "NY",
"zip": 10001
}
},
{
"id": 2,
"name": "Bob",
"age": 35,
"address": {
"street": "456 Orange Ave",
"city": "Los Angeles",
"state": "CA",
"zip": 90001
}
},
]
df = pd.DataFrame(json_data)
load_job = client.load_table_from_dataframe(
df, "xenon-world-399922.oss.your_table"
)
load_job.result() |
Closing. |
Environment details
3.9.2
22.2.2
google-cloud-bigquery
version:2.34.4
Steps to reproduce
Stack trace
The text was updated successfully, but these errors were encountered: