Skip to content

Commit 2a5774e

Browse files
committed
add new classes and tests
1 parent 68d04f0 commit 2a5774e

File tree

3 files changed

+324
-15
lines changed

3 files changed

+324
-15
lines changed

google/cloud/bigquery/schema.py

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,5 +677,158 @@ def to_api_repr(self) -> dict:
677677
return copy.deepcopy(self._properties)
678678

679679

680+
class StorageDescriptor(ResourceBase):
681+
"""Contains information about how a table's data is stored and accessed by open
682+
source query engines.
680683
684+
Args:
685+
inputFormat (Optional[str]): Specifies the fully qualified class name of
686+
the InputFormat (e.g.
687+
"org.apache.hadoop.hive.ql.io.orc.OrcInputFormat"). The maximum
688+
length is 128 characters.
689+
locationUri (Optional[str]): The physical location of the table (e.g.
690+
`gs://spark-dataproc-data/pangea-data/case_sensitive/` or
691+
`gs://spark-dataproc-data/pangea-data/*`). The maximum length is
692+
2056 bytes.
693+
outputFormat (Optional[str]): Specifies the fully qualified class name
694+
of the OutputFormat (e.g.
695+
"org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat"). The maximum
696+
length is 128 characters.
697+
serdeInfo (Optional[Any]): Serializer and deserializer information.
698+
"""
699+
700+
def __init__(self, input_format: Optional[str] = None, location_uri: Optional[str] = None, output_format: Optional[str] = None, serde_info: Optional[Any] = None):
701+
self._properties = {}
702+
self.input_format = input_format
703+
self.location_uri = location_uri
704+
self.output_format = output_format
705+
self.serde_info = serde_info
706+
707+
@property
708+
def input_format(self) -> Any:
709+
'''Optional. Specifies the fully qualified class name of the InputFormat
710+
(e.g. "org.apache.hadoop.hive.ql.io.orc.OrcInputFormat"). The maximum
711+
length is 128 characters.'''
712+
713+
return self._properties.get("inputFormat")
714+
715+
@input_format.setter
716+
def input_format(self, value: Optional[str]):
717+
value = _isinstance_or_raise(value, (str, None))
718+
self._properties['inputFormat'] = value
719+
720+
@property
721+
def location_uri(self) -> Any:
722+
'''Optional. The physical location of the table (e.g. `gs://spark-
723+
dataproc-data/pangea-data/case_sensitive/` or `gs://spark-dataproc-
724+
data/pangea-data/*`). The maximum length is 2056 bytes.'''
725+
726+
return self._properties.get("locationUri")
727+
728+
@location_uri.setter
729+
def location_uri(self, value: Optional[str]):
730+
value = _isinstance_or_raise(value, (str, None))
731+
self._properties['locationUri'] = value
732+
733+
@property
734+
def output_format(self) -> Any:
735+
'''Optional. Specifies the fully qualified class name of the
736+
OutputFormat (e.g. "org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat").
737+
The maximum length is 128 characters.'''
681738

