Google BigQuery:"无效的源格式CSV"从Datalab加载数据时

时间:2016-06-04 14:09:32

标签: google-bigquery google-cloud-storage google-cloud-datalab

我有一些文件存储在Google云端存储中,我从Google Cloud Datalab的笔记本中运行以下内容:

path = r'data/path/to/csv/orders_1234'
orders_path = os.path.join(bucket_path, path)
print(orders_path)
dest = 'project_name:dataset_name.orders'
%bigquery load -m append -f csv -d '\t' -S $orders_path -D $dest

但是在运行此代码时出现错误无效的源格式CSV 。你知道我在这里做错了吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

请尝试从working example存储库中获取以下datalab sample notebooks

import datalab.bigquery as bq
import datalab.storage as storage
import pandas as pd
from StringIO import StringIO

# Create the schema, conveniently using a DataFrame example.
%storage read --object gs://cloud-datalab-samples/cars.csv --variable cars
df = pd.read_csv(StringIO(cars))
schema = bq.Schema.from_dataframe(df)

# Create the dataset
bq.Dataset('sample').create()

# Create the table
sample_table = bq.Table('sample.cars').create(schema = schema, overwrite = True)

# Load csv file from GCS to Google BigQuery
sample_table.load('gs://cloud-datalab-samples/cars.csv', mode='append',
                  source_format = 'csv', csv_options=bq.CSVOptions(skip_leading_rows = 1))   

请注意:如果您使用的是旧版本的datalab,则可能必须使用import gcp.bigquery as bq代替import datalab.bigquery as bq

您可以在BigQuery console的“作业历史记录”页面上看到其他错误消息信息。