2016-03-30 16 views
1

Cloud BigQueryにテーブルがありますが、サービスがあります.Tabledata.InsertAllコールでは、ネストされたフィールドにデータが挿入されます。Google BigQueryのテーブルのネストされたフィールドにデータを挿入

// works 
jsonRow["name"] = bigquery.JsonValue("Name") 

// doesn't work 
jsonRow["geo_location.City.Names.en"] = bigquery.JsonValue("Irvine") 

rows[index] = new(bigquery.TableDataInsertAllRequestRows) 
rows[index].Json = jsonRow 
insertRequest := &bigquery.TableDataInsertAllRequest{Rows: rows} 
insertRequest.IgnoreUnknownValues = true 

call := service.Tabledata.InsertAll(project, dataset, "analytics_events", insertRequest) 

if res, err := call.Do(); err!=nil{ 
    Log.Fatal("Unable to Insert to BigQuery ", err) 
    return err 
} 

答えて

0

jsonRowのキー内にドット表記を使用するのではなく、クライアント側で入れ子になったオブジェクトを作成する必要があります。

+0

ジェレミー、コードサンプルまたは要点はありますか?それは非常に役に立つでしょう –

1

実際には、スキーマの構造に一致するオブジェクト構造を構築する必要があります。

jsonRow["geo_location.City.Names.en"] = bigquery.JsonValue("Irvine") 

あなたが期待しているオブジェクト構造を作成しません:

ここで混乱が行があることです。あなたが実際に行われてきたJSONオブジェクトは、次のようになります。

{ 
    "geo_location.City.Names.en": "Irvine" 
} 

次のように見える何かをしたいのに対し:

{ 
    "geo_location": { 
    "City": { 
     "Names": { 
     "en": "Irvine" 
     } 
    } 
    } 
} 

だからあなたのコードは次のようになります。

// Probably not valid code. Just guessing. 
jsonRow["geo_location"] = bigquery.JsonObject() 
jsonRow["geo_location"]["City"] = bigquery.JsonObject() 
jsonRow["geo_location"]["City"]["Names"] = bigquery.JsonObject() 
jsonRow["geo_location"]["City"]["Names"]["en"] = bigquery.JsonValue("Irvine") 

希望をそれは助ける。

+0

どのような厄介なAPI .... – themihai

関連する問題