Table toPb() { Table tablePb = new Table(); if (getSchema() != null) { tablePb.setSchema(getSchema().toPb()); } tablePb.setType(getType().name()); return tablePb; }
Table toPb() { Table tablePb = new Table(); if (schema != null) { tablePb.setSchema(schema.toPb()); } tablePb.setType(type.name()); return tablePb; }
Table toPb() { Table tablePb = new Table(); if (schema != null) { tablePb.setSchema(schema.toPb()); } tablePb.setType(type.name()); return tablePb; }
public Table toTable(BigQueryTable source) { Table sink = new Table(); TableReference tableRef = tableReference(source); TableSchema schema = toTableSchema(source); sink.setTableReference(tableRef); sink.setSchema(schema); return sink; }
private Table table(String defaultProjectId, Optional<DatasetReference> defaultDataset, TableConfig config) { Optional<String> datasetId = config.dataset().or(defaultDataset.transform(DatasetReference::getDatasetId)); if (!datasetId.isPresent()) { throw new ConfigException("Bad table reference or configuration: Missing 'dataset'"); } return new Table() .setTableReference(new TableReference() .setProjectId(config.project().or(defaultProjectId)) .setDatasetId(datasetId.get()) .setTableId(config.id())) .setSchema(config.schema().orNull()) .setFriendlyName(config.friendly_name().orNull()) .setExpirationTime(config.expiration_time() .transform(p -> p.getTimestamp().toInstant(request.getTimeZone()).toEpochMilli()).orNull()) .setTimePartitioning(config.time_partitioning().orNull()) .setView(config.view().orNull()); }
Table toPb() { Table tablePb = new Table(); if (getSchema() != null) { tablePb.setSchema(getSchema().toPb()); } tablePb.setType(getType().name()); return tablePb; }
public static Table createTable(String projectId, String datasetId, String tableId, TableSchema schema, Bigquery bigquery) throws IOException { Table table = new Table(); TableReference tableRef = new TableReference(); tableRef.setDatasetId(datasetId); tableRef.setProjectId(projectId); tableRef.setTableId(tableId); table.setTableReference(tableRef); table.setFriendlyName(tableId); table.setSchema(schema); try { return bigquery.tables().insert(projectId, datasetId, table).execute(); } catch (GoogleJsonResponseException e) { return null; //table already exists } } }
private Table createTable(Description description) throws IOException, InterruptedException { TableReference tableReference = new TableReference() .setProjectId(pipelineOptions.getProject()) .setDatasetId(pipelineOptions.getTargetDataset()) .setTableId(createRandomizedName(description)); table = new Table() .setTableReference(tableReference) .setSchema(BigQueryUtils.toTableSchema(schema)) .setDescription( "Table created for " + description.getDisplayName() + " by TestBigQueryRule. " + "Should be automatically cleaned up after test completion."); if (datasetService.getTable(tableReference) != null) { throw new IllegalStateException( "Table '" + tableReference + "' already exists. " + "It should have been cleaned up by the test rule."); } datasetService.createTable(table); return table; }
private Table basicTableSchema() { return new Table() .setSchema( new TableSchema() .setFields( Arrays.asList( new TableFieldSchema().setName("name").setType("STRING"), new TableFieldSchema().setName("answer").setType("INTEGER")))); }
/** Tests that table creation succeeds when the table already exists. */ @Test public void testCreateTableSucceedsAlreadyExists() throws IOException { TableReference ref = new TableReference().setProjectId("project").setDatasetId("dataset").setTableId("table"); TableSchema schema = new TableSchema() .setFields( ImmutableList.of( new TableFieldSchema().setName("column1").setType("String"), new TableFieldSchema().setName("column2").setType("Integer"))); Table testTable = new Table().setTableReference(ref).setSchema(schema); when(response.getStatusCode()).thenReturn(409); // 409 means already exists BigQueryServicesImpl.DatasetServiceImpl services = new BigQueryServicesImpl.DatasetServiceImpl(bigquery, PipelineOptionsFactory.create()); Table ret = services.tryCreateTable( testTable, new RetryBoundedBackOff(0, BackOff.ZERO_BACKOFF), Sleeper.DEFAULT); assertNull(ret); verify(response, times(1)).getStatusCode(); verify(response, times(1)).getContent(); verify(response, times(1)).getContentType(); }
private Table toTable(Shape shape, GoogleBigQueryTable dataSource) { Table table = new Table(); BigQueryTableReference ref = dataSource.getTableReference(); TableReference reference = new TableReference(); reference.setProjectId(ref.getProjectId()); reference.setDatasetId(ref.getDatasetId()); reference.setTableId(ref.getTableId()); table.setTableReference(reference); if (!(dataSource instanceof GoogleBigQueryView)){ TableSchema tableSchema = tableGenerator.toTableSchema(shape); table.setSchema(tableSchema); } ExternalDataConfiguration external = dataSource.getExternalDataConfiguration(); if (external != null) { table.setExternalDataConfiguration(external); table.setType("EXTERNAL"); } return table; }
private void setupNewTypesQueryTest() { this.bqClient.createNewTable( this.project, this.bigQueryDatasetId, new Table() .setSchema(BigQueryToTableIT.NEW_TYPES_QUERY_TABLE_SCHEMA) .setTableReference( new TableReference() .setTableId(BigQueryToTableIT.NEW_TYPES_QUERY_TABLE_NAME) .setDatasetId(this.bigQueryDatasetId) .setProjectId(this.project))); this.bqClient.insertDataToTable( this.project, this.bigQueryDatasetId, BigQueryToTableIT.NEW_TYPES_QUERY_TABLE_NAME, BigQueryToTableIT.NEW_TYPES_QUERY_TABLE_DATA); this.options.setQuery( String.format( "SELECT bytes, date, time FROM [%s:%s.%s]", project, this.bigQueryDatasetId, BigQueryToTableIT.NEW_TYPES_QUERY_TABLE_NAME)); this.options.setOutput(outputTable); this.options.setOutputSchema(BigQueryToTableIT.NEW_TYPES_QUERY_TABLE_SCHEMA); }
.clone() .setTableId(BigQueryHelpers.stripPartitionDecorator(destination.getTableId())); existingTable = new Table().setTableReference(strippedDestination).setSchema(schema); if (load.getTimePartitioning() != null) { existingTable = existingTable.setTimePartitioning(load.getTimePartitioning());
Table newTable = new Table() .setSchema(schema) .setTableReference( new TableReference()
new Table() .setTableReference(destination) .setSchema(schema) .setTimePartitioning(partitioning)); datasetService.insertAll(destination, allRows, null);
new Table() .setTableReference(table) .setSchema( new TableSchema() .setFields(
new Table() .setTableReference(table) .setSchema( new TableSchema() .setFields(
new Table() .setTableReference(table) .setSchema( new TableSchema() .setFields(
private void testReadFromTable(boolean useTemplateCompatibility, boolean useReadTableRows) throws IOException, InterruptedException { Table sometable = new Table(); sometable.setSchema( new TableSchema() .setFields(
new Table() .setTableReference(tableReference) .setSchema( new TableSchema() .setFields(