-
Notifications
You must be signed in to change notification settings - Fork 312
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: adds the SerDeInfo class and tests #2108
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,10 @@ | |
|
||
"""Schemas for BigQuery tables / queries.""" | ||
|
||
from __future__ import annotations | ||
import collections | ||
import enum | ||
import typing | ||
from typing import Any, cast, Dict, Iterable, Optional, Union | ||
|
||
from google.cloud.bigquery import _helpers | ||
|
@@ -556,3 +558,89 @@ def to_api_repr(self) -> dict: | |
""" | ||
answer = {"names": list(self.names)} | ||
return answer | ||
|
||
|
||
class SerDeInfo: | ||
"""Serializer and deserializer information. | ||
|
||
Args: | ||
serialization_library (str): Required. Specifies a fully-qualified class | ||
name of the serialization library that is responsible for the | ||
translation of data between table representation and the underlying | ||
low-level input and output format structures. The maximum length is | ||
256 characters. | ||
name (Optional[str]): Name of the SerDe. The maximum length is 256 | ||
characters. | ||
parameters: (Optional[dict[str, str]]): Key-value pairs that define the initialization | ||
parameters for the serialization library. Maximum size 10 Kib. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
serialization_library: str, | ||
name: Optional[str] = None, | ||
parameters: Optional[dict[str, str]] = None, | ||
): | ||
self._properties: Dict[str, Any] = {} | ||
self.serialization_library = serialization_library | ||
self.name = name | ||
self.parameters = parameters | ||
|
||
@property | ||
def serialization_library(self) -> str: | ||
"""Required. Specifies a fully-qualified class name of the serialization | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in chat, I prefer to leave this as is. |
||
library that is responsible for the translation of data between table | ||
representation and the underlying low-level input and output format | ||
structures. The maximum length is 256 characters.""" | ||
|
||
return typing.cast(str, self._properties.get("serializationLibrary")) | ||
|
||
@serialization_library.setter | ||
def serialization_library(self, value: str): | ||
value = _helpers._isinstance_or_raise(value, str, none_allowed=False) | ||
self._properties["serializationLibrary"] = value | ||
|
||
@property | ||
def name(self) -> Optional[str]: | ||
"""Optional. Name of the SerDe. The maximum length is 256 characters.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: similarly, we can remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in chat, I prefer to leave this as is. |
||
|
||
return self._properties.get("name") | ||
|
||
@name.setter | ||
def name(self, value: Optional[str] = None): | ||
Linchin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
value = _helpers._isinstance_or_raise(value, str, none_allowed=True) | ||
self._properties["name"] = value | ||
|
||
@property | ||
def parameters(self) -> Optional[dict[str, str]]: | ||
"""Optional. Key-value pairs that define the initialization parameters | ||
for the serialization library. Maximum size 10 Kib.""" | ||
|
||
return self._properties.get("parameters") | ||
|
||
@parameters.setter | ||
def parameters(self, value: Optional[dict[str, str]] = None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See reply above from Python Docs about the concept of optional versus |
||
value = _helpers._isinstance_or_raise(value, dict, none_allowed=True) | ||
self._properties["parameters"] = value | ||
|
||
def to_api_repr(self) -> dict: | ||
"""Build an API representation of this object. | ||
Returns: | ||
Dict[str, Any]: | ||
A dictionary in the format used by the BigQuery API. | ||
""" | ||
return self._properties | ||
|
||
@classmethod | ||
def from_api_repr(cls, api_repr: dict) -> SerDeInfo: | ||
"""Factory: constructs an instance of the class (cls) | ||
given its API representation. | ||
Args: | ||
resource (Dict[str, Any]): | ||
API representation of the object to be instantiated. | ||
Returns: | ||
An instance of the class initialized with data from 'resource'. | ||
""" | ||
config = cls("PLACEHOLDER") | ||
config._properties = api_repr | ||
return config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the name in the REST API? I'd prefer the full names rather than abbreviations, but I'm OK with this if it's to be consistent with the proto/REST API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SerDeInfo
is the name in the proto/REST API definitions.