google-cloud-python icon indicating copy to clipboard operation
google-cloud-python copied to clipboard

BigQuery: how are field names derived when uploading from GCS using autodetect?

Open DavisWang-LR opened this issue 7 years ago • 3 comments

job_config = bigquery.LoadJobConfig()
job_config.autodetect = True
job_config.skip_leading_rows = 1

I use autodetect to load data to BigQuery, but I find a question. If all the columns in my file are the STRING type, the field name of the table is the default naming convention. Smaple data:

ppid|channel|customer_id|hhd_num|country|birth_dt|gender|valid_email|valid_mobile|valid_mail f2b83c24|a8|1b2d524a4d|36fb93c9|FRA|a197312|aF|aN|aY|aY

As follows. 1 But if I change one column to the INTEGER type, the field name will use file's header. Sample data:

ppid|channel|customer_id|hhd_num|country|birth_dt|gender|valid_email|valid_mobile|valid_mail f2b83c24|8|1b2d524a4d|36fb93c9|FRA|a197312|aF|aN|aY|aY

As follows. 2

DavisWang-LR avatar Jul 08 '19 08:07 DavisWang-LR

It looks like that is the default behavior of BigQuery Autodetect import. more about this here https://stackoverflow.com/questions/48590983/how-to-have-google-bigquery-properly-detect-header-names and here https://issuetracker.google.com/issues/112210765

I'm dealing with the same issue as well :)

zdenulo avatar Aug 01 '19 16:08 zdenulo

Since CSV parsing is done entirely in the backend, there is nothing we can do in the client. Please +1 the issue at https://issuetracker.google.com/112210765 if this affects you, or escalate it using your support contract if you have one.

tswast avatar Nov 12 '19 22:11 tswast

One issue I encountered while uploading data to a BigQuery table is that the column names are in Chinese characters. the data in these columns appears as null. How can this issue be resolved?

`import pandas as pd import pandas_gbq from google.oauth2 import service_account from google.cloud import bigquery

data = { '学生姓名': ['张三', '李四', '王五'], '年龄': [20, 22, 21], '成绩': [85, 90, 88] } df = pd.DataFrame(data)

pandas_gbq.to_gbq(df, 'your_dataset.your_table', project_id='your_project_id', if_exists='replace', credentials=credentials, table_schema=schema) `

image

MSaadMakhdoom avatar Apr 19 '24 17:04 MSaadMakhdoom