java - 用于列出表数据的 Java BigQuery API
问题描述
我正在尝试使用 JAVA 从 BigQuery 中列出表数据。但是我无法找到如何配置 API 以获取每次调用的最大行数?
public class QuickstartSample {
public static void main(String... args) throws Exception {
GoogleCredentials credentials;
File credentialsPath = new File("/Users/gaurang.shah/Downloads/fb3735b731b9.json"); // TODO: update to your key path.
FileInputStream serviceAccountStream = new FileInputStream(credentialsPath);
credentials = ServiceAccountCredentials.fromStream(serviceAccountStream);
BigQuery bigquery = BigQueryOptions.newBuilder().
setCredentials(credentials).
setProjectId("bigquery-public-data").
build().
getService();
Dataset hacker_news = bigquery.getDataset("hacker_news");
Table comments = hacker_news.get("comments");
TableResult result = comments.list().;
for (FieldValueList row : result.iterateAll()) {
// do something with the row
System.out.println(row);
}
}
}
解决方案
To limit the number of rows you can use listTableData
method with TableDataListOption.pageSize(n)
parameter.
Following example returns 100 rows as the result:
String datasetName = "my_dataset_name";
String tableName = "my_table_name";
TableId tableIdObject = TableId.of(datasetName, tableName);
TableResult tableData =
bigquery.listTableData(tableIdObject, TableDataListOption.pageSize(100));
for (FieldValueList row : tableData.iterateAll()) {
// do something with the row
}
推荐阅读
- mongodb - 根据MongoDB中两个日期的差异统计记录
- java - Java Axon 从 2.4.2 版本迁移到 4.0.3
- javascript - 从 git 子模块导入 Typescript 文件并使用 create-react-app 进行转换
- html - 将动画应用于包含背景颜色的最后一个元素 li:after #a1c642
- c++ - 以编程方式将蓝牙设备配对为音频设备
- android - 反应原生应用程序图标问题。应用程序菜单中的应用程序图标未更改
- rust - 如何在 Rust 中以编程方式读取属性
- vuejs2 - 添加没有 ES6 或 webpack 的库
- c# - 使用 WMI 远程查询服务
- angular - HttpClient 不发出 http 网络请求