我正在使用以下代码行从 Google Bigquery 获取数据。
public class BQTEST {
public static void main(String... args) throws Exception {
String datasetName = "mydataset";
String tableName = "mytable";
String projectId = "id-gcs";
String query =
"SELECT id, " +
"qtr, " +
"sales, " +
"year " +
"FROM `id-gcs.mydataset.mytable` " +
"where MOD(id,2) = 0";
BigQuery bigquery = BigQueryOptions.newBuilder().setProjectId(projectId)
.setCredentials(
ServiceAccountCredentials.fromStream(new
FileInputStream("gcs.json"))
)
.build().getService();
TableId tableId = TableId.of(projectId, datasetName, tableName);
QueryJobConfiguration queryConfig = QueryJobConfiguration
.newBuilder(query)
.setPriority(QueryJobConfiguration.Priority.BATCH)
.build();
try {
bigquery.query(queryConfig);
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
TableResult results = bigquery.listTableData(
tableId,
BigQuery.TableDataListOption.pageSize(1)
);
for (FieldValueList row : results.iterateAll()) {
System.out.printf(
"ID: %s qtr: %s sales: %s year: %s\n", row.get(0).getValue(), row.get(1).getValue(), row.get(2).getValue(), row.get(3).getValue());
}
}
}
我在源表中有 12 条记录,从 1,2,3...12 开始 id 值。由于我在 ID 上应用了 Mod,结果集的 id 值应为 2、4、6、8、10、12。
相反,它将整个数据作为结果集返回。
因此,where 子句中的条件不适用。
寻求帮助。