简体   繁体   English

CLI“ bq load”-如何使用不可打印字符作为分隔符?

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

I'm having trouble loading data into BigQuery as a single column row. 我在将数据作为单列行加载到BigQuery时遇到了麻烦。 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. 我希望BigQuery能够提供“没有定界符”作为选项,但是与此同时,我需要选择我能找到的最模糊的ASCII定界符,这样我的单列行就不会分成几列。

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. 这样做时,CLI不允许我输入奇怪的字符,因此我需要通过Python或其他渠道使用API​​。

How can I use the CLI instead with a non printable character? 如何使用带有不可打印字符的CLI?

Python example from BigQuery lazy data loading: DDL, DML, partitions, and half a trillion Wikipedia pageviews : BigQuery延迟数据加载的 Python示例:DDL,DML,分区和六十亿亿个Wikipedia页面浏览量

#!/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 = ''

To use a non-printable character with BQ load you can use echo in bash: 要在BQ加载中使用不可打印的字符,可以在bash中使用echo

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM