Skip to content

Commit

Permalink
feat(bigquery): add support of use_avro_logical_types for extract jobs (
Browse files Browse the repository at this point in the history
#9642)

* feat(bigquery): add support of use_avro_logical_types for extract jobs

* feat(bigquery): cosmetic change

* feat(bigquery): docstring change of use_avro_logical_types in LoadJobConfig class
  • Loading branch information
HemangChothani authored and tswast committed Nov 20, 2019
1 parent 357e521 commit 1959307
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 13 additions & 1 deletion bigquery/google/cloud/bigquery/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ def time_partitioning(self, value):
@property
def use_avro_logical_types(self):
"""bool: For loads of Avro data, governs whether Avro logical types are
converted to their corresponding BigQuery types(e.g. TIMESTAMP) rather than
converted to their corresponding BigQuery types (e.g. TIMESTAMP) rather than
raw types (e.g. INTEGER).
"""
return self._get_sub_prop("useAvroLogicalTypes")
Expand Down Expand Up @@ -1938,6 +1938,18 @@ def print_header(self):
def print_header(self, value):
self._set_sub_prop("printHeader", value)

@property
def use_avro_logical_types(self):
"""bool: For loads of Avro data, governs whether Avro logical types are
converted to their corresponding BigQuery types (e.g. TIMESTAMP) rather than
raw types (e.g. INTEGER).
"""
return self._get_sub_prop("useAvroLogicalTypes")

@use_avro_logical_types.setter
def use_avro_logical_types(self, value):
self._set_sub_prop("useAvroLogicalTypes", bool(value))


class ExtractJob(_AsyncJob):
"""Asynchronous job: extract data from a table into Cloud Storage.
Expand Down
4 changes: 4 additions & 0 deletions bigquery/tests/unit/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -3036,6 +3036,7 @@ def test_to_api_repr(self):
config.field_delimiter = "ignored for avro"
config.print_header = False
config._properties["extract"]["someNewField"] = "some-value"
config.use_avro_logical_types = True
resource = config.to_api_repr()
self.assertEqual(
resource,
Expand All @@ -3046,6 +3047,7 @@ def test_to_api_repr(self):
"fieldDelimiter": "ignored for avro",
"printHeader": False,
"someNewField": "some-value",
"useAvroLogicalTypes": True,
}
},
)
Expand All @@ -3060,6 +3062,7 @@ def test_from_api_repr(self):
"fieldDelimiter": "\t",
"printHeader": True,
"someNewField": "some-value",
"useAvroLogicalTypes": False,
}
}
)
Expand All @@ -3068,6 +3071,7 @@ def test_from_api_repr(self):
self.assertEqual(config.field_delimiter, "\t")
self.assertEqual(config.print_header, True)
self.assertEqual(config._properties["extract"]["someNewField"], "some-value")
self.assertEqual(config.use_avro_logical_types, False)


class TestExtractJob(unittest.TestCase, _Base):
Expand Down

0 comments on commit 1959307

Please sign in to comment.