diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index fec7e55e0..f6d87c709 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -621,14 +621,16 @@ class ITBigQueryTest { private static final String EXTRACT_FILE = "extract.csv"; private static final String EXTRACT_MODEL_FILE = "extract_model.csv"; private static final String BUCKET = RemoteStorageHelper.generateBucketName(); - private static final TableId TABLE_ID = TableId.of(DATASET, "testing_table"); - private static final TableId TABLE_ID_DDL = TableId.of(DATASET, "ddl_testing_table"); - private static final TableId TABLE_ID_FASTQUERY = TableId.of(DATASET, "fastquery_testing_table"); - private static final TableId TABLE_ID_FASTQUERY_UK = - TableId.of(UK_DATASET, "fastquery_testing_table"); - private static final TableId TABLE_ID_LARGE = TableId.of(DATASET, "large_data_testing_table"); - private static final TableId TABLE_ID_FASTQUERY_BQ_RESULTSET = - TableId.of(DATASET, "fastquery_testing_bq_resultset"); + private static final TableId TABLE_ID = TableId.of(DATASET, generateTableName("testing_table")); + private static final TableId TABLE_ID_DDL = + TableId.of(DATASET, generateTableName("ddl_testing_table")); + private static final TableId TABLE_ID_FAST_QUERY = + TableId.of(DATASET, generateTableName("fast_query_testing_table")); + private static final TableId TABLE_ID_LARGE = + TableId.of(DATASET, generateTableName("large_data_testing_table")); + private static final TableId TABLE_ID_FAST_QUERY_BQ_RESULTSET = + TableId.of(DATASET, generateTableName("fast_query_testing_bq_resultset")); + private static final String CSV_CONTENT = "StringValue1\nStringValue2\n"; private static final String CSV_CONTENT_NULL = "String\0Value1\n"; private static final String CSV_CONTENT_FLEXIBLE_COLUMN = "name,&ersand\nrow_name,1"; @@ -1063,6 +1065,10 @@ public CompletableResultCode shutdown() { } } + private static String generateTableName(String prefix) { + return prefix + UUID.randomUUID().toString().substring(0, 8); + } + @BeforeAll static void beforeClass() throws InterruptedException, IOException { RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create(); @@ -1133,7 +1139,7 @@ static void beforeClass() throws InterruptedException, IOException { LoadJobConfiguration configurationFastQuery = LoadJobConfiguration.newBuilder( - TABLE_ID_FASTQUERY, "gs://" + BUCKET + "/" + JSON_LOAD_FILE, FormatOptions.json()) + TABLE_ID_FAST_QUERY, "gs://" + BUCKET + "/" + JSON_LOAD_FILE, FormatOptions.json()) .setCreateDisposition(JobInfo.CreateDisposition.CREATE_IF_NEEDED) .setSchema(TABLE_SCHEMA) .setLabels(labels) @@ -1144,7 +1150,7 @@ static void beforeClass() throws InterruptedException, IOException { LoadJobConfiguration configFastQueryBQResultset = LoadJobConfiguration.newBuilder( - TABLE_ID_FASTQUERY_BQ_RESULTSET, + TABLE_ID_FAST_QUERY_BQ_RESULTSET, "gs://" + BUCKET + "/" + JSON_LOAD_FILE_BQ_RESULTSET, FormatOptions.json()) .setCreateDisposition(JobInfo.CreateDisposition.CREATE_IF_NEEDED) @@ -2681,7 +2687,7 @@ void testListTablesWithRangePartitioning() { @Test void testListPartitions() throws InterruptedException { - String tableName = "test_table_partitions_" + UUID.randomUUID().toString().substring(0, 8); + String tableName = generateTableName("test_table_partitions_"); Date date = Date.fromJavaUtilDate(new java.util.Date()); String partitionDate = date.toString().replaceAll("-", ""); TableId tableId = TableId.of(DATASET, tableName + "$" + partitionDate); @@ -3503,8 +3509,15 @@ void testLosslessTimestamp() throws InterruptedException { void testQuery() throws InterruptedException { String query = "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID.getTable(); QueryJobConfiguration config = - QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(DATASET)).build(); + QueryJobConfiguration.newBuilder(query) + // Disable the cache as query plans do not exist from cached results + // This will force generation of execution plan + .setUseQueryCache(false) + .setDefaultDataset(DatasetId.of(DATASET)) + .build(); Job job = bigquery.create(JobInfo.of(JobId.of(), config)); + job = job.waitFor(); + assertNotNull(job); TableResult result = job.getQueryResults(); assertNotNull(result.getJobId()); @@ -3527,6 +3540,7 @@ void testQuery() throws InterruptedException { } assertEquals(2, rowCount); + // Query Plan will exist for a completed job Job job2 = bigquery.getJob(job.getJobId()); JobStatistics.QueryStatistics statistics = job2.getStatistics(); assertNotNull(statistics.getQueryPlan()); @@ -3822,7 +3836,7 @@ void testConnectionImplDryRun() throws SQLException { String query = String.format( "select StringField, BigNumericField, BooleanField, BytesField, IntegerField, TimestampField, FloatField, NumericField, TimeField, DateField, DateTimeField , GeographyField, RecordField.BytesField, RecordField.BooleanField, IntegerArrayField from %s where StringField = ? order by TimestampField", - TABLE_ID_FASTQUERY_BQ_RESULTSET.getTable()); + TABLE_ID_FAST_QUERY_BQ_RESULTSET.getTable()); ConnectionSettings connectionSettings = ConnectionSettings.newBuilder() .setDefaultDataset(DatasetId.of(DATASET)) @@ -3850,7 +3864,7 @@ void testConnectionImplDryRunNoQueryParameters() throws SQLException { + "TimestampField, FloatField, NumericField, TimeField, DateField, DateTimeField, " + "GeographyField, RecordField.BytesField, RecordField.BooleanField, " + "IntegerArrayField from %s order by TimestampField", - TABLE_ID_FASTQUERY_BQ_RESULTSET.getTable()); + TABLE_ID_FAST_QUERY_BQ_RESULTSET.getTable()); ConnectionSettings connectionSettings = ConnectionSettings.newBuilder() .setDefaultDataset(DatasetId.of(DATASET)) @@ -3933,7 +3947,7 @@ void testExecuteSelectSinglePageTableRow() throws SQLException { String query = "select StringField, BigNumericField, BooleanField, BytesField, IntegerField, TimestampField, FloatField, " + "NumericField, TimeField, DateField, DateTimeField , GeographyField, RecordField.BytesField, RecordField.BooleanField, IntegerArrayField from " - + TABLE_ID_FASTQUERY_BQ_RESULTSET.getTable() + + TABLE_ID_FAST_QUERY_BQ_RESULTSET.getTable() + " order by TimestampField"; ConnectionSettings connectionSettings = ConnectionSettings.newBuilder().setDefaultDataset(DatasetId.of(DATASET)).build(); @@ -3997,7 +4011,7 @@ void testExecuteSelectSinglePageTableRowWithReadAPI() throws SQLException { String query = "select StringField, BigNumericField, BooleanField, BytesField, IntegerField, TimestampField, FloatField, " + "NumericField, TimeField, DateField, DateTimeField , GeographyField, RecordField.BytesField, RecordField.BooleanField, IntegerArrayField from " - + TABLE_ID_FASTQUERY_BQ_RESULTSET.getTable() + + TABLE_ID_FAST_QUERY_BQ_RESULTSET.getTable() + " order by TimestampField"; ConnectionSettings connectionSettings = ConnectionSettings.newBuilder() @@ -4344,7 +4358,7 @@ void testExecuteSelectSinglePageTableRowColInd() throws SQLException { String query = "select StringField, BigNumericField, BooleanField, BytesField, IntegerField, TimestampField, FloatField, " + "NumericField, TimeField, DateField, DateTimeField , GeographyField, RecordField.BytesField, RecordField.BooleanField, IntegerArrayField from " - + TABLE_ID_FASTQUERY_BQ_RESULTSET.getTable() + + TABLE_ID_FAST_QUERY_BQ_RESULTSET.getTable() + " order by TimestampField"; /* Column Index mapping for ref: @@ -4543,7 +4557,7 @@ void testExecuteSelectArrayOfStruct() throws SQLException { @Test void testFastQueryMultipleRuns() throws InterruptedException { String query = - "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID_FASTQUERY.getTable(); + "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID_FAST_QUERY.getTable(); QueryJobConfiguration config = QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(DATASET)).build(); TableResult result = bigquery.query(config); @@ -4580,7 +4594,7 @@ void testFastQueryMultipleRuns() throws InterruptedException { @Test void testFastQuerySinglePageDuplicateRequestIds() throws InterruptedException { String query = - "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID_FASTQUERY.getTable(); + "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID_FAST_QUERY.getTable(); QueryJobConfiguration config = QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(DATASET)).build(); TableResult result = bigquery.query(config); @@ -4613,7 +4627,7 @@ void testFastQuerySinglePageDuplicateRequestIds() throws InterruptedException { @Test void testFastSQLQuery() throws InterruptedException { String query = - "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID_FASTQUERY.getTable(); + "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID_FAST_QUERY.getTable(); QueryJobConfiguration config = QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(DATASET)).build(); TableResult result = bigquery.query(config); @@ -4642,27 +4656,28 @@ void testFastSQLQuery() throws InterruptedException { @Test void testProjectIDFastSQLQueryWithJobId() throws InterruptedException { - String random_project_id = "RANDOM_PROJECT_" + UUID.randomUUID().toString().replace('-', '_'); - System.out.println(random_project_id); + String invalidProjectId = "RANDOM_PROJECT_" + UUID.randomUUID().toString().replace('-', '_'); + System.out.println(invalidProjectId); String query = - "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID_FASTQUERY.getTable(); + "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID_FAST_QUERY.getTable(); // With incorrect projectID in jobid // The job will be created with the specified(incorrect) projectID // hence failing the operation - JobId jobIdWithProjectId = JobId.newBuilder().setProject(random_project_id).build(); + JobId jobIdWithProjectId = JobId.newBuilder().setProject(invalidProjectId).build(); QueryJobConfiguration configSelect = QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(DATASET)).build(); try { bigquery.query(configSelect, jobIdWithProjectId); } catch (Exception exception) { // error message for non-existent project - assertTrue(exception.getMessage().contains("Cannot parse as CloudRegion")); + assertTrue(exception.getMessage().contains("Cannot parse as CloudRegion")); assertEquals(BigQueryException.class, exception.getClass()); } } @Test void testLocationFastSQLQueryWithJobId() throws InterruptedException { + TableId tableIdFastQueryUk = TableId.of(UK_DATASET, "fastquery_testing_table"); DatasetInfo infoUK = DatasetInfo.newBuilder(UK_DATASET) .setDescription(DESCRIPTION) @@ -4672,11 +4687,11 @@ void testLocationFastSQLQueryWithJobId() throws InterruptedException { bigquery.create(infoUK); TableDefinition tableDefinition = StandardTableDefinition.of(SIMPLE_SCHEMA); - TableInfo tableInfo = TableInfo.newBuilder(TABLE_ID_FASTQUERY_UK, tableDefinition).build(); + TableInfo tableInfo = TableInfo.newBuilder(tableIdFastQueryUk, tableDefinition).build(); bigquery.create(tableInfo); String insert = - "INSERT " + UK_DATASET + "." + TABLE_ID_FASTQUERY_UK.getTable() + " VALUES('Anna');"; + "INSERT " + UK_DATASET + "." + tableIdFastQueryUk.getTable() + " VALUES('Anna');"; QueryJobConfiguration config = QueryJobConfiguration.newBuilder(insert) @@ -4685,10 +4700,12 @@ void testLocationFastSQLQueryWithJobId() throws InterruptedException { TableResult result = bigquery.query(config); assertNotNull(result.getJobId()); assertEquals(SIMPLE_SCHEMA, result.getSchema()); - assertEquals(1, result.getTotalRows()); - assertNull(result.getNextPage()); - assertNull(result.getNextPageToken()); - assertFalse(result.hasNextPage()); + // Use `getNumDmlAffectedRows()` for DML operations + Job queryJob = bigquery.getJob(result.getJobId()); + queryJob = queryJob.waitFor(); + JobStatistics.QueryStatistics statistics = queryJob.getStatistics(); + assertEquals(1L, statistics.getNumDmlAffectedRows().longValue()); + // Verify correctness of table content for (FieldValueList row : result.getValues()) { FieldValue stringCell = row.get(0); @@ -4698,7 +4715,7 @@ void testLocationFastSQLQueryWithJobId() throws InterruptedException { // With incorrect location in jobid // The job will be created with the specified(incorrect) location // hence failing the operation - String query = "SELECT StringField FROM " + TABLE_ID_FASTQUERY_UK.getTable(); + String query = "SELECT StringField FROM " + tableIdFastQueryUk.getTable(); JobId jobIdWithLocation = JobId.newBuilder().setLocation("us-west1").build(); QueryJobConfiguration configSelect = QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(UK_DATASET)).build(); @@ -4757,7 +4774,7 @@ void testFastSQLQueryMultiPage() throws InterruptedException { @Test void testFastDMLQuery() throws InterruptedException { - String tableName = TABLE_ID_FASTQUERY.getTable(); + String tableName = TABLE_ID_FAST_QUERY.getTable(); String dmlQuery = String.format("UPDATE %s.%s SET StringField = 'hello' WHERE TRUE", DATASET, tableName); QueryJobConfiguration dmlConfig = QueryJobConfiguration.newBuilder(dmlQuery).build(); @@ -4812,8 +4829,7 @@ void testFastDDLQuery() throws InterruptedException { @Test void testFastQuerySlowDDL() throws InterruptedException { - String tableName = - "test_table_fast_query_ddl_slow_" + UUID.randomUUID().toString().substring(0, 8); + String tableName = generateTableName("test_table_fast_query_ddl_slow_"); // This query take more than 10s to run and should fall back on the old query path String slowDdlQuery = String.format( @@ -4846,7 +4862,7 @@ void testFastQuerySlowDDL() throws InterruptedException { @Test void testFastQueryHTTPException() throws InterruptedException { String queryInvalid = - "CREATE OR REPLACE SELECT * FROM UPDATE TABLE SET " + TABLE_ID_FASTQUERY.getTable(); + "CREATE OR REPLACE SELECT * FROM UPDATE TABLE SET " + TABLE_ID_FAST_QUERY.getTable(); QueryJobConfiguration configInvalidQuery = QueryJobConfiguration.newBuilder(queryInvalid) .setDefaultDataset(DatasetId.of(DATASET)) @@ -5063,7 +5079,7 @@ void testExecuteSelectSessionSupport() throws BigQuerySQLException { @Test void testDmlStatistics() throws InterruptedException { - String tableName = TABLE_ID_FASTQUERY.getTable(); + String tableName = TABLE_ID_FAST_QUERY.getTable(); // Run a DML statement to UPDATE 2 rows of data String dmlQuery = String.format("UPDATE %s.%s SET StringField = 'hello' WHERE TRUE", DATASET, tableName); @@ -5085,7 +5101,7 @@ void testDmlStatistics() throws InterruptedException { /* TODO(prasmish): replicate the entire test case for executeSelect */ @Test void testTransactionInfo() throws InterruptedException { - String tableName = TABLE_ID_FASTQUERY.getTable(); + String tableName = TABLE_ID_FAST_QUERY.getTable(); String transaction = String.format( "BEGIN TRANSACTION;\n" @@ -5726,8 +5742,8 @@ void testListJobsWithCreationBounding() { @Test void testCreateAndGetJob() throws InterruptedException, TimeoutException { - String sourceTableName = "test_create_and_get_job_source_table"; - String destinationTableName = "test_create_and_get_job_destination_table"; + String sourceTableName = generateTableName("test_create_and_get_job_source_table"); + String destinationTableName = generateTableName("test_create_and_get_job_destination_table"); TableId sourceTable = TableId.of(DATASET, sourceTableName); StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA); TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition); @@ -5784,8 +5800,10 @@ void testCreateJobAndWaitForWithRetryOptions() throws InterruptedException, Time @Test void testCreateAndGetJobWithSelectedFields() throws InterruptedException, TimeoutException { - String sourceTableName = "test_create_and_get_job_with_selected_fields_source_table"; - String destinationTableName = "test_create_and_get_job_with_selected_fields_destination_table"; + String sourceTableName = + generateTableName("test_create_and_get_job_with_selected_fields_source_table"); + String destinationTableName = + generateTableName("test_create_and_get_job_with_selected_fields_destination_table"); TableId sourceTable = TableId.of(DATASET, sourceTableName); StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA); TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition); @@ -5832,8 +5850,8 @@ void testCreateAndGetJobWithSelectedFields() throws InterruptedException, Timeou @Test void testCopyJob() throws InterruptedException, TimeoutException { - String sourceTableName = "test_copy_job_source_table"; - String destinationTableName = "test_copy_job_destination_table"; + String sourceTableName = generateTableName("test_copy_job_source_table"); + String destinationTableName = generateTableName("test_copy_job_destination_table"); TableId sourceTable = TableId.of(DATASET, sourceTableName); StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA); TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition); @@ -5864,8 +5882,8 @@ void testCopyJob() throws InterruptedException, TimeoutException { @Test void testCopyJobStatistics() throws InterruptedException, TimeoutException { - String sourceTableName = "test_copy_job_statistics_source_table"; - String destinationTableName = "test_copy_job_statistics_destination_table"; + String sourceTableName = generateTableName("test_copy_job_statistics_source_table"); + String destinationTableName = generateTableName("test_copy_job_statistics_destination_table"); QueryJobConfiguration createTable = QueryJobConfiguration.newBuilder( @@ -5974,10 +5992,8 @@ void testSnapshotTableCopyJob() throws InterruptedException { @Test void testCopyJobWithLabelsAndExpTime() throws InterruptedException { String destExpiryTime = "2099-12-31T23:59:59.999999999Z"; - String sourceTableName = - "test_copy_job_source_table_label" + UUID.randomUUID().toString().substring(0, 8); - String destinationTableName = - "test_copy_job_destination_table_label" + UUID.randomUUID().toString().substring(0, 8); + String sourceTableName = generateTableName("test_copy_job_source_table_label"); + String destinationTableName = generateTableName("test_copy_job_destination_table_label"); Map labels = ImmutableMap.of("test_job_name", "test_copy_job"); TableId sourceTable = TableId.of(DATASET, sourceTableName); StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA); @@ -6006,7 +6022,7 @@ void testCopyJobWithLabelsAndExpTime() throws InterruptedException { /* TODO(prasmish): replicate the entire test case for executeSelect */ @Test public void testQueryJob() throws InterruptedException, TimeoutException { - String tableName = "test_query_job_table"; + String tableName = generateTableName("test_query_job_table"); String query = "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID.getTable(); TableId destinationTable = TableId.of(DATASET, tableName); QueryJobConfiguration configuration = @@ -6052,7 +6068,7 @@ public void testQueryJob() throws InterruptedException, TimeoutException { /* TODO(prasmish): replicate the entire test case for executeSelect */ @Test void testQueryJobWithConnectionProperties() throws InterruptedException { - String tableName = "test_query_job_table_connection_properties"; + String tableName = generateTableName("test_query_job_table_connection_properties"); String query = "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID.getTable(); TableId destinationTable = TableId.of(DATASET, tableName); QueryJobConfiguration configuration = @@ -6072,7 +6088,7 @@ void testQueryJobWithConnectionProperties() throws InterruptedException { /* TODO(prasmish): replicate the entire test case for executeSelect */ @Test void testQueryJobWithLabels() throws InterruptedException, TimeoutException { - String tableName = "test_query_job_table"; + String tableName = generateTableName("test_query_job_table"); String query = "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID.getTable(); Map labels = ImmutableMap.of("test-job-name", "test-query-job"); TableId destinationTable = TableId.of(DATASET, tableName); @@ -6095,11 +6111,9 @@ void testQueryJobWithLabels() throws InterruptedException, TimeoutException { @Test void testQueryJobWithSearchReturnsSearchStatisticsUnused() throws InterruptedException { - String tableName = "test_query_job_table"; + String tableName = generateTableName("test_query_job_table"); String query = - "SELECT * FROM " - + TABLE_ID.getTable() - + " WHERE search(StringField, \"stringValue\")"; + "SELECT * FROM " + TABLE_ID.getTable() + " WHERE search(StringField, \"stringValue\")"; TableId destinationTable = TableId.of(DATASET, tableName); try { QueryJobConfiguration configuration = @@ -6125,7 +6139,7 @@ void testQueryJobWithSearchReturnsSearchStatisticsUnused() throws InterruptedExc /* TODO(prasmish): replicate the entire test case for executeSelect */ @Test void testQueryJobWithRangePartitioning() throws InterruptedException { - String tableName = "test_query_job_table_rangepartitioning"; + String tableName = generateTableName("test_query_job_table_rangepartitioning"); String query = "SELECT IntegerField, TimestampField, StringField, BooleanField FROM " + TABLE_ID.getTable(); @@ -6150,7 +6164,7 @@ void testQueryJobWithRangePartitioning() throws InterruptedException { @Test void testLoadJobWithRangePartitioning() throws InterruptedException { - String tableName = "test_load_job_table_rangepartitioning"; + String tableName = generateTableName("test_load_job_table_rangepartitioning"); TableId destinationTable = TableId.of(DATASET, tableName); try { LoadJobConfiguration configuration = @@ -6174,7 +6188,7 @@ void testLoadJobWithRangePartitioning() throws InterruptedException { @Test void testLoadJobWithDecimalTargetTypes() throws InterruptedException { - String tableName = "test_load_job_table_parquet_decimalTargetTypes"; + String tableName = generateTableName("test_load_job_table_parquet_decimalTargetTypes"); TableId destinationTable = TableId.of(DATASET, tableName); String sourceUri = "gs://" + CLOUD_SAMPLES_DATA + "/bigquery/numeric/numeric_38_12.parquet"; try { @@ -6202,7 +6216,7 @@ void testLoadJobWithDecimalTargetTypes() throws InterruptedException { @Test void testExternalTableWithDecimalTargetTypes() throws InterruptedException { - String tableName = "test_create_external_table_parquet_decimalTargetTypes"; + String tableName = generateTableName("test_create_external_table_parquet_decimalTargetTypes"); TableId destinationTable = TableId.of(DATASET, tableName); String sourceUri = "gs://" + CLOUD_SAMPLES_DATA + "/bigquery/numeric/numeric_38_12.parquet"; ExternalTableDefinition externalTableDefinition = @@ -6222,7 +6236,7 @@ void testExternalTableWithDecimalTargetTypes() throws InterruptedException { @Test void testQueryJobWithDryRun() throws InterruptedException, TimeoutException { - String tableName = "test_query_job_table"; + String tableName = generateTableName("test_query_job_table"); String query = "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID.getTable(); TableId destinationTable = TableId.of(DATASET, tableName); QueryJobConfiguration configuration = @@ -6240,7 +6254,7 @@ void testQueryJobWithDryRun() throws InterruptedException, TimeoutException { @Test void testExtractJob() throws InterruptedException, TimeoutException { - String tableName = "test_export_job_table"; + String tableName = generateTableName("test_export_job_table"); TableId destinationTable = TableId.of(DATASET, tableName); Map labels = ImmutableMap.of("test-job-name", "test-load-extract-job"); LoadJobConfiguration configuration = @@ -6317,7 +6331,7 @@ void testExtractJobWithModel() throws InterruptedException { @Test void testExtractJobWithLabels() throws InterruptedException, TimeoutException { - String tableName = "test_export_job_table_label"; + String tableName = generateTableName("test_export_job_table_label"); Map labels = ImmutableMap.of("test_job_name", "test_export_job"); TableId destinationTable = TableId.of(DATASET, tableName); LoadJobConfiguration configuration = @@ -6343,7 +6357,7 @@ void testExtractJobWithLabels() throws InterruptedException, TimeoutException { @Test void testCancelJob() throws InterruptedException, TimeoutException { - String destinationTableName = "test_cancel_query_job_table"; + String destinationTableName = generateTableName("test_cancel_query_job_table"); String query = "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID.getTable(); TableId destinationTable = TableId.of(DATASET, destinationTableName); QueryJobConfiguration configuration = @@ -6625,7 +6639,8 @@ void testWriteChannelPreserveAsciiControlCharacters() @Test void testLoadJobPreserveAsciiControlCharacters() throws InterruptedException { - String destinationTableName = "test_load_job_preserve_ascii_control_characters"; + String destinationTableName = + generateTableName("test_load_job_preserve_ascii_control_characters"); TableId destinationTable = TableId.of(DATASET, destinationTableName); try { diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITNightlyBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITNightlyBigQueryTest.java index 84e355f9e..641868203 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITNightlyBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITNightlyBigQueryTest.java @@ -77,7 +77,8 @@ public class ITNightlyBigQueryTest { private static final Logger logger = Logger.getLogger(ITNightlyBigQueryTest.class.getName()); private static final String DATASET = RemoteBigQueryHelper.generateDatasetName(); - private static final String TABLE = "TEMP_RS_TEST_TABLE"; + private static final String TABLE = + "TEMP_RS_TEST_TABLE" + UUID.randomUUID().toString().substring(0, 8); private static final byte[] BYTES = "TestByteValue".getBytes(StandardCharsets.UTF_8); private static final String BYTES_BASE64 = BaseEncoding.base64().encode(BYTES); // Script will populate NUM_BATCHES*REC_PER_BATCHES number of records (eg: 100*10000 = 1M) @@ -355,7 +356,7 @@ void testConnectionClose() throws SQLException { while (rs.next()) { ++cnt; if (cnt == 50000) { // interrupt at 50K - assertTrue(connection.close()); + break; } } assertTrue(LIMIT_RECS > cnt);