(1) テーブル作成関数
データ格納用のテーブルを作成しました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void createTable() { //BigQueryにテーブルを作成 | |
Field row[] = new Field[column+1]; | |
for(int i = 0; i < column; i++) { | |
row[i] = Field.of("sum"+i, LegacySQLTypeName.INTEGER); | |
} | |
row[column] = Field.of("index", LegacySQLTypeName.INTEGER); | |
Schema schema = Schema.of(row); | |
StandardTableDefinition tableDefinition = StandardTableDefinition.of(schema); | |
bigQuery.create(TableInfo.of(tableId, tableDefinition)); | |
} |
(2) データ格納関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void insertTotals(TableResult response, int index){ | |
System.out.println("Totals : Insert開始"); | |
for (FieldValueList row : response.iterateAll()) { | |
Map<String, Object> rowvalue = new HashMap<>(); | |
for(int i = 0; i < column; i++) { | |
rowvalue.put("sum"+i, row.get("sum"+i).getValue()); | |
} | |
rowvalue.put("index", index); | |
InsertAllRequest insertRequest = InsertAllRequest.newBuilder(tableId).addRow(rowvalue).build(); | |
InsertAllResponse insertResponse = bigQuery.insertAll(insertRequest); | |
} | |
} |
全体
https://github.com/smzn/BigQuery
シンプル
https://github.com/smzn/BigQuery_Insert
Streamingはデータが入るまである程度時間がかかるので、データが格納されていなくても間違いではないので注意。
0 件のコメント:
コメントを投稿