public class BigQueryIO
extends java.lang.Object
projectId: the Cloud project id (defaults to
GcpOptions.getProject()).
datasetId: the BigQuery dataset id, unique within a project.
tableId: a table id, unique within a dataset.
BigQuery table references are stored as a TableReference, which comes
from the BigQuery Java Client API.
Tables can be referred to as Strings, with or without the projectId.
A helper function is provided (parseTableSpec(String)),
which parses the following string forms into a TableReference:
project_id]:[dataset_id].[table_id]
dataset_id].[table_id]
BigQueryIO.Read transformation.
This produces a PCollection<TableRow> as output:
PCollection<TableRow> shakespeare = pipeline.apply(
BigQueryIO.Read
.named("Read")
.from("clouddataflow-readonly:samples.weather_stations");
BigQueryIO.Write transformation.
This consumes a PCollection<TableRow> as input.
PCollection<TableRow> quotes = ...
List<TableFieldSchema> fields = new ArrayList<>();
fields.add(new TableFieldSchema().setName("source").setType("STRING"));
fields.add(new TableFieldSchema().setName("quote").setType("STRING"));
TableSchema schema = new TableSchema().setFields(fields);
quotes.apply(BigQueryIO.Write
.named("Write")
.to("my-project:output.output_table")
.withSchema(schema)
.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE));
See BigQueryIO.Write for details on how to specify if a write should
append to an existing table, replace the table, or verify that the table is
empty. Note that the dataset being written to must already exist.
| Modifier and Type | Class and Description |
|---|---|
static class |
BigQueryIO.Read
A PTransform that reads from a BigQuery table and returns a
PCollection<TableRow> containing each of the rows of the table. |
static class |
BigQueryIO.Write
A PTransform that writes a
PCollection<TableRow> containing rows
to a BigQuery table. |
| Constructor and Description |
|---|
BigQueryIO() |
| Modifier and Type | Method and Description |
|---|---|
static TableReference |
parseTableSpec(java.lang.String tableSpec)
Parse a table specification in the form
"[project_id]:[dataset_id].[table_id]" or "[dataset_id].[table_id]".
|
static java.lang.String |
toTableSpec(TableReference ref)
Returns a canonical string representation of the TableReference.
|
public static TableReference parseTableSpec(java.lang.String tableSpec)
If the project id is omitted, the default project id is used.
public static java.lang.String toTableSpec(TableReference ref)