Skip to content

Commit

Permalink
Merge branch 'pangea-v1alpha' into feat-b358215039-update-schema-object
Browse files Browse the repository at this point in the history
  • Loading branch information
chalmerlowe authored Dec 6, 2024
2 parents 83aacdf + 07bc30a commit 7c08ca8
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 54 deletions.
17 changes: 0 additions & 17 deletions google/cloud/bigquery/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""Shared helper functions for BigQuery API classes."""

import base64
import copy
import datetime
import decimal
import json
Expand Down Expand Up @@ -1038,19 +1037,3 @@ def _isinstance_or_raise(

msg = f"Pass {value} as a '{dtype}'{or_none}. Got {type(value)}."
raise TypeError(msg)


def _from_api_repr(cls, resource: dict):
"""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 = copy.deepcopy(resource)
return config
23 changes: 23 additions & 0 deletions google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class Table(_TableBase):
"mview_last_refresh_time": ["materializedView", "lastRefreshTime"],
"mview_query": "materializedView",
"mview_refresh_interval": "materializedView",
"mview_allow_non_incremental_definition": "materializedView",
"num_bytes": "numBytes",
"num_rows": "numRows",
"partition_expiration": "timePartitioning",
Expand Down Expand Up @@ -935,6 +936,28 @@ def mview_refresh_interval(self, value):
refresh_interval_ms,
)

@property
def mview_allow_non_incremental_definition(self):
"""Optional[bool]: This option declares the intention to construct a
materialized view that isn't refreshed incrementally.
The default value is :data:`False`.
"""
api_field = self._PROPERTY_TO_API_FIELD[
"mview_allow_non_incremental_definition"
]
return _helpers._get_sub_prop(
self._properties, [api_field, "allowNonIncrementalDefinition"]
)

@mview_allow_non_incremental_definition.setter
def mview_allow_non_incremental_definition(self, value):
api_field = self._PROPERTY_TO_API_FIELD[
"mview_allow_non_incremental_definition"
]
_helpers._set_sub_prop(
self._properties, [api_field, "allowNonIncrementalDefinition"], value
)

@property
def streaming_buffer(self):
"""google.cloud.bigquery.StreamingBuffer: Information about a table's
Expand Down
2 changes: 1 addition & 1 deletion samples/geography/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pandas==2.2.3; python_version >= '3.9'
proto-plus==1.25.0
pyarrow===12.0.1; python_version == '3.7'
pyarrow===17.0.0; python_version == '3.8'
pyarrow==18.0.0; python_version >= '3.9'
pyarrow==18.1.0; python_version >= '3.9'
pyasn1===0.5.1; python_version == '3.7'
pyasn1==0.6.1; python_version >= '3.8'
pyasn1-modules===0.3.0; python_version == '3.7'
Expand Down
25 changes: 2 additions & 23 deletions tests/unit/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import google.api_core
from google.cloud.bigquery._helpers import (
_isinstance_or_raise,
_from_api_repr,
)


Expand Down Expand Up @@ -1695,25 +1694,5 @@ def test__valid_isinstance_or_raise(self, value, dtype, none_allowed, expected):
],
)
def test__invalid_isinstance_or_raise(self, value, dtype, none_allowed, expected):
with expected as e:
result = _isinstance_or_raise(value, dtype, none_allowed=none_allowed)

assert result == e


class _MockClass:
def __init__(self):
self._properties = {}


@pytest.fixture
def mock_class():
return _MockClass


class Test__from_api_repr:
def test_from_api_repr(self, mock_class):
resource = {"foo": "bar", "baz": {"qux": 1}}
config = _from_api_repr(mock_class, resource)
assert config._properties == resource
assert config._properties is not resource
with expected:
_isinstance_or_raise(value, dtype, none_allowed=none_allowed)
14 changes: 6 additions & 8 deletions tests/unit/test_external_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,10 +930,8 @@ def test_ctor_initialization(
parameters=parameters,
)

assert instance._properties == {
"defaultStorageLocationUri": default_storage_location_uri,
"parameters": parameters,
}
assert instance.default_storage_location_uri == default_storage_location_uri
assert instance.parameters == parameters

def test_ctor_invalid_input(self):
"""Test ExternalCatalogDatasetOptions constructor with invalid input."""
Expand Down Expand Up @@ -1025,15 +1023,15 @@ def test_ctor_initialization(
storage_descriptor=storage_descriptor,
)

assert instance._properties["connectionId"] == connection_id
assert instance._properties["parameters"] == parameters
assert instance.connection_id == connection_id
assert instance.parameters == parameters
if storage_descriptor is not None:
assert (
instance._properties["storageDescriptor"]
instance.storage_descriptor.to_api_repr()
== storage_descriptor.to_api_repr()
)
else:
assert instance._properties["storageDescriptor"] == storage_descriptor
assert instance.storage_descriptor is None

@pytest.mark.parametrize(
"connection_id, parameters, storage_descriptor",
Expand Down
9 changes: 4 additions & 5 deletions tests/unit/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ def _make_one(self, *args, **kw):
def test_ctor_valid_input(self, type_system, expected):
result = self._make_one(type_system=type_system)

assert result._properties["typeSystem"] == expected
assert result.type_system == expected

def test_ctor_invalid_input(self):
with pytest.raises(TypeError) as e:
Expand Down Expand Up @@ -1444,7 +1444,6 @@ def test_ctor_valid_input(
assert storage_descriptor.input_format == input_format
assert storage_descriptor.location_uri == location_uri
assert storage_descriptor.output_format == output_format

if serde_info is not None:
assert (
storage_descriptor.serde_info.to_api_repr() == serde_info.to_api_repr()
Expand Down Expand Up @@ -1546,9 +1545,9 @@ def test_ctor_valid_input(self, serialization_library, name, parameters):
name=name,
parameters=parameters,
)
assert serde_info._properties["serializationLibrary"] == serialization_library
assert serde_info._properties["name"] == name
assert serde_info._properties["parameters"] == parameters
assert serde_info.serialization_library == serialization_library
assert serde_info.name == name
assert serde_info.parameters == parameters

@pytest.mark.parametrize(
"serialization_library,name,parameters",
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,16 @@ def test_mview_refresh_interval(self):
table.mview_refresh_interval = None
self.assertIsNone(table.mview_refresh_interval)

def test_mview_allow_non_incremental_definition(self):
table = self._make_one()
self.assertIsNone(table.mview_allow_non_incremental_definition)
table.mview_allow_non_incremental_definition = True
self.assertTrue(table.mview_allow_non_incremental_definition)
table.mview_allow_non_incremental_definition = False
self.assertFalse(table.mview_allow_non_incremental_definition)
table.mview_allow_non_incremental_definition = None
self.assertIsNone(table.mview_allow_non_incremental_definition)

def test_from_string(self):
cls = self._get_target_class()
got = cls.from_string("string-project.string_dataset.string_table")
Expand Down

0 comments on commit 7c08ca8

Please sign in to comment.