5

Zasadniczo mój kod wygląda oficjalny przykład w https://cloud.google.com/bigquery/streaming-data-into-bigquerydane wstawić do tabeli BigQuery

mój kod:

TableRow data = new TableRow(); 
data.set("type", eventType); 
data.set("timestamp", new Date()); 

TableDataInsertAllRequest.Rows row = new TableDataInsertAllRequest.Rows(); 
row.setInsertId(System.currentTimeMillis()); 
row.setJson(data); 
request = new TableDataInsertAllRequest(); 
request.setRows(Arrays.asList(row)); 

TableDataInsertAllResponse response = bigquery.tabledata().insertAll(projectId, datasetId, tableId, request).execute(); 
for (TableDataInsertAllResponse.InsertErrors err: response.getInsertErrors()) { 
    for (ErrorProto ep: err.getErrors()) { 
     log.error(ep.getReason() + " : " + ep.getMessage() + " at " + ep.getLocation()); 
    } 
} 

Ale otrzymuję błąd:

invalid : JSON map specified for non-record field at null 

Wydaje się, że tęskniłem za coś , ale nie mam pojęcia, co jest nie tak z moim kodem. Mam dwa pola, String i Date, a komunikat o błędzie nie ma dla mnie żadnego sensu.

Jak wstawić dane do tabeli BigQuery?

+0

Witam czy możesz odpowiedzieć na to pytanie http://stackoverflow.com/questions/40481371/io-exception-while-inserting-data-in-table-on-big-query –

Odpowiedz

13

Po kilku godzinach debugowania okazało się, że klient Java BigQuery nie obsługuje wartości Date. I powinno się używać opakowania typu com.google.api.client.util.DateTime.

Więc zamiast

data.set("timestamp", new Date()); 

nie powinno być:

data.set("timestamp", new DateTime(new Date())); 

nadzieję, że pomoże ktoś.

+0

Prawdopodobnie @AlexMartelli przyjmie on, ale musi to zrobić 48 godzin. – Pentium10

+0

Mam ten błąd: obiekt JSON określony dla pola innego niż rekord: timestamp ... Jaki jest typ pola "datownik"? Mój jest DATE, ale czy powinien to być DATE_TIME? – CCC

Powiązane problemy