Class BigQueryUtils
java.lang.Object
org.apache.beam.sdk.io.gcp.bigquery.BigQueryUtils
Utility methods for BigQuery related operations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Options for how to convert BigQuery data to Beam data.static class
Options for how to convert BigQuery schemas to Beam schemas. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
convertAvroFormat
(Schema.FieldType beamFieldType, Object avroValue, BigQueryUtils.ConversionOptions options) Tries to convert an Avro decoded value to a Beam field value based on the target type of the Beam field.static TableRow
Convert generic record to Bq TableRow.static TableRow
convertGenericRecordToTableRow
(GenericRecord record, TableSchema tableSchema) Deprecated.static TableSchema
fromGenericAvroSchema
(Schema schema) Convert an AvroSchema
to a BigQueryTableSchema
.static TableSchema
fromGenericAvroSchema
(Schema schema, Boolean useAvroLogicalTypes) Convert an AvroSchema
to a BigQueryTableSchema
.static Schema
fromTableSchema
(TableSchema tableSchema) Convert a BigQueryTableSchema
to a BeamSchema
.static Schema
fromTableSchema
(TableSchema tableSchema, BigQueryUtils.SchemaConversionOptions options) Convert a BigQueryTableSchema
to a BeamSchema
.static @Nullable org.apache.beam.runners.core.metrics.ServiceCallMetric
readCallMetric
(@Nullable TableReference tableReference) static final org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TypedRead.FromBeamRowFunction
<TableRow> static final org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TypedRead.ToBeamRowFunction
<TableRow> static Row
toBeamRow
(GenericRecord record, Schema schema, BigQueryUtils.ConversionOptions options) static Row
static Row
toBeamRow
(Schema rowSchema, TableSchema bqSchema, TableRow jsonBqRow) Tries to parse the JSONTableRow
from BigQuery.static Schema
toGenericAvroSchema
(TableSchema tableSchema) Convert a BigQueryTableSchema
to AvroSchema
.static Schema
toGenericAvroSchema
(TableSchema tableSchema, Boolean useAvroLogicalTypes) Convert a BigQueryTableSchema
to AvroSchema
.static Schema
toGenericAvroSchema
(String schemaName, List<TableFieldSchema> fieldSchemas) Convert a list of BigQueryTableFieldSchema
to AvroSchema
.static Schema
toGenericAvroSchema
(String schemaName, List<TableFieldSchema> fieldSchemas, Boolean useAvroLogicalTypes) Convert a list of BigQueryTableFieldSchema
to AvroSchema
.static @Nullable TableReference
toTableReference
(String fullTableId) static SerializableFunction
<Row, TableRow> static <T> SerializableFunction
<T, TableRow> toTableRow
(SerializableFunction<T, Row> toRow) Convert a Beam schema type to a BigQueryTableRow
.static TableRow
toTableRow
(Row row) Convert a Beam Row to a BigQuery TableRow.static TableSchema
toTableSchema
(Schema schema) Convert a BeamSchema
to a BigQueryTableSchema
.toTableSpec
(TableReference tableReference) static org.apache.beam.runners.core.metrics.ServiceCallMetric
writeCallMetric
(TableReference tableReference)
-
Constructor Details
-
BigQueryUtils
public BigQueryUtils()
-
-
Method Details
-
toTableSchema
Convert a BeamSchema
to a BigQueryTableSchema
. -
fromTableSchema
Convert a BigQueryTableSchema
to a BeamSchema
. -
fromTableSchema
public static Schema fromTableSchema(TableSchema tableSchema, BigQueryUtils.SchemaConversionOptions options) Convert a BigQueryTableSchema
to a BeamSchema
. -
toGenericAvroSchema
Convert a BigQueryTableSchema
to AvroSchema
. -
fromGenericAvroSchema
Convert an AvroSchema
to a BigQueryTableSchema
. -
fromGenericAvroSchema
Convert an AvroSchema
to a BigQueryTableSchema
. -
toGenericAvroSchema
Convert a BigQueryTableSchema
to AvroSchema
. -
toGenericAvroSchema
Convert a list of BigQueryTableFieldSchema
to AvroSchema
. -
toGenericAvroSchema
public static Schema toGenericAvroSchema(String schemaName, List<TableFieldSchema> fieldSchemas, Boolean useAvroLogicalTypes) Convert a list of BigQueryTableFieldSchema
to AvroSchema
. -
tableRowToBeamRow
public static final org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TypedRead.ToBeamRowFunction<TableRow> tableRowToBeamRow() -
tableRowFromBeamRow
public static final org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TypedRead.FromBeamRowFunction<TableRow> tableRowFromBeamRow() -
toTableRow
-
toTableRow
Convert a Beam schema type to a BigQueryTableRow
. -
toBeamRow
public static Row toBeamRow(GenericRecord record, Schema schema, BigQueryUtils.ConversionOptions options) -
convertGenericRecordToTableRow
@Deprecated public static TableRow convertGenericRecordToTableRow(GenericRecord record, TableSchema tableSchema) Deprecated.Convert generic record to Bq TableRow. -
convertGenericRecordToTableRow
Convert generic record to Bq TableRow. -
toTableRow
Convert a Beam Row to a BigQuery TableRow. -
toBeamRow
-
toBeamRow
Tries to parse the JSONTableRow
from BigQuery.Only supports basic types and arrays. Doesn't support date types.
-
convertAvroFormat
public static Object convertAvroFormat(Schema.FieldType beamFieldType, Object avroValue, BigQueryUtils.ConversionOptions options) Tries to convert an Avro decoded value to a Beam field value based on the target type of the Beam field.For the Avro formats of BigQuery types, see https://cloud.google.com/bigquery/docs/exporting-data#avro_export_details and https://cloud.google.com/bigquery/docs/loading-data-cloud-storage-avro#avro_conversions
-
toTableReference
- Parameters:
fullTableId
- - Is one of the two forms commonly used to refer to bigquery tables in the beam codebase:- projects/{project_id}/datasets/{dataset_id}/tables/{table_id}
- myproject:mydataset.mytable
- myproject.mydataset.mytable
- Returns:
- a BigQueryTableIdentifier by parsing the fullTableId. If it cannot be parsed properly null is returned.
-
toTableSpec
- Parameters:
tableReference
- - a BigQueryTableIdentifier that may or may not include the project.- Returns:
- a String representation of the table destination in the form: `myproject.mydataset.mytable`
-
readCallMetric
public static @Nullable org.apache.beam.runners.core.metrics.ServiceCallMetric readCallMetric(@Nullable TableReference tableReference) - Parameters:
tableReference
- - The table being read from. Can be a temporary BQ table used to read from a SQL query.- Returns:
- a ServiceCallMetric for recording statuses for all BQ API responses related to reading elements directly from BigQuery in a process-wide metric. Such as: calls to readRows, splitReadStream, createReadSession.
-
writeCallMetric
public static org.apache.beam.runners.core.metrics.ServiceCallMetric writeCallMetric(TableReference tableReference) - Parameters:
tableReference
- - The table being written to.- Returns:
- a ServiceCallMetric for recording statuses for all BQ responses related to writing elements directly to BigQuery in a process-wide metric. Such as: insertAll.
-
convertGenericRecordToTableRow(GenericRecord)