Class BigQueryUtils
- java.lang.Object
-
- org.apache.beam.sdk.io.gcp.bigquery.BigQueryUtils
-
public class BigQueryUtils extends java.lang.ObjectUtility methods for BigQuery related operations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBigQueryUtils.ConversionOptionsOptions for how to convert BigQuery data to Beam data.static classBigQueryUtils.SchemaConversionOptionsOptions for how to convert BigQuery schemas to Beam schemas.
-
Constructor Summary
Constructors Constructor Description BigQueryUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.ObjectconvertAvroFormat(org.apache.beam.sdk.schemas.Schema.FieldType beamFieldType, java.lang.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 com.google.api.services.bigquery.model.TableRowconvertGenericRecordToTableRow(org.apache.avro.generic.GenericRecord record)Convert generic record to Bq TableRow.static com.google.api.services.bigquery.model.TableRowconvertGenericRecordToTableRow(org.apache.avro.generic.GenericRecord record, com.google.api.services.bigquery.model.TableSchema tableSchema)Deprecated.static com.google.api.services.bigquery.model.TableSchemafromGenericAvroSchema(org.apache.avro.Schema schema)Convert an AvroSchemato a BigQueryTableSchema.static com.google.api.services.bigquery.model.TableSchemafromGenericAvroSchema(org.apache.avro.Schema schema, java.lang.Boolean useAvroLogicalTypes)Convert an AvroSchemato a BigQueryTableSchema.static org.apache.beam.sdk.schemas.SchemafromTableSchema(com.google.api.services.bigquery.model.TableSchema tableSchema)Convert a BigQueryTableSchemato a BeamSchema.static org.apache.beam.sdk.schemas.SchemafromTableSchema(com.google.api.services.bigquery.model.TableSchema tableSchema, BigQueryUtils.SchemaConversionOptions options)Convert a BigQueryTableSchemato a BeamSchema.static @Nullable org.apache.beam.runners.core.metrics.ServiceCallMetricreadCallMetric(@Nullable com.google.api.services.bigquery.model.TableReference tableReference)static org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TypedRead.FromBeamRowFunction<com.google.api.services.bigquery.model.TableRow>tableRowFromBeamRow()static org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TypedRead.ToBeamRowFunction<com.google.api.services.bigquery.model.TableRow>tableRowToBeamRow()static org.apache.beam.sdk.values.RowtoBeamRow(org.apache.avro.generic.GenericRecord record, org.apache.beam.sdk.schemas.Schema schema, BigQueryUtils.ConversionOptions options)static org.apache.beam.sdk.values.RowtoBeamRow(org.apache.beam.sdk.schemas.Schema rowSchema, com.google.api.services.bigquery.model.TableRow jsonBqRow)Tries to convert a JSONTableRowfrom BigQuery into a BeamRow.static org.apache.beam.sdk.values.RowtoBeamRow(org.apache.beam.sdk.schemas.Schema rowSchema, com.google.api.services.bigquery.model.TableSchema bqSchema, com.google.api.services.bigquery.model.TableRow jsonBqRow)Tries to parse the JSONTableRowfrom BigQuery.static org.apache.avro.SchematoGenericAvroSchema(com.google.api.services.bigquery.model.TableSchema tableSchema)Convert a BigQueryTableSchemato AvroSchema.static org.apache.avro.SchematoGenericAvroSchema(com.google.api.services.bigquery.model.TableSchema tableSchema, java.lang.Boolean useAvroLogicalTypes)Convert a BigQueryTableSchemato AvroSchema.static org.apache.avro.SchematoGenericAvroSchema(java.lang.String schemaName, java.util.List<com.google.api.services.bigquery.model.TableFieldSchema> fieldSchemas)Convert a list of BigQueryTableFieldSchemato AvroSchema.static org.apache.avro.SchematoGenericAvroSchema(java.lang.String schemaName, java.util.List<com.google.api.services.bigquery.model.TableFieldSchema> fieldSchemas, java.lang.Boolean useAvroLogicalTypes)Convert a list of BigQueryTableFieldSchemato AvroSchema.static @Nullable com.google.api.services.bigquery.model.TableReferencetoTableReference(java.lang.String fullTableId)static org.apache.beam.sdk.transforms.SerializableFunction<org.apache.beam.sdk.values.Row,com.google.api.services.bigquery.model.TableRow>toTableRow()Convert a BeamRowto a BigQueryTableRow.static <T> org.apache.beam.sdk.transforms.SerializableFunction<T,com.google.api.services.bigquery.model.TableRow>toTableRow(org.apache.beam.sdk.transforms.SerializableFunction<T,org.apache.beam.sdk.values.Row> toRow)Convert a Beam schema type to a BigQueryTableRow.static com.google.api.services.bigquery.model.TableRowtoTableRow(org.apache.beam.sdk.values.Row row)Convert a Beam Row to a BigQuery TableRow.static com.google.api.services.bigquery.model.TableSchematoTableSchema(org.apache.beam.sdk.schemas.Schema schema)Convert a BeamSchemato a BigQueryTableSchema.static @Nullable java.lang.StringtoTableSpec(com.google.api.services.bigquery.model.TableReference tableReference)static org.apache.beam.runners.core.metrics.ServiceCallMetricwriteCallMetric(com.google.api.services.bigquery.model.TableReference tableReference)
-
-
-
Method Detail
-
toTableSchema
public static com.google.api.services.bigquery.model.TableSchema toTableSchema(org.apache.beam.sdk.schemas.Schema schema)
Convert a BeamSchemato a BigQueryTableSchema.
-
fromTableSchema
public static org.apache.beam.sdk.schemas.Schema fromTableSchema(com.google.api.services.bigquery.model.TableSchema tableSchema)
Convert a BigQueryTableSchemato a BeamSchema.
-
fromTableSchema
public static org.apache.beam.sdk.schemas.Schema fromTableSchema(com.google.api.services.bigquery.model.TableSchema tableSchema, BigQueryUtils.SchemaConversionOptions options)Convert a BigQueryTableSchemato a BeamSchema.
-
toGenericAvroSchema
public static org.apache.avro.Schema toGenericAvroSchema(com.google.api.services.bigquery.model.TableSchema tableSchema)
Convert a BigQueryTableSchemato AvroSchema.
-
fromGenericAvroSchema
public static com.google.api.services.bigquery.model.TableSchema fromGenericAvroSchema(org.apache.avro.Schema schema)
Convert an AvroSchemato a BigQueryTableSchema.
-
fromGenericAvroSchema
public static com.google.api.services.bigquery.model.TableSchema fromGenericAvroSchema(org.apache.avro.Schema schema, java.lang.Boolean useAvroLogicalTypes)Convert an AvroSchemato a BigQueryTableSchema.
-
toGenericAvroSchema
public static org.apache.avro.Schema toGenericAvroSchema(com.google.api.services.bigquery.model.TableSchema tableSchema, java.lang.Boolean useAvroLogicalTypes)Convert a BigQueryTableSchemato AvroSchema.
-
toGenericAvroSchema
public static org.apache.avro.Schema toGenericAvroSchema(java.lang.String schemaName, java.util.List<com.google.api.services.bigquery.model.TableFieldSchema> fieldSchemas)Convert a list of BigQueryTableFieldSchemato AvroSchema.
-
toGenericAvroSchema
public static org.apache.avro.Schema toGenericAvroSchema(java.lang.String schemaName, java.util.List<com.google.api.services.bigquery.model.TableFieldSchema> fieldSchemas, java.lang.Boolean useAvroLogicalTypes)Convert a list of BigQueryTableFieldSchemato AvroSchema.
-
tableRowToBeamRow
public static final org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TypedRead.ToBeamRowFunction<com.google.api.services.bigquery.model.TableRow> tableRowToBeamRow()
-
tableRowFromBeamRow
public static final org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TypedRead.FromBeamRowFunction<com.google.api.services.bigquery.model.TableRow> tableRowFromBeamRow()
-
toTableRow
public static org.apache.beam.sdk.transforms.SerializableFunction<org.apache.beam.sdk.values.Row,com.google.api.services.bigquery.model.TableRow> toTableRow()
Convert a BeamRowto a BigQueryTableRow.
-
toTableRow
public static <T> org.apache.beam.sdk.transforms.SerializableFunction<T,com.google.api.services.bigquery.model.TableRow> toTableRow(org.apache.beam.sdk.transforms.SerializableFunction<T,org.apache.beam.sdk.values.Row> toRow)
Convert a Beam schema type to a BigQueryTableRow.
-
toBeamRow
public static org.apache.beam.sdk.values.Row toBeamRow(org.apache.avro.generic.GenericRecord record, org.apache.beam.sdk.schemas.Schema schema, BigQueryUtils.ConversionOptions options)
-
convertGenericRecordToTableRow
@Deprecated public static com.google.api.services.bigquery.model.TableRow convertGenericRecordToTableRow(org.apache.avro.generic.GenericRecord record, com.google.api.services.bigquery.model.TableSchema tableSchema)Deprecated.Convert generic record to Bq TableRow.
-
convertGenericRecordToTableRow
public static com.google.api.services.bigquery.model.TableRow convertGenericRecordToTableRow(org.apache.avro.generic.GenericRecord record)
Convert generic record to Bq TableRow.
-
toTableRow
public static com.google.api.services.bigquery.model.TableRow toTableRow(org.apache.beam.sdk.values.Row row)
Convert a Beam Row to a BigQuery TableRow.
-
toBeamRow
public static org.apache.beam.sdk.values.Row toBeamRow(org.apache.beam.sdk.schemas.Schema rowSchema, com.google.api.services.bigquery.model.TableRow jsonBqRow)Tries to convert a JSONTableRowfrom BigQuery into a BeamRow.Only supports basic types and arrays. Doesn't support date types or structs.
-
toBeamRow
public static org.apache.beam.sdk.values.Row toBeamRow(org.apache.beam.sdk.schemas.Schema rowSchema, com.google.api.services.bigquery.model.TableSchema bqSchema, com.google.api.services.bigquery.model.TableRow jsonBqRow)Tries to parse the JSONTableRowfrom BigQuery.Only supports basic types and arrays. Doesn't support date types.
-
convertAvroFormat
public static java.lang.Object convertAvroFormat(org.apache.beam.sdk.schemas.Schema.FieldType beamFieldType, java.lang.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
public static @Nullable com.google.api.services.bigquery.model.TableReference toTableReference(java.lang.String fullTableId)
- 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
public static @Nullable java.lang.String toTableSpec(com.google.api.services.bigquery.model.TableReference tableReference)
- 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 com.google.api.services.bigquery.model.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(com.google.api.services.bigquery.model.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.
-
-