Search in sources :

Example 6 with Experimental

use of org.apache.beam.sdk.annotations.Experimental in project beam by apache.

the class BigQueryQuerySourceDef method getBeamSchema.

/**
 * {@inheritDoc}
 */
@Experimental(Kind.SCHEMAS)
@Override
public Schema getBeamSchema(BigQueryOptions bqOptions) {
    try {
        JobStatistics stats = BigQueryQueryHelper.dryRunQueryIfNeeded(bqServices, bqOptions, dryRunJobStats, query.get(), flattenResults, useLegacySql, location);
        TableSchema tableSchema = stats.getQuery().getSchema();
        return BigQueryUtils.fromTableSchema(tableSchema);
    } catch (IOException | InterruptedException | NullPointerException e) {
        throw new BigQuerySchemaRetrievalException("Exception while trying to retrieve schema of query", e);
    }
}
Also used : JobStatistics(com.google.api.services.bigquery.model.JobStatistics) TableSchema(com.google.api.services.bigquery.model.TableSchema) IOException(java.io.IOException) Experimental(org.apache.beam.sdk.annotations.Experimental)

Example 7 with Experimental

use of org.apache.beam.sdk.annotations.Experimental in project beam by apache.

the class BigQueryTableSourceDef method getBeamSchema.

/**
 * {@inheritDoc}
 */
@Experimental(Kind.SCHEMAS)
@Override
public Schema getBeamSchema(BigQueryOptions bqOptions) {
    try {
        TableReference tableRef = getTableReference(bqOptions);
        TableSchema tableSchema = bqServices.getDatasetService(bqOptions).getTable(tableRef).getSchema();
        return BigQueryUtils.fromTableSchema(tableSchema);
    } catch (IOException | InterruptedException | NullPointerException e) {
        throw new BigQuerySchemaRetrievalException("Exception while trying to retrieve schema", e);
    }
}
Also used : TableReference(com.google.api.services.bigquery.model.TableReference) TableSchema(com.google.api.services.bigquery.model.TableSchema) IOException(java.io.IOException) Experimental(org.apache.beam.sdk.annotations.Experimental)

Aggregations

Experimental (org.apache.beam.sdk.annotations.Experimental)7 TableSchema (com.google.api.services.bigquery.model.TableSchema)4 Schema (org.apache.beam.sdk.schemas.Schema)4 IOException (java.io.IOException)3 TableReference (com.google.api.services.bigquery.model.TableReference)2 ProtoDynamicMessageSchema (org.apache.beam.sdk.extensions.protobuf.ProtoDynamicMessageSchema)2 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)1 Bigquery (com.google.api.services.bigquery.Bigquery)1 JobStatistics (com.google.api.services.bigquery.model.JobStatistics)1 Table (com.google.api.services.bigquery.model.Table)1 TableDataInsertAllRequest (com.google.api.services.bigquery.model.TableDataInsertAllRequest)1 Rows (com.google.api.services.bigquery.model.TableDataInsertAllRequest.Rows)1 TableDataInsertAllResponse (com.google.api.services.bigquery.model.TableDataInsertAllResponse)1 TableFieldSchema (com.google.api.services.bigquery.model.TableFieldSchema)1 TableRow (com.google.api.services.bigquery.model.TableRow)1 Credentials (com.google.auth.Credentials)1 HttpCredentialsAdapter (com.google.auth.http.HttpCredentialsAdapter)1 ChainingHttpRequestInitializer (com.google.cloud.hadoop.util.ChainingHttpRequestInitializer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Arrays (java.util.Arrays)1