BigQuery

APIs

Data iterator for application and data source
public static Object getBigQueryIterator(String query, int startIndex, int pageSize);
public static Object getBigQueryIterator(String serviceName, String query, int startIndex, int pageSize);

List datasets and Tables
public static Object getBQDataSets();
public static Object getBQTables(String datasetName)
public static Object getTable(String datasetName, String tableName);

Sample Function

Following function runs a query and get rows in a paginated way.

import com.collager.trillo.model.BigQueryIterator;
import com.collager.trillo.pojo.Result;
import com.google.cloud.bigquery.Field;
import com.google.cloud.bigquery.FieldValue;
import com.google.cloud.bigquery.FieldValueList;
import java.util.List;

String query="SELECT * FROM project-trillort.stage3.Applications LIMIT 10";
BigQueryIterator iter = func.getBigQueryIterator(query, 0, 5);

while (iter.hasNextPage()) {
  func.logInfo("Getting page");
  Object page = iter.getPage();
  if (page instanceof Result) {
    func.logInfo("No more pages found: " + page.message);
  } else {
    func.logInfo("Getting column names");
    for (Field field : iter.getFieldList()) {
      func.logInfo("Column Name: " + field.getName());      
    }
    for (FieldValueList fieldValues : (List) page) {
      func.logInfo("Getting rows");
      for (FieldValue fieldValue : fieldValues) {
        func.logInfo("Value: " + fieldValue.getStringValue());
      }
    }
  }
}