Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d664d2d

Browse filesBrowse files
shollymantseaver
authored andcommitted
Add avro logical type control for load jobs. (googleapis#6827)
1 parent e9ddb89 commit d664d2d
Copy full SHA for d664d2d

File tree

Expand file treeCollapse file tree

2 files changed

+35
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+35
-0
lines changed

‎bigquery/google/cloud/bigquery/job.py

Copy file name to clipboardExpand all lines: bigquery/google/cloud/bigquery/job.py
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,18 @@ def time_partitioning(self, value):
11951195
else:
11961196
self._del_sub_prop("timePartitioning")
11971197

1198+
@property
1199+
def use_avro_logical_types(self):
1200+
"""bool: For loads of Avro data, governs whether Avro logical types are
1201+
converted to their corresponding BigQuery types(e.g. TIMESTAMP) rather than
1202+
raw types (e.g. INTEGER).
1203+
"""
1204+
return self._get_sub_prop("useAvroLogicalTypes")
1205+
1206+
@use_avro_logical_types.setter
1207+
def use_avro_logical_types(self, value):
1208+
self._set_sub_prop("useAvroLogicalTypes", bool(value))
1209+
11981210
@property
11991211
def write_disposition(self):
12001212
"""google.cloud.bigquery.job.WriteDisposition: Action that occurs if
@@ -1362,6 +1374,13 @@ def time_partitioning(self):
13621374
"""
13631375
return self._configuration.time_partitioning
13641376

1377+
@property
1378+
def use_avro_logical_types(self):
1379+
"""See
1380+
:attr:`google.cloud.bigquery.job.LoadJobConfig.use_avro_logical_types`.
1381+
"""
1382+
return self._configuration.use_avro_logical_types
1383+
13651384
@property
13661385
def clustering_fields(self):
13671386
"""See

‎bigquery/tests/unit/test_job.py

Copy file name to clipboardExpand all lines: bigquery/tests/unit/test_job.py
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,15 @@ def test_time_partitioning_setter_w_none(self):
15881588
self.assertIsNone(config.time_partitioning)
15891589
self.assertNotIn("timePartitioning", config._properties["load"])
15901590

1591+
def test_use_avro_logical_types(self):
1592+
config = self._get_target_class()()
1593+
self.assertIsNone(config.use_avro_logical_types)
1594+
1595+
def test_use_avro_logical_types_setter(self):
1596+
config = self._get_target_class()()
1597+
config.use_avro_logical_types = True
1598+
self.assertTrue(config._properties["load"]["useAvroLogicalTypes"])
1599+
15911600
def test_write_disposition_missing(self):
15921601
config = self._get_target_class()()
15931602
self.assertIsNone(config.write_disposition)
@@ -1663,6 +1672,10 @@ def _verifyBooleanConfigProperties(self, job, config):
16631672
self.assertEqual(job.ignore_unknown_values, config["ignoreUnknownValues"])
16641673
else:
16651674
self.assertIsNone(job.ignore_unknown_values)
1675+
if "useAvroLogicalTypes" in config:
1676+
self.assertEqual(job.use_avro_logical_types, config["useAvroLogicalTypes"])
1677+
else:
1678+
self.assertIsNone(job.use_avro_logical_types)
16661679

16671680
def _verifyEnumConfigProperties(self, job, config):
16681681
if "createDisposition" in config:
@@ -1765,6 +1778,7 @@ def test_ctor(self):
17651778
self.assertIsNone(job.write_disposition)
17661779
self.assertIsNone(job.destination_encryption_configuration)
17671780
self.assertIsNone(job.time_partitioning)
1781+
self.assertIsNone(job.use_avro_logical_types)
17681782
self.assertIsNone(job.clustering_fields)
17691783
self.assertIsNone(job.schema_update_options)
17701784

@@ -2097,6 +2111,7 @@ def test_begin_w_alternate_client(self):
20972111
"quote": "'",
20982112
"skipLeadingRows": "1",
20992113
"sourceFormat": "CSV",
2114+
"useAvroLogicalTypes": True,
21002115
"writeDisposition": WriteDisposition.WRITE_TRUNCATE,
21012116
"schema": {
21022117
"fields": [
@@ -2139,6 +2154,7 @@ def test_begin_w_alternate_client(self):
21392154
config.quote_character = "'"
21402155
config.skip_leading_rows = 1
21412156
config.source_format = "CSV"
2157+
config.use_avro_logical_types = True
21422158
config.write_disposition = WriteDisposition.WRITE_TRUNCATE
21432159
config.schema_update_options = [SchemaUpdateOption.ALLOW_FIELD_ADDITION]
21442160

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.