2015-05-02 569 views

回答

3

正如亚当所说,你可以使用该API表PATCH方法来更新架构列。另一种方法是使用bq。

你可以先通过做获取架构如下:

1:获取JSON模式:

TABLE=publicdata:samples.shakespeare 

bq show --format=prettyjson ${TABLE} > table.txt 

然后将模式从table.txt复制到schema.txt ...这将看起来像这样:

[ 
    { 
    "description": "A single unique word (where whitespace is the delimiter) extracted from a corpus.", 
    "mode": "REQUIRED", 
    "name": "word", 
    "type": "STRING" 
    }, 
    { 
    "description": "The number of times this word appears in this corpus.", 
    "mode": "REQUIRED", 
    "name": "word_count", 
    "type": "INTEGER" 
    }, 
    .... 
] 

2:设置描述字段为任何你想要的(如果它不在那里,添加它)。

3:告诉BigQuery使用添加的列更新架构。请注意,schema.txt必须包含完整的模式。

bq update --schema schema.txt -t ${TABLE} 
+0

嗨乔丹,我试过这种方法,但我不断收到错误:更新操作中的BigQuery错误:提供的架构不匹配表tableABC,可能是什么原因? – Echo

+0

听起来好像在你指定的那个和表上的那个之间检测到了一些其他的模式差异。如果它不起作用,你可以用一个新问题来描述它(在评论中描述可能太长)。 –

+0

对于冗长的评论感到抱歉,当我从检索到的模式文件中提取头文件和尾部文件时,它很有用,谢谢。 – Echo