Search in sources :

Example 31 with TableId

use of com.google.cloud.bigquery.TableId in project presto by prestodb.

the class BigQueryClient method getTable.

public TableInfo getTable(TableId tableId) {
    TableId bigQueryTableId = tableIds.get(tableId);
    Table table = bigQuery.getTable(bigQueryTableId != null ? bigQueryTableId : tableId);
    if (table != null) {
        tableIds.putIfAbsent(tableId, table.getTableId());
        datasetIds.putIfAbsent(toDatasetId(tableId), toDatasetId(table.getTableId()));
    }
    return table;
}
Also used : TableId(com.google.cloud.bigquery.TableId) Table(com.google.cloud.bigquery.Table)

Example 32 with TableId

use of com.google.cloud.bigquery.TableId in project presto by prestodb.

the class BigQueryTableHandle method from.

public static BigQueryTableHandle from(TableInfo tableInfo) {
    TableId tableId = tableInfo.getTableId();
    String type = tableInfo.getDefinition().getType().toString();
    return new BigQueryTableHandle(tableId.getProject(), tableId.getDataset(), tableId.getTable(), type, TupleDomain.none(), Optional.empty(), OptionalLong.empty());
}
Also used : TableId(com.google.cloud.bigquery.TableId)

Example 33 with TableId

use of com.google.cloud.bigquery.TableId in project components by Talend.

the class BigQueryDatasetRuntimeTestIT method initDatasetAndTable.

@BeforeClass
public static void initDatasetAndTable() throws IOException {
    BigQuery bigquery = BigQueryConnection.createClient(createDatastore());
    for (String dataset : datasets) {
        DatasetId datasetId = DatasetId.of(BigQueryTestConstants.PROJECT, dataset);
        bigquery.create(DatasetInfo.of(datasetId));
    }
    for (String table : tables) {
        TableDefinition tableDefinition = StandardTableDefinition.of(Schema.of(Field.of("test", Field.Type.string())));
        TableId tableId = TableId.of(BigQueryTestConstants.PROJECT, datasets.get(0), table);
        bigquery.create(TableInfo.of(tableId, tableDefinition));
    }
}
Also used : TableId(com.google.cloud.bigquery.TableId) BigQuery(com.google.cloud.bigquery.BigQuery) TableDefinition(com.google.cloud.bigquery.TableDefinition) StandardTableDefinition(com.google.cloud.bigquery.StandardTableDefinition) DatasetId(com.google.cloud.bigquery.DatasetId) BeforeClass(org.junit.BeforeClass)

Example 34 with TableId

use of com.google.cloud.bigquery.TableId in project beam by apache.

the class BigQueryClient method createTableIfNotExists.

/**
 * Creates a new table with given schema when it not exists.
 *
 * @param tableName name of the desired table
 * @param schema schema of consequent table fields (name, type pairs).
 */
public void createTableIfNotExists(String tableName, Map<String, String> schema) {
    TableId tableId = TableId.of(projectId, dataset, tableName);
    if (client.getTable(tableId, FIELD_OPTIONS) == null) {
        List<Field> schemaFields = schema.entrySet().stream().map(entry -> Field.of(entry.getKey(), LegacySQLTypeName.valueOf(entry.getValue()))).collect(Collectors.toList());
        createTable(tableId, Schema.of(schemaFields));
    }
}
Also used : TableId(com.google.cloud.bigquery.TableId) Field(com.google.cloud.bigquery.Field) TableOption(com.google.cloud.bigquery.BigQuery.TableOption) StandardTableDefinition(com.google.cloud.bigquery.StandardTableDefinition) Collection(java.util.Collection) TableId(com.google.cloud.bigquery.TableId) InsertAllRequest(com.google.cloud.bigquery.InsertAllRequest) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) BigQuery(com.google.cloud.bigquery.BigQuery) BigQueryOptions(com.google.cloud.bigquery.BigQueryOptions) List(java.util.List) InsertAllResponse(com.google.cloud.bigquery.InsertAllResponse) Schema(com.google.cloud.bigquery.Schema) Map(java.util.Map) TableInfo(com.google.cloud.bigquery.TableInfo) LegacySQLTypeName(com.google.cloud.bigquery.LegacySQLTypeName) Collections(java.util.Collections) Field(com.google.cloud.bigquery.Field)

Aggregations

TableId (com.google.cloud.bigquery.TableId)34 Table (com.google.cloud.bigquery.Table)13 Test (org.junit.Test)13 Job (com.google.cloud.bigquery.Job)11 StandardTableDefinition (com.google.cloud.bigquery.StandardTableDefinition)9 TableInfo (com.google.cloud.bigquery.TableInfo)8 FieldValue (com.google.cloud.bigquery.FieldValue)7 List (java.util.List)7 BigQuery (com.google.cloud.bigquery.BigQuery)6 Schema (com.google.cloud.bigquery.Schema)6 InsertAllResponse (com.google.cloud.bigquery.InsertAllResponse)5 QueryResponse (com.google.cloud.bigquery.QueryResponse)5 Field (com.google.cloud.bigquery.Field)4 QueryRequest (com.google.cloud.bigquery.QueryRequest)4 FixedSplitSource (com.facebook.presto.spi.FixedSplitSource)3 CopyJobConfiguration (com.google.cloud.bigquery.CopyJobConfiguration)3 InsertAllRequest (com.google.cloud.bigquery.InsertAllRequest)3 ImmutableList (com.google.common.collect.ImmutableList)3 String.format (java.lang.String.format)3 Logger (com.facebook.airlift.log.Logger)2