-
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 StorageDescriptor and tests #2109
Changes from 1 commit
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 | ||||
---|---|---|---|---|---|---|
|
@@ -644,3 +644,117 @@ def from_api_repr(cls, api_repr: dict) -> SerDeInfo: | |||||
config = cls("PLACEHOLDER") | ||||||
config._properties = api_repr | ||||||
return config | ||||||
|
||||||
|
||||||
class StorageDescriptor: | ||||||
"""Contains information about how a table's data is stored and accessed by open | ||||||
source query engines. | ||||||
Args: | ||||||
inputFormat (Optional[str]): Specifies the fully qualified class name of | ||||||
the InputFormat (e.g. | ||||||
"org.apache.hadoop.hive.ql.io.orc.OrcInputFormat"). The maximum | ||||||
length is 128 characters. | ||||||
locationUri (Optional[str]): The physical location of the table (e.g. | ||||||
'gs://spark-dataproc-data/pangea-data/case_sensitive/' or | ||||||
'gs://spark-dataproc-data/pangea-data/'). The maximum length is | ||||||
2056 bytes. | ||||||
outputFormat (Optional[str]): Specifies the fully qualified class name | ||||||
of the OutputFormat (e.g. | ||||||
"org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat"). The maximum | ||||||
length is 128 characters. | ||||||
serdeInfo (Union[SerDeInfo, dict, None]): Serializer and deserializer information. | ||||||
""" | ||||||
|
||||||
def __init__( | ||||||
self, | ||||||
input_format: Optional[str] = None, | ||||||
location_uri: Optional[str] = None, | ||||||
output_format: Optional[str] = None, | ||||||
serde_info: Union[SerDeInfo, dict, None] = None, | ||||||
): | ||||||
self._properties: Dict[str, Any] = {} | ||||||
self.input_format = input_format | ||||||
self.location_uri = location_uri | ||||||
self.output_format = output_format | ||||||
self.serde_info = serde_info | ||||||
|
||||||
@property | ||||||
def input_format(self) -> Optional[str]: | ||||||
"""Optional. Specifies the fully qualified class name of the InputFormat | ||||||
(e.g. "org.apache.hadoop.hive.ql.io.orc.OrcInputFormat"). The maximum | ||||||
length is 128 characters.""" | ||||||
|
||||||
return self._properties.get("inputFormat") | ||||||
|
||||||
@input_format.setter | ||||||
def input_format(self, value: Optional[str]): | ||||||
value = _helpers._isinstance_or_raise(value, str, none_allowed=True) | ||||||
self._properties["inputFormat"] = value | ||||||
|
||||||
@property | ||||||
def location_uri(self) -> Optional[str]: | ||||||
"""Optional. The physical location of the table (e.g. 'gs://spark- | ||||||
dataproc-data/pangea-data/case_sensitive/' or 'gs://spark-dataproc- | ||||||
data/pangea-data/'). The maximum length is 2056 bytes.""" | ||||||
|
||||||
return self._properties.get("locationUri") | ||||||
|
||||||
@location_uri.setter | ||||||
def location_uri(self, value: Optional[str]): | ||||||
value = _helpers._isinstance_or_raise(value, str, none_allowed=True) | ||||||
self._properties["locationUri"] = value | ||||||
|
||||||
@property | ||||||
def output_format(self) -> Optional[str]: | ||||||
"""Optional. Specifies the fully qualified class name of the | ||||||
OutputFormat (e.g. "org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat"). | ||||||
The maximum length is 128 characters.""" | ||||||
|
||||||
return self._properties.get("outputFormat") | ||||||
|
||||||
@output_format.setter | ||||||
def output_format(self, value: Optional[str]): | ||||||
value = _helpers._isinstance_or_raise(value, str, none_allowed=True) | ||||||
self._properties["outputFormat"] = value | ||||||
|
||||||
@property | ||||||
def serde_info(self) -> Union[SerDeInfo, dict, 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. We'd never return a 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. resolved.
I added a |
||||||
"""Optional. Serializer and deserializer information.""" | ||||||
|
||||||
prop = _helpers._get_sub_prop(self._properties, ["serDeInfo"]) | ||||||
if prop is not None: | ||||||
prop = SerDeInfo("PLACEHOLDER").from_api_repr(prop) | ||||||
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.
Suggested change
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. Resolved. |
||||||
return prop | ||||||
|
||||||
@serde_info.setter | ||||||
def serde_info(self, value: Union[SerDeInfo, dict, None]): | ||||||
value = _helpers._isinstance_or_raise( | ||||||
value, (SerDeInfo, dict), none_allowed=True | ||||||
) | ||||||
|
||||||
if value is not None: | ||||||
if isinstance(value, SerDeInfo): | ||||||
value = value.to_api_repr() | ||||||
self._properties["serDeInfo"] = 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, resource: dict) -> StorageDescriptor: | ||||||
"""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() | ||||||
config._properties = resource | ||||||
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.
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.
Resolved.