use of com.google.api.services.bigquery.model.TableFieldSchema in project zeppelin by apache.
the class BigQueryInterpreter method printRows.
// Function that generates and returns the schema and the rows as string
public static String printRows(final GetQueryResultsResponse response) {
StringBuilder msg = new StringBuilder();
try {
List<String> schemNames = new ArrayList<String>();
for (TableFieldSchema schem : response.getSchema().getFields()) {
schemNames.add(schem.getName());
}
msg.append(Joiner.on(TAB).join(schemNames));
msg.append(NEWLINE);
for (TableRow row : response.getRows()) {
List<String> fieldValues = new ArrayList<String>();
for (TableCell field : row.getF()) {
fieldValues.add(field.getV().toString());
}
msg.append(Joiner.on(TAB).join(fieldValues));
msg.append(NEWLINE);
}
return msg.toString();
} catch (NullPointerException ex) {
throw new NullPointerException("SQL Execution returned an error!");
}
}
use of com.google.api.services.bigquery.model.TableFieldSchema in project beam by apache.
the class CombinePerKeyExamples method main.
public static void main(String[] args) throws Exception {
Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
Pipeline p = Pipeline.create(options);
// Build the table schema for the output table.
List<TableFieldSchema> fields = new ArrayList<>();
fields.add(new TableFieldSchema().setName("word").setType("STRING"));
fields.add(new TableFieldSchema().setName("all_plays").setType("STRING"));
TableSchema schema = new TableSchema().setFields(fields);
p.apply(BigQueryIO.readTableRows().from(options.getInput())).apply(new PlaysForWord()).apply(BigQueryIO.writeTableRows().to(options.getOutput()).withSchema(schema).withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED).withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE));
p.run().waitUntilFinish();
}
use of com.google.api.services.bigquery.model.TableFieldSchema in project beam by apache.
the class FilterExamples method buildWeatherSchemaProjection.
/**
* Helper method to build the table schema for the output table.
*/
private static TableSchema buildWeatherSchemaProjection() {
List<TableFieldSchema> fields = new ArrayList<>();
fields.add(new TableFieldSchema().setName("year").setType("INTEGER"));
fields.add(new TableFieldSchema().setName("month").setType("INTEGER"));
fields.add(new TableFieldSchema().setName("day").setType("INTEGER"));
fields.add(new TableFieldSchema().setName("mean_temp").setType("FLOAT"));
return new TableSchema().setFields(fields);
}
use of com.google.api.services.bigquery.model.TableFieldSchema in project beam by apache.
the class MaxPerKeyExamples method main.
public static void main(String[] args) throws Exception {
Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
Pipeline p = Pipeline.create(options);
// Build the table schema for the output table.
List<TableFieldSchema> fields = new ArrayList<>();
fields.add(new TableFieldSchema().setName("month").setType("INTEGER"));
fields.add(new TableFieldSchema().setName("max_mean_temp").setType("FLOAT"));
TableSchema schema = new TableSchema().setFields(fields);
p.apply(BigQueryIO.readTableRows().from(options.getInput())).apply(new MaxMeanTemp()).apply(BigQueryIO.writeTableRows().to(options.getOutput()).withSchema(schema).withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED).withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE));
p.run().waitUntilFinish();
}
use of com.google.api.services.bigquery.model.TableFieldSchema in project beam by apache.
the class WriteToBigQuery method getSchema.
/**
* Build the output table schema.
*/
protected TableSchema getSchema() {
List<TableFieldSchema> fields = new ArrayList<>();
for (Map.Entry<String, FieldInfo<InputT>> entry : fieldInfo.entrySet()) {
String key = entry.getKey();
FieldInfo<InputT> fcnInfo = entry.getValue();
String bqType = fcnInfo.getFieldType();
fields.add(new TableFieldSchema().setName(key).setType(bqType));
}
return new TableSchema().setFields(fields);
}
Aggregations