【发布时间】:2017-04-06 22:38:03
【问题描述】:
我正在使用以下代码从 FILENAME 插入日志。日志文件包含 1000 行。每隔几秒钟就会添加新行。但是,当我运行此代码时,结果表只有 15-20 奇数行。
Rows dfpadunit = new TableDataInsertAllRequest.Rows();
List<Rows> dfpadunits = new ArrayList<Rows>();
TableDataInsertAllRequest content = new TableDataInsertAllRequest();
content.setIgnoreUnknownValues(true);
content.setSkipInvalidRows(true);
reader = new BufferedReader(new FileReader( FILENAME ) );
while( running ) {
while ((line = reader.readLine()) != null) {
TableRow aRow = new TableRow();
aRow.set("RAW_DATA", line);
String time = BigqueryUtils.getCurrentYYMMDDHHMM();
aRow.set("TIME", time);
dfpadunit.setJson(aRow);
dfpadunit.setInsertId(time);
dfpadunits.add(dfpadunit);
}
if(dfpadunits.size() > 0) {
content.setRows(dfpadunits);
TableDataInsertAllResponse response = BQUtils.run(PRE_STG_DATA_SET_ID, DESTINATION_TABLE, content);
dfpadunits.clear();
if(response != null) {
formatTable();
}
}
System.out.println("About to sleep");
Thread.sleep( 1000 * 60);
}
【问题讨论】:
-
如何在 BigQuery 中检查表的大小?
-
一个简单的选择计数(*)。一天后我也试过了,还是一样。
-
插入用作去重键。您正在使用当前时间(以分钟为单位)作为插入 ID。这意味着在同一分钟内的所有插入都使用相同的重复数据删除密钥——只有最后一个保留。您需要将插入 ID 留空或使用随机生成的 ID 作为插入 ID
-
@PavanEdara 修复了它。如果您将回复添加为答案,我会将其标记为已修复。谢谢!
标签: google-bigquery