@@ -828,6 +828,22 @@ def test_write_disposition_setter(self):
828828 config ._properties ["load" ]["writeDisposition" ], write_disposition
829829 )
830830
831+ def test_time_zone_missing (self ):
832+ config = self ._get_target_class ()()
833+ self .assertIsNone (config .time_zone )
834+
835+ def test_time_zone_hit (self ):
836+ time_zone = "UTC"
837+ config = self ._get_target_class ()()
838+ config ._properties ["load" ]["timeZone" ] = time_zone
839+ self .assertEqual (config .time_zone , time_zone )
840+
841+ def test_time_zone_setter (self ):
842+ time_zone = "America/New_York"
843+ config = self ._get_target_class ()()
844+ config .time_zone = time_zone
845+ self .assertEqual (config ._properties ["load" ]["timeZone" ], time_zone )
846+
831847 def test_parquet_options_missing (self ):
832848 config = self ._get_target_class ()()
833849 self .assertIsNone (config .parquet_options )
@@ -901,3 +917,114 @@ def test_column_name_character_map_none(self):
901917 config ._properties ["load" ]["columnNameCharacterMap" ],
902918 ColumnNameCharacterMap .COLUMN_NAME_CHARACTER_MAP_UNSPECIFIED ,
903919 )
920+
921+ RESOURCE = {
922+ "load" : {
923+ "allowJaggedRows" : True ,
924+ "createDisposition" : "CREATE_NEVER" ,
925+ "encoding" : "UTF-8" ,
926+ "fieldDelimiter" : "," ,
927+ "ignoreUnknownValues" : True ,
928+ "maxBadRecords" : 10 ,
929+ "nullMarker" : "\\ N" ,
930+ "quote" : '"' ,
931+ "schema" : {
932+ "fields" : [
933+ {"name" : "name" , "type" : "STRING" , "mode" : "NULLABLE" },
934+ {"name" : "age" , "type" : "INTEGER" , "mode" : "NULLABLE" },
935+ ]
936+ },
937+ "skipLeadingRows" : "1" ,
938+ "sourceFormat" : "CSV" ,
939+ "timePartitioning" : {
940+ "type" : "DAY" ,
941+ "field" : "transaction_date" ,
942+ },
943+ "useAvroLogicalTypes" : True ,
944+ "writeDisposition" : "WRITE_TRUNCATE" ,
945+ "timeZone" : "America/New_York" ,
946+ "parquetOptions" : {"enableListInference" : True },
947+ "columnNameCharacterMap" : "V2" ,
948+ "someNewField" : "some-value" ,
949+ }
950+ }
951+
952+ def test_from_api_repr (self ):
953+ from google .cloud .bigquery .job import (
954+ CreateDisposition ,
955+ LoadJobConfig ,
956+ SourceFormat ,
957+ WriteDisposition ,
958+ )
959+ from google .cloud .bigquery .schema import SchemaField
960+ from google .cloud .bigquery .table import TimePartitioning , TimePartitioningType
961+
962+ from google .cloud .bigquery .job .load import ColumnNameCharacterMap
963+
964+ config = LoadJobConfig .from_api_repr (self .RESOURCE )
965+
966+ self .assertTrue (config .allow_jagged_rows )
967+ self .assertEqual (config .create_disposition , CreateDisposition .CREATE_NEVER )
968+ self .assertEqual (config .encoding , "UTF-8" )
969+ self .assertEqual (config .field_delimiter , "," )
970+ self .assertTrue (config .ignore_unknown_values )
971+ self .assertEqual (config .max_bad_records , 10 )
972+ self .assertEqual (config .null_marker , "\\ N" )
973+ self .assertEqual (config .quote_character , '"' )
974+ self .assertEqual (
975+ config .schema ,
976+ [SchemaField ("name" , "STRING" ), SchemaField ("age" , "INTEGER" )],
977+ )
978+ self .assertEqual (config .skip_leading_rows , 1 )
979+ self .assertEqual (config .source_format , SourceFormat .CSV )
980+ self .assertEqual (
981+ config .time_partitioning ,
982+ TimePartitioning (type_ = TimePartitioningType .DAY , field = "transaction_date" ),
983+ )
984+ self .assertTrue (config .use_avro_logical_types )
985+ self .assertEqual (config .write_disposition , WriteDisposition .WRITE_TRUNCATE )
986+ self .assertEqual (config .time_zone , "America/New_York" )
987+ self .assertTrue (config .parquet_options .enable_list_inference )
988+ self .assertEqual (config .column_name_character_map , ColumnNameCharacterMap .V2 )
989+ self .assertEqual (config ._properties ["load" ]["someNewField" ], "some-value" )
990+
991+ def test_to_api_repr (self ):
992+ from google .cloud .bigquery .job import (
993+ CreateDisposition ,
994+ LoadJobConfig ,
995+ SourceFormat ,
996+ WriteDisposition ,
997+ )
998+ from google .cloud .bigquery .schema import SchemaField
999+ from google .cloud .bigquery .table import TimePartitioning , TimePartitioningType
1000+ from google .cloud .bigquery .format_options import ParquetOptions
1001+ from google .cloud .bigquery .job .load import ColumnNameCharacterMap
1002+
1003+ config = LoadJobConfig ()
1004+ config .allow_jagged_rows = True
1005+ config .create_disposition = CreateDisposition .CREATE_NEVER
1006+ config .encoding = "UTF-8"
1007+ config .field_delimiter = ","
1008+ config .ignore_unknown_values = True
1009+ config .max_bad_records = 10
1010+ config .null_marker = r"\N"
1011+ config .quote_character = '"'
1012+ config .schema = [SchemaField ("name" , "STRING" ), SchemaField ("age" , "INTEGER" )]
1013+ config .skip_leading_rows = 1
1014+ config .source_format = SourceFormat .CSV
1015+ config .time_partitioning = TimePartitioning (
1016+ type_ = TimePartitioningType .DAY , field = "transaction_date"
1017+ )
1018+ config .use_avro_logical_types = True
1019+ config .write_disposition = WriteDisposition .WRITE_TRUNCATE
1020+ config .time_zone = "America/New_York"
1021+ parquet_options = ParquetOptions ()
1022+ parquet_options .enable_list_inference = True
1023+ config .parquet_options = parquet_options
1024+ config .column_name_character_map = ColumnNameCharacterMap .V2
1025+ config ._properties ["load" ]["someNewField" ] = "some-value"
1026+
1027+ api_repr = config .to_api_repr ()
1028+
1029+ expected = self .RESOURCE
1030+ self .assertEqual (api_repr , expected )
0 commit comments