2

I am trying to list the table data from BigQuery using JAVA. However I am not able to find how to configure API to get maximum rows per call?

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);
        }
    }
}

1 Answer 1

2

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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.