@@ -425,6 +425,106 @@ def test_to_api_repr_bigtable(self):
425
425
426
426
self .assertEqual (got_resource , exp_resource )
427
427
428
+ def test_parquet_options_getter (self ):
429
+ from google .cloud .bigquery .format_options import ParquetOptions
430
+
431
+ parquet_options = ParquetOptions .from_api_repr (
432
+ {"enumAsString" : True , "enableListInference" : False }
433
+ )
434
+ ec = external_config .ExternalConfig (
435
+ external_config .ExternalSourceFormat .PARQUET
436
+ )
437
+
438
+ self .assertIsNone (ec .parquet_options .enum_as_string )
439
+ self .assertIsNone (ec .parquet_options .enable_list_inference )
440
+
441
+ ec ._options = parquet_options
442
+
443
+ self .assertTrue (ec .parquet_options .enum_as_string )
444
+ self .assertFalse (ec .parquet_options .enable_list_inference )
445
+
446
+ self .assertIs (ec .parquet_options , ec .options )
447
+
448
+ def test_parquet_options_getter_non_parquet_format (self ):
449
+ ec = external_config .ExternalConfig (external_config .ExternalSourceFormat .CSV )
450
+ self .assertIsNone (ec .parquet_options )
451
+
452
+ def test_parquet_options_setter (self ):
453
+ from google .cloud .bigquery .format_options import ParquetOptions
454
+
455
+ parquet_options = ParquetOptions .from_api_repr (
456
+ {"enumAsString" : False , "enableListInference" : True }
457
+ )
458
+ ec = external_config .ExternalConfig (
459
+ external_config .ExternalSourceFormat .PARQUET
460
+ )
461
+
462
+ ec .parquet_options = parquet_options
463
+
464
+ # Setting Parquet options should be reflected in the generic options attribute.
465
+ self .assertFalse (ec .options .enum_as_string )
466
+ self .assertTrue (ec .options .enable_list_inference )
467
+
468
+ def test_parquet_options_setter_non_parquet_format (self ):
469
+ from google .cloud .bigquery .format_options import ParquetOptions
470
+
471
+ parquet_options = ParquetOptions .from_api_repr (
472
+ {"enumAsString" : False , "enableListInference" : True }
473
+ )
474
+ ec = external_config .ExternalConfig (external_config .ExternalSourceFormat .CSV )
475
+
476
+ with self .assertRaisesRegex (TypeError , "Cannot set.*source format is CSV" ):
477
+ ec .parquet_options = parquet_options
478
+
479
+ def test_from_api_repr_parquet (self ):
480
+ from google .cloud .bigquery .format_options import ParquetOptions
481
+
482
+ resource = _copy_and_update (
483
+ self .BASE_RESOURCE ,
484
+ {
485
+ "sourceFormat" : "PARQUET" ,
486
+ "parquetOptions" : {"enumAsString" : True , "enableListInference" : False },
487
+ },
488
+ )
489
+
490
+ ec = external_config .ExternalConfig .from_api_repr (resource )
491
+
492
+ self ._verify_base (ec )
493
+ self .assertEqual (ec .source_format , external_config .ExternalSourceFormat .PARQUET )
494
+ self .assertIsInstance (ec .options , ParquetOptions )
495
+ self .assertTrue (ec .parquet_options .enum_as_string )
496
+ self .assertFalse (ec .parquet_options .enable_list_inference )
497
+
498
+ got_resource = ec .to_api_repr ()
499
+
500
+ self .assertEqual (got_resource , resource )
501
+
502
+ del resource ["parquetOptions" ]["enableListInference" ]
503
+ ec = external_config .ExternalConfig .from_api_repr (resource )
504
+ self .assertIsNone (ec .options .enable_list_inference )
505
+ got_resource = ec .to_api_repr ()
506
+ self .assertEqual (got_resource , resource )
507
+
508
+ def test_to_api_repr_parquet (self ):
509
+ from google .cloud .bigquery .format_options import ParquetOptions
510
+
511
+ ec = external_config .ExternalConfig (
512
+ external_config .ExternalSourceFormat .PARQUET
513
+ )
514
+ options = ParquetOptions .from_api_repr (
515
+ dict (enumAsString = False , enableListInference = True )
516
+ )
517
+ ec ._options = options
518
+
519
+ exp_resource = {
520
+ "sourceFormat" : external_config .ExternalSourceFormat .PARQUET ,
521
+ "parquetOptions" : {"enumAsString" : False , "enableListInference" : True },
522
+ }
523
+
524
+ got_resource = ec .to_api_repr ()
525
+
526
+ self .assertEqual (got_resource , exp_resource )
527
+
428
528
429
529
def _copy_and_update (d , u ):
430
530
d = copy .deepcopy (d )
0 commit comments