CLI “bq load” - how to use non-printable character as delimiter?

自作多情 提交于 2019-12-12 09:27:14

问题


I'm having trouble loading data into BigQuery as a single column row. I wish BigQuery offered the ability to have "no delimiter" as an option, but in the meantime I need to choose the most obscure ASCII delimiter I can find so my single column row is not split into columns.

When doing this the CLI won't allow me to input strange characters, so I need to use the API through Python or other channels.

How can I use the CLI instead with a non printable character?

Python example from BigQuery lazy data loading: DDL, DML, partitions, and half a trillion Wikipedia pageviews:

#!/bin/python
from google.cloud import bigquery
bq_client = bigquery.Client(project='fh-bigquery')
table_ref = bq_client.dataset('views').table('wikipedia_views_gcs')
table = bigquery.Table(table_ref, schema=SCHEMA)
extconfig = bigquery.ExternalConfig('CSV')
extconfig.schema = [bigquery.SchemaField('line', 'STRING')]
extconfig.options.field_delimiter = u'\u00ff'
extconfig.options.quote_character = ''

回答1:


To use a non-printable character with BQ load you can use echo in bash:

bq load \
 --source_format=CSV \
 --field_delimiter=$(echo -en "\x01") \
 --noreplace --max_bad_records=100 \
 <bq_dataset>.<bq_table> gs://<bucket_name>/<file_name>.csv


来源:https://stackoverflow.com/questions/55700063/cli-bq-load-how-to-use-non-printable-character-as-delimiter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!