-
Notifications
You must be signed in to change notification settings - Fork 323
feat: add support for Parquet options #679
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import copy | ||
from typing import Dict | ||
|
||
|
||
class ParquetOptions: | ||
"""Additional options if the PARQUET source format is used.""" | ||
|
||
_SOURCE_FORMAT = "PARQUET" | ||
_RESOURCE_NAME = "parquetOptions" | ||
|
||
def __init__(self): | ||
self._properties = {} | ||
|
||
@property | ||
def enum_as_string(self) -> bool: | ||
"""Indicates whether to infer Parquet ENUM logical type as STRING instead of | ||
BYTES by default. | ||
|
||
See | ||
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ParquetOptions.FIELDS.enum_as_string | ||
""" | ||
return self._properties.get("enumAsString") | ||
|
||
@enum_as_string.setter | ||
def enum_as_string(self, value: bool) -> None: | ||
self._properties["enumAsString"] = value | ||
|
||
@property | ||
def enable_list_inference(self) -> bool: | ||
"""Indicates whether to use schema inference specifically for Parquet LIST | ||
logical type. | ||
|
||
See | ||
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ParquetOptions.FIELDS.enable_list_inference | ||
""" | ||
return self._properties.get("enableListInference") | ||
|
||
@enable_list_inference.setter | ||
def enable_list_inference(self, value: bool) -> None: | ||
self._properties["enableListInference"] = value | ||
|
||
@classmethod | ||
def from_api_repr(cls, resource: Dict[str, bool]) -> "ParquetOptions": | ||
"""Factory: construct an instance from a resource dict. | ||
|
||
Args: | ||
resource (Dict[str, bool]): | ||
Definition of a :class:`~.format_options.ParquetOptions` instance in | ||
the same representation as is returned from the API. | ||
|
||
Returns: | ||
:class:`~.format_options.ParquetOptions`: | ||
Configuration parsed from ``resource``. | ||
""" | ||
config = cls() | ||
config._properties = copy.deepcopy(resource) | ||
return config | ||
|
||
def to_api_repr(self) -> dict: | ||
"""Build an API representation of this object. | ||
|
||
Returns: | ||
Dict[str, bool]: | ||
A dictionary in the format used by the BigQuery API. | ||
""" | ||
return copy.deepcopy(self._properties) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
class TestParquetOptions: | ||
@staticmethod | ||
def _get_target_class(): | ||
from google.cloud.bigquery.format_options import ParquetOptions | ||
|
||
return ParquetOptions | ||
|
||
def test_ctor(self): | ||
config = self._get_target_class()() | ||
assert config.enum_as_string is None | ||
assert config.enable_list_inference is None | ||
|
||
def test_from_api_repr(self): | ||
config = self._get_target_class().from_api_repr( | ||
{"enumAsString": False, "enableListInference": True} | ||
) | ||
assert not config.enum_as_string | ||
assert config.enable_list_inference | ||
|
||
def test_to_api_repr(self): | ||
config = self._get_target_class()() | ||
config.enum_as_string = True | ||
config.enable_list_inference = False | ||
|
||
result = config.to_api_repr() | ||
assert result == {"enumAsString": True, "enableListInference": False} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.