【问题标题】:How to skip rows of csv file in BIGQUERY load API如何在 BIGQUERY 加载 API 中跳过 csv 文件的行
【发布时间】:2018-02-25 23:37:32
【问题描述】:

我正在尝试使用 BigQuery API 将 CSV 数据从云存储桶加载到 BigQuery 表 我的代码是:

def load_data_from_gcs(dataset_name, table_name, source):
    bigquery_client = bigquery.Client()
    dataset = bigquery_client.dataset(dataset_name)
    table = dataset.table(table_name)
    job_name = str(uuid.uuid4())

    job = bigquery_client.load_table_from_storage(
        job_name, table, source)
    job.sourceFormat = 'CSV'
    job.fieldDelimiter = ','
    job.skipLeadingRows = 2

    job.begin()
    job.result()  # Wait for job to complete

    print('Loaded {} rows into {}:{}.'.format(
        job.output_rows, dataset_name, table_name))

    wait_for_job(job)

它给了我错误:

400 CSV table encountered too many errors, giving up. Rows: 1; errors: 1.

这个错误是因为,我的 csv 文件包含前两行作为标题信息,并且不应该加载。我给了 job.skipLeadingRows = 2 但它没有跳过前 2 行。 是否有任何其他语法来设置跳过行?

请帮忙。

【问题讨论】:

    标签: google-bigquery google-cloud-storage


    【解决方案1】:

    您拼写错误(使用驼峰式而不是下划线)。这是skip_leading_rows,而不是skipLeadingRowsfield_delimitersource_format 相同。

    查看 Python 源代码here

    【讨论】:

    • 谢谢。是的,它奏效了。我已经想通了,但是是的,谢谢您的回复:)。
    • 我正在使用 Node JS @google-cloud/bigquery 1.2.0 版,bigquery .dataset(datasetId) .table(tableId) .load(fileName, {skipLeadingRows: 1}) =>作品
    猜你喜欢
    • 2014-11-02
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-29
    • 1970-01-01
    相关资源
    最近更新 更多