2016-08-22 92 views
0

我有一個表不斷地接收流式插入(可能每秒數千)。流式插入時更新表模式

我有興趣使用更新功能(通過API調用)添加一列。我可以撥打Update將數據列添加到現有表中,而數據仍在插入中,而不用擔心丟失數據?

供參考,在這裏是我使用的列添加到表規劃代碼:

func addColumnToTable(service *bigquery.Service, project, dataset, table string, newCols map[string]string) bool { 
    resp, err := service.Tables.Get(project, dataset, table).Do() 
    if err != nil { 
     fmt.Println(err) 
     return false 
    } 

    for col, col_type := range newCols { 
     this_col := &bigquery.TableFieldSchema{} 
     this_col.Name = col 
     this_col.Type = col_type 
     resp.Schema.Fields = append(resp.Schema.Fields, this_col) 
    } 

    _, err = service.Tables.Update(project, dataset, table, resp).Do() 
    if err != nil { 
     fmt.Println(err) 
     return false 
    } 

    return true 
} 

回答

1

可以更新使用表tables.update的模式(只允許更新添加一列和放寬需求的一列)。

流式傳輸模式更新變得可見有一點點延遲。因此,在流式傳輸包含新列的數據(假設您的更新是添加了列)之前,您需要等待少量時間(最多5分鐘)。舊數據不會丟失。