2017-08-14 28 views
1

我需要從平面文件的BigQuery表格上傳記錄 這裏是用分隔符爲‘$’上傳示例文件:如何引號字符(「)上傳到在Python腳本中使用API​​ BigQuery表格

LCR_REF_OPS_DEPOSITS$amm_reporting_row:string,amm_section:string,amm_report_row_desc:string,amm_subsection_row:float,amm_subsection_desc:string$$csv$|$REF$1$"$$$$TRUE$Sample file$ALT REF 

問題是,在我需要上傳引號字符(「)和上傳失敗,因爲它的列之一。 下面是API的代碼片段,我使用:遇到

bigquery_client = bigquery.Client() 
dataset = bigquery_client.dataset('DATASET1') 
table = dataset.table('SAMPLE_TAB') 
# Reload the table to get the schema. 
table.reload() 
with open('testfile.txt', 'rb') as source_file: 
    # This example uses CSV, but you can use other formats. 
    # See https://cloud.google.com/bigquery/loading-data 
    job = table.upload_from_file(
     source_file, source_format='text/csv', field_delimiter='$') 

錯誤:

google.cloud.exceptions.BadRequest: 400 CSV table encountered too many errors, giving up. Rows: 1; errors: 1. 

任何人都可以建議如何做到這一點?

回答

1

"字符是used as default由BigQuery在讀取數據時包含記錄。

這可能是你,然後一個解決辦法:

with open('testfile.txt', 'rb') as source_file: 
    job = table.upload_from_file(
     source_file, 
     source_format='text/csv', 
     field_delimiter='$', 
     quote_character='') 
+0

這是有幫助的。謝謝:) – GaurangR

+0

我試過上面的選項,它可以正常工作,當我給出像(「」)的引號時,但是如果我只想給出雙引號(「),它就會失敗 – GaurangR

+0

@GaurangR不太明白你的意思。你有一個例子 –

相關問題