【发布时间】:2022-01-27 16:53:28
【问题描述】:
我正在使用以下代码从 BigQuery 获取数据。
public class BQTEST {
public static void main(String... args) throws Exception {
String datasetName = "mydataset";
String tableName = "mytable";
String projectId = "gcs";
String query =
"SELECT id, " +
"qtr, " +
"sales, " +
"year " +
"FROM `gcs.mydataset.mytable` " +
;
BigQuery bigquery = BigQueryOptions.newBuilder().setProjectId(projectId)
.setCredentials(
ServiceAccountCredentials.fromStream(new
FileInputStream("20a3c78f8388.json"))
)
.build().getService();
TableId tableId = TableId.of(projectId, datasetName, tableName);
QueryJobConfiguration queryConfig = QueryJobConfiguration
.newBuilder(query)
.build();
try {
bigquery.query(queryConfig);
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
TableResult results = bigquery.listTableData(
tableId,
BigQuery.TableDataListOption.pageSize(1),
BigQuery.TableDataListOption.startIndex(5)
);
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());
}
}
}
BigQuery.TableDataListOption.startIndex(5) -- 这将有助于从第 5 个索引读取数据,索引从 0 开始。
但我想分块读取数据,例如一个进程中的前 10 条记录,然后是另一个进程中的下 20 条记录,等等。
尝试在并行进程中从一个非常大的表中读取数据。这是一个截断/加载表。所以没有分区和日期范围来读取数据。
我找不到在任何 BigQuery 方法中赋予 LAST_INDEX 值的方法。
有人可以帮忙吗?
【问题讨论】:
标签: java google-cloud-platform google-bigquery