@@ -180,6 +180,7 @@ public class ITBigQueryTest {
180
180
private static final Long EXPIRATION_MS = 86400000L ;
181
181
private static final Logger LOG = Logger .getLogger (ITBigQueryTest .class .getName ());
182
182
private static final String DATASET = RemoteBigQueryHelper .generateDatasetName ();
183
+ private static final String UK_DATASET = RemoteBigQueryHelper .generateDatasetName ();
183
184
private static final String DESCRIPTION = "Test dataset" ;
184
185
private static final String OTHER_DATASET = RemoteBigQueryHelper .generateDatasetName ();
185
186
private static final String MODEL_DATASET = RemoteBigQueryHelper .generateDatasetName ();
@@ -533,6 +534,8 @@ public class ITBigQueryTest {
533
534
private static final TableId TABLE_ID = TableId .of (DATASET , "testing_table" );
534
535
private static final TableId TABLE_ID_DDL = TableId .of (DATASET , "ddl_testing_table" );
535
536
private static final TableId TABLE_ID_FASTQUERY = TableId .of (DATASET , "fastquery_testing_table" );
537
+ private static final TableId TABLE_ID_FASTQUERY_UK =
538
+ TableId .of (UK_DATASET , "fastquery_testing_table" );
536
539
private static final TableId TABLE_ID_LARGE = TableId .of (DATASET , "large_data_testing_table" );
537
540
private static final TableId TABLE_ID_FASTQUERY_BQ_RESULTSET =
538
541
TableId .of (DATASET , "fastquery_testing_bq_resultset" );
@@ -717,6 +720,7 @@ public static void beforeClass() throws InterruptedException, IOException {
717
720
DatasetInfo info3 =
718
721
DatasetInfo .newBuilder (ROUTINE_DATASET ).setDescription ("java routine lifecycle" ).build ();
719
722
bigquery .create (info3 );
723
+
720
724
LoadJobConfiguration configuration =
721
725
LoadJobConfiguration .newBuilder (
722
726
TABLE_ID , "gs://" + BUCKET + "/" + JSON_LOAD_FILE , FormatOptions .json ())
@@ -781,6 +785,7 @@ public static void beforeClass() throws InterruptedException, IOException {
781
785
public static void afterClass () throws ExecutionException , InterruptedException {
782
786
if (bigquery != null ) {
783
787
RemoteBigQueryHelper .forceDelete (bigquery , DATASET );
788
+ RemoteBigQueryHelper .forceDelete (bigquery , UK_DATASET );
784
789
RemoteBigQueryHelper .forceDelete (bigquery , MODEL_DATASET );
785
790
RemoteBigQueryHelper .forceDelete (bigquery , ROUTINE_DATASET );
786
791
}
@@ -3284,6 +3289,86 @@ public void testFastSQLQuery() throws InterruptedException {
3284
3289
}
3285
3290
}
3286
3291
3292
+ @ Test
3293
+ public void testProjectIDFastSQLQueryWithJobId () throws InterruptedException {
3294
+ String random_project_id = "RANDOM_PROJECT_" + UUID .randomUUID ().toString ().replace ('-' , '_' );
3295
+ System .out .println (random_project_id );
3296
+ String query =
3297
+ "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID_FASTQUERY .getTable ();
3298
+ // With incorrect projectID in jobid
3299
+ // The job will be created with the specified(incorrect) projectID
3300
+ // hence failing the operation
3301
+ JobId jobIdWithProjectId = JobId .newBuilder ().setProject (random_project_id ).build ();
3302
+ QueryJobConfiguration configSelect =
3303
+ QueryJobConfiguration .newBuilder (query ).setDefaultDataset (DatasetId .of (DATASET )).build ();
3304
+ try {
3305
+ bigquery .query (configSelect , jobIdWithProjectId );
3306
+ } catch (Exception exception ) {
3307
+ // error message for non-existent project
3308
+ assertTrue (exception .getMessage ().contains ("Cannot parse as CloudRegion" ));
3309
+ assertEquals (BigQueryException .class , exception .getClass ());
3310
+ }
3311
+ }
3312
+
3313
+ @ Test
3314
+ public void testLocationFastSQLQueryWithJobId () throws InterruptedException {
3315
+ DatasetInfo infoUK =
3316
+ DatasetInfo .newBuilder (UK_DATASET )
3317
+ .setDescription (DESCRIPTION )
3318
+ .setLocation ("europe-west1" )
3319
+ .setLabels (LABELS )
3320
+ .build ();
3321
+ bigquery .create (infoUK );
3322
+
3323
+ TableDefinition tableDefinition = StandardTableDefinition .of (SIMPLE_SCHEMA );
3324
+ TableInfo tableInfo = TableInfo .newBuilder (TABLE_ID_FASTQUERY_UK , tableDefinition ).build ();
3325
+ bigquery .create (tableInfo );
3326
+
3327
+ String insert =
3328
+ "INSERT " + UK_DATASET + "." + TABLE_ID_FASTQUERY_UK .getTable () + " VALUES('Anna');" ;
3329
+
3330
+ QueryJobConfiguration config =
3331
+ QueryJobConfiguration .newBuilder (insert )
3332
+ .setDefaultDataset (DatasetId .of (UK_DATASET ))
3333
+ .build ();
3334
+ TableResult result = bigquery .query (config );
3335
+ assertEquals (SIMPLE_SCHEMA , result .getSchema ());
3336
+ assertEquals (1 , result .getTotalRows ());
3337
+ assertNull (result .getNextPage ());
3338
+ assertNull (result .getNextPageToken ());
3339
+ assertFalse (result .hasNextPage ());
3340
+ // Verify correctness of table content
3341
+ for (FieldValueList row : result .getValues ()) {
3342
+ FieldValue stringCell = row .get (0 );
3343
+ assertEquals (stringCell , row .get ("StringField" ));
3344
+ assertEquals ("Anna" , stringCell .getStringValue ());
3345
+ }
3346
+ // With incorrect location in jobid
3347
+ // The job will be created with the specified(incorrect) location
3348
+ // hence failing the operation
3349
+ String query = "SELECT StringField FROM " + TABLE_ID_FASTQUERY_UK .getTable ();
3350
+ JobId jobIdWithLocation = JobId .newBuilder ().setLocation ("us-west1" ).build ();
3351
+ QueryJobConfiguration configSelect =
3352
+ QueryJobConfiguration .newBuilder (query ).setDefaultDataset (DatasetId .of (UK_DATASET )).build ();
3353
+ try {
3354
+ bigquery .query (configSelect , jobIdWithLocation );
3355
+ } catch (BigQueryException exception ) {
3356
+ assertTrue (exception .getMessage ().contains ("Not found" ));
3357
+ assertEquals (BigQueryException .class , exception .getClass ());
3358
+ }
3359
+
3360
+ // Without location in jobID, the query job defaults to the location of the dataset
3361
+ JobId jobIdNoLocation = JobId .newBuilder ().build ();
3362
+ QueryJobConfiguration configNoLocation =
3363
+ QueryJobConfiguration .newBuilder (query ).setDefaultDataset (DatasetId .of (UK_DATASET )).build ();
3364
+ TableResult resultNoLocation = bigquery .query (configNoLocation , jobIdNoLocation );
3365
+ for (FieldValueList row : resultNoLocation .getValues ()) {
3366
+ FieldValue stringCell = row .get (0 );
3367
+ assertEquals (stringCell , row .get ("StringField" ));
3368
+ assertEquals ("Anna" , stringCell .getStringValue ());
3369
+ }
3370
+ }
3371
+
3287
3372
/* TODO(prasmish): replicate the entire test case for executeSelect */
3288
3373
@ Test
3289
3374
public void testFastSQLQueryMultiPage () throws InterruptedException {
0 commit comments