Skip to content

Commit

Permalink
TransformColumns: @Property 'getters' and 'setters' + updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Salem Boyland authored and SalemJorden committed Sep 20, 2023
1 parent 209455a commit 61eb437
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 41 deletions.
29 changes: 17 additions & 12 deletions google/cloud/bigquery/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,22 +470,27 @@ def __init__(self,resource: Dict[str, Any]):
else:
self.type_ = standard_sql.StandardSqlDataType.from_api_repr(type_json)
self.transform_sql = resource.get("transformSql")
'''

@property
def name(self) -> Optional[str]:
"""str: Name of the transform column."""
return self.resource.get("name")
def name(self) -> str:
return self._properties.get("name")

@name.setter
def name(self, value: str):
self._properties["name"] = value

@property
def get_object_kind(self) -> Optional[standard_sql.StandardSqlDataType]:
"""str: Type of the transform column."""
return self.resource.get("type")
def type_json(self) -> Any:
return self._properties.get("type")

@property
def transform_sql(self) -> Optional[str]:
"""str: SQL expression of the transform column."""
return self.resource.get("transformSql")
'''
def transform_sql(self) -> str:
return self._properties.get("transformSql")

@transform_sql.setter
def transform_sql(self, value: str):
self._properties["transformSql"] = value


@classmethod
def from_api_repr(cls, resource: Dict[str, Any]) -> "TransformColumn":
Expand Down
39 changes: 10 additions & 29 deletions tests/unit/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ def test_feature_columns(object_under_test):
def test_transform_columns():
from google.cloud.bigquery import standard_sql
input_resource_ = {
"name": "is_male",
"type": {
"name": "is_male",
"type": {
"typeKind": "BOOL"
},
"transformSql": "is_male"
},
"transformSql": "is_male"
}
google.cloud.bigquery.model.TransformColumn(input_resource_)

Expand All @@ -323,31 +323,12 @@ def test_transform_column_type_none():
transform_column = google.cloud.bigquery.model.TransformColumn({"type":None})
assert transform_column.type_ is None

def test_transform_column_properties ():
transform_column = google.cloud.bigquery.model.TransformColumn({"Salem":"Apprentice"})
assert transform_column._properties == {"Salem":"Apprentice"}
""""
object_under_test._properties["transformColumns"] = [
{"name": "col_1", "type": {"name": "STRING"}},
{"name": "col_2", "type": {"typeKind": "INT64"}},
{"name": "col_3", "type": {"transform_sql": "STRING"}}
]
expected = [
"name": "col_1",
"type": {"name": "STRING"},
"transform_sql": "STRING"
,
"name": "col_2",
"type": {"typeKind": "INT64"},
"transform_sql": "STRING"
,
"name": "col_3",
"type": {"transform_sql": "STRING"},
"transform_sql": "STRING"
,
]
assert object_under_test.transform_columns == expected
"""
def test_transform_column_properties():
transform_column = google.cloud.bigquery.model.TransformColumn({"name": str,"type": {
"typeKind": bool},"transformSql":str})
assert transform_column._properties == {"name": str,"type": {
"typeKind": bool},"transformSql":str}


def test_label_columns(object_under_test):
from google.cloud.bigquery import standard_sql
Expand Down

0 comments on commit 61eb437

Please sign in to comment.