Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion bigquery/google/cloud/bigquery/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,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 @@ -1910,6 +1910,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 @@ -2996,6 +2996,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 @@ -3006,6 +3007,7 @@ def test_to_api_repr(self):
"fieldDelimiter": "ignored for avro",
"printHeader": False,
"someNewField": "some-value",
"useAvroLogicalTypes": True,
}
},
)
Expand All @@ -3020,6 +3022,7 @@ def test_from_api_repr(self):
"fieldDelimiter": "\t",
"printHeader": True,
"someNewField": "some-value",
"useAvroLogicalTypes": False,
}
}
)
Expand All @@ -3028,6 +3031,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