@@ -438,6 +438,8 @@ public Table createTable(String datasetName, String tableName, String fieldName)
438438 // [VARIABLE "my_table_name"]
439439 public Page <FieldValueList > listTableData (String datasetName , String tableName ) {
440440 // [START listTableData]
441+ // This example reads the result 100 rows per RPC call. If there's no need to limit the number,
442+ // simply omit the option.
441443 Page <FieldValueList > tableData =
442444 bigquery .listTableData (datasetName , tableName , TableDataListOption .pageSize (100 ));
443445 for (FieldValueList row : tableData .iterateAll ()) {
@@ -456,6 +458,8 @@ public Page<FieldValueList> listTableData(String datasetName, String tableName)
456458 public Page <FieldValueList > listTableDataFromId (String datasetName , String tableName ) {
457459 // [START listTableDataFromId]
458460 TableId tableIdObject = TableId .of (datasetName , tableName );
461+ // This example reads the result 100 rows per RPC call. If there's no need to limit the number,
462+ // simply omit the option.
459463 Page <FieldValueList > tableData =
460464 bigquery .listTableData (tableIdObject , TableDataListOption .pageSize (100 ));
461465 for (FieldValueList row : tableData .iterateAll ()) {
@@ -465,6 +469,43 @@ public Page<FieldValueList> listTableDataFromId(String datasetName, String table
465469 return tableData ;
466470 }
467471
472+ /** Example of listing table rows with schema. */
473+ // [TARGET listTableData(String, String, Schema, TableDataListOption...)]
474+ // [VARIABLE "my_dataset_name"]
475+ // [VARIABLE "my_table_name"]
476+ // [VARIABLE ...]
477+ // [VARIABLE "field"]
478+ public Page <FieldValueList > listTableDataSchema (
479+ String datasetName , String tableName , Schema schema , String field ) {
480+ // [START listTableDataSchema]
481+ Page <FieldValueList > tableData =
482+ bigquery .listTableData (datasetName , tableName , schema );
483+ for (FieldValueList row : tableData .iterateAll ()) {
484+ row .get (field );
485+ }
486+ // [END listTableDataSchema]
487+ return tableData ;
488+ }
489+
490+ /** Example of listing table rows with schema. */
491+ // [TARGET listTableData(TableId, Schema, TableDataListOption...)]
492+ public FieldValueList listTableDataSchemaId () {
493+ // [START listTableDataSchemaId]
494+ Schema schema =
495+ Schema .of (
496+ Field .of ("word" , LegacySQLTypeName .STRING ),
497+ Field .of ("word_count" , LegacySQLTypeName .STRING ),
498+ Field .of ("corpus" , LegacySQLTypeName .STRING ),
499+ Field .of ("corpus_date" , LegacySQLTypeName .STRING ));
500+ Page <FieldValueList > page =
501+ bigquery .listTableData (
502+ TableId .of ("bigquery-public-data" , "samples" , "shakespeare" ), schema );
503+ FieldValueList row = page .getValues ().iterator ().next ();
504+ System .out .println (row .get ("word" ).getStringValue ());
505+ // [END listTableDataSchemaId]
506+ return row ;
507+ }
508+
468509 /**
469510 * Example of creating a query job.
470511 */
0 commit comments