739+
return self._properties.get("outputFormat")
740+
741+
@output_format.setter
742+
def output_format(self, value: Optional[str]):
743+
value = _isinstance_or_raise(value, (str, None))
744+
self._properties['outputFormat'] = value
745+
746+
@property
747+
def serde_info(self) -> Any:
748+
'''Optional. Serializer and deserializer information.'''
749+
750+
return self._properties.get("serdeInfo")
751+
752+
@serde_info.setter
753+
def serde_info(self, value: Optional[Any]):
754+
value = _isinstance_or_raise(value, (str, None)) #TODO fix, when serde class is done
755+
self._properties['serdeInfo'] = value
756+
757+
758+
def to_api_repr(self) -> dict:
759+
"""Build an API representation of this object.
760+
761+
Returns:
762+
Dict[str, Any]:
763+
A dictionary in the format used by the BigQuery API.
764+
"""
765+
return copy.deepcopy(self._properties)
766+
767+
768+
class SerDeInfo(ResourceBase):
769+
"""Serializer and deserializer information.
770+
771+
Args:
772+
serializationLibrary (str): Required. Specifies a fully-qualified class
773+
name of the serialization library that is responsible for the
774+
translation of data between table representation and the underlying
775+
low-level input and output format structures. The maximum length is
776+
256 characters.
777+
name (Optional[str]): Name of the SerDe. The maximum length is 256
778+
characters.
779+
parameters: (Optional[dict[str, str]]): Key-value pairs that define the initialization
780+
parameters for the serialization library. Maximum size 10 Kib.
781+
"""
782+
783+
def __init__(self, serialization_library: str, name: Optional[str] = None, parameters: Optional[dict[str, str]] = None):
784+
self._properties = {}
785+
self.serialization_library = serialization_library
786+
self.name = name
787+
self.parameters = parameters
788+
789+
@property
790+
def serialization_library(self) -> Any:
791+
'''Required. Specifies a fully-qualified class name of the serialization
792+
library that is responsible for the translation of data between table
793+
representation and the underlying low-level input and output format
794+
structures. The maximum length is 256 characters.'''
795+
796+
return self._properties.get('serializationLibrary')
797+
798+
@serialization_library.setter
799+
def serialization_library(self, value: str):
800+
value = _isinstance_or_raise(value, str)
801+
self._properties['serializationLibrary'] = value
802+
803+
804+
@property
805+
def name(self) -> Any:
806+
'''Optional. Name of the SerDe. The maximum length is 256 characters.'''
807+
808+
return self._properties.get('name')
809+
810+
@name.setter
811+
def name(self, value: Optional[str] = None):
812+
value = _isinstance_or_raise(value, (str, None))
813+
self._properties['name'] = value
814+
815+
@property
816+
def parameters(self) -> Any:
817+
'''Optional. Key-value pairs that define the initialization parameters
818+
for the serialization library. Maximum size 10 Kib.'''
819+
820+
return self._properties.get('parameters')
821+
822+
@parameters.setter
823+
def parameters(self, value: Optional[dict[str, str]] = None):
824+
value = _isinstance_or_raise(value, (dict, None))
825+
self._properties['parameters'] = value
826+
827+
def to_api_repr(self) -> dict:
828+
"""Build an API representation of this object.
829+
830+
Returns:
831+
Dict[str, Any]:
832+
A dictionary in the format used by the BigQuery API.
833+
"""
834+
return copy.deepcopy(self._properties)

tests/unit/test_external_config.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -935,11 +935,11 @@ def test_ctor_invalid_input(self):
935935
"""Test ExternalCatalogDatasetOptions constructor with invalid input."""
936936
with pytest.raises(TypeError) as e:
937937
result = self._make_one(default_storage_location_uri=123)
938-
assert result == e
938+
assert "Pass" in str(e.value)
939+
939940
with pytest.raises(TypeError) as e:
940941
result = self._make_one(parameters=123)
941-
assert result == e
942-
942+
assert "Pass" in str(e.value)
943943

944944
def test_to_api_repr(self):
945945
"""Test ExternalCatalogDatasetOptions.to_api_repr method."""
@@ -1006,27 +1006,24 @@ def test_to_api_repr(self):
10061006
}
10071007

10081008
@pytest.mark.parametrize(
1009-
"connection_id, parameters, storage_descriptor, exception_class",
1009+
"connection_id, parameters, storage_descriptor",
10101010
[
10111011
pytest.param(
10121012
123,
1013-
{"key": "value"},
1014-
"placeholder",
1015-
TypeError,
1013+
{"test_key": "test_value"},
1014+
"test placeholder",
10161015
id="connection_id-invalid-type",
10171016
),
10181017
pytest.param(
10191018
"connection123",
10201019
123,
1021-
"placeholder",
1022-
TypeError,
1020+
"test placeholder",
10231021
id="parameters-invalid-type",
10241022
),
10251023
pytest.param(
10261024
"connection123",
1027-
{"key": "value"},
1025+
{"test_key": "test_value"},
10281026
123,
1029-
TypeError,
10301027
id="storage_descriptor-invalid-type",
10311028
),
10321029
],
@@ -1036,11 +1033,12 @@ def test_ctor_invalid_input(
10361033
connection_id: str,
10371034
parameters: Dict[str, Any],
10381035
storage_descriptor: str,
1039-
exception_class: TypeError,
10401036
):
1041-
with pytest.raises(exception_class):
1037+
with pytest.raises(TypeError) as e:
10421038
external_config.ExternalCatalogTableOptions(
10431039
connection_id=connection_id,
10441040
parameters=parameters,
10451041
storage_descriptor=storage_descriptor,
10461042
)
1043+
1044+
assert "Pass" in str(e.value)

0 commit comments

Comments
 (0)