Skip to content

Commit ce368d9

Browse files
authored
Merge branch 'main' into b323176126-pandas-gbq
2 parents aff7021 + 9c50418 commit ce368d9

File tree

16 files changed

+1066
-13
lines changed

16 files changed

+1066
-13
lines changed

.github/.OwlBot.lock.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Google LLC
1+
# Copyright 2025 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -13,5 +13,5 @@
1313
# limitations under the License.
1414
docker:
1515
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
16-
digest: sha256:8e3e7e18255c22d1489258d0374c901c01f9c4fd77a12088670cd73d580aa737
17-
# created: 2024-12-17T00:59:58.625514486Z
16+
digest: sha256:8ff1efe878e18bd82a0fb7b70bb86f77e7ab6901fed394440b6135db0ba8d84a
17+
# created: 2025-01-09T12:01:16.422459506Z

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,34 @@
55
[1]: https://pypi.org/project/google-cloud-bigquery/#history
66

77

8+
## [3.28.0](https://github.com/googleapis/python-bigquery/compare/v3.27.0...v3.28.0) (2025-01-15)
9+
10+
11+
### Features
12+
13+
* Add property for `allowNonIncrementalDefinition` for materialized view ([#2084](https://github.com/googleapis/python-bigquery/issues/2084)) ([3359ef3](https://github.com/googleapis/python-bigquery/commit/3359ef37b90243bea2d9e68bb996fe5d736f304c))
14+
* Add property for maxStaleness in table definitions ([#2087](https://github.com/googleapis/python-bigquery/issues/2087)) ([729322c](https://github.com/googleapis/python-bigquery/commit/729322c2288a30464f2f135ba18b9c4aa7d2f0da))
15+
* Add type hints to Client ([#2044](https://github.com/googleapis/python-bigquery/issues/2044)) ([40529de](https://github.com/googleapis/python-bigquery/commit/40529de923e25c41c6728c121b9c82a042967ada))
16+
* Adds ExternalCatalogDatasetOptions and tests ([#2111](https://github.com/googleapis/python-bigquery/issues/2111)) ([b929a90](https://github.com/googleapis/python-bigquery/commit/b929a900d49e2c15897134209ed9de5fc7f238cd))
17+
* Adds ForeignTypeInfo class and tests ([#2110](https://github.com/googleapis/python-bigquery/issues/2110)) ([55ca63c](https://github.com/googleapis/python-bigquery/commit/55ca63c23fcb56573e2de67e4f7899939628c4a1))
18+
* Adds new input validation function similar to isinstance. ([#2107](https://github.com/googleapis/python-bigquery/issues/2107)) ([a2bebb9](https://github.com/googleapis/python-bigquery/commit/a2bebb95c5ef32ac7c7cbe19c3e7a9412cbee60d))
19+
* Adds StorageDescriptor and tests ([#2109](https://github.com/googleapis/python-bigquery/issues/2109)) ([6be0272](https://github.com/googleapis/python-bigquery/commit/6be0272ff25dac97a38ae4ee5aa02016dc82a0d8))
20+
* Adds the SerDeInfo class and tests ([#2108](https://github.com/googleapis/python-bigquery/issues/2108)) ([62960f2](https://github.com/googleapis/python-bigquery/commit/62960f255d05b15940a8d2cdc595592175fada11))
21+
* Migrate to pyproject.toml ([#2041](https://github.com/googleapis/python-bigquery/issues/2041)) ([1061611](https://github.com/googleapis/python-bigquery/commit/106161180ead01aca1ead909cf06ca559f68666d))
22+
* Preserve unknown fields from the REST API representation in `SchemaField` ([#2097](https://github.com/googleapis/python-bigquery/issues/2097)) ([aaf1eb8](https://github.com/googleapis/python-bigquery/commit/aaf1eb85ada95ab866be0199812ea7f5c7f50766))
23+
* Resource tags in dataset ([#2090](https://github.com/googleapis/python-bigquery/issues/2090)) ([3e13016](https://github.com/googleapis/python-bigquery/commit/3e130166f43dcc06704fe90edf9068dfd44842a6))
24+
* Support setting max_stream_count when fetching query result ([#2051](https://github.com/googleapis/python-bigquery/issues/2051)) ([d461297](https://github.com/googleapis/python-bigquery/commit/d4612979b812d2a835e47200f27a87a66bcb856a))
25+
26+
27+
### Bug Fixes
28+
29+
* Allow geopandas 1.x ([#2065](https://github.com/googleapis/python-bigquery/issues/2065)) ([f2ab8cb](https://github.com/googleapis/python-bigquery/commit/f2ab8cbfe00d442ad3b40683ecfec320e53b4688))
30+
31+
32+
### Documentation
33+
34+
* Render fields correctly for update calls ([#2055](https://github.com/googleapis/python-bigquery/issues/2055)) ([a4d9534](https://github.com/googleapis/python-bigquery/commit/a4d9534a900f13ae7355904cda05097d781f27e3))
35+
836
## [3.27.0](https://github.com/googleapis/python-bigquery/compare/v3.26.0...v3.27.0) (2024-11-01)
937

1038

google/cloud/bigquery/_helpers.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import re
2323
import os
2424
import warnings
25-
from typing import Optional, Union
25+
from typing import Optional, Union, Any, Tuple, Type
2626

2727
from dateutil import relativedelta
2828
from google.cloud._helpers import UTC # type: ignore
@@ -1004,3 +1004,33 @@ def _verify_job_config_type(job_config, expected_type, param_name="job_config"):
10041004
job_config=job_config,
10051005
)
10061006
)
1007+
1008+
1009+
def _isinstance_or_raise(
1010+
value: Any,
1011+
dtype: Union[Type, Tuple[Type, ...]],
1012+
none_allowed: Optional[bool] = False,
1013+
) -> Any:
1014+
"""Determine whether a value type matches a given datatype or None.
1015+
Args:
1016+
value (Any): Value to be checked.
1017+
dtype (type): Expected data type or tuple of data types.
1018+
none_allowed Optional(bool): whether value is allowed to be None. Default
1019+
is False.
1020+
Returns:
1021+
Any: Returns the input value if the type check is successful.
1022+
Raises:
1023+
TypeError: If the input value's type does not match the expected data type(s).
1024+
"""
1025+
if none_allowed and value is None:
1026+
return value
1027+
1028+
if isinstance(value, dtype):
1029+
return value
1030+
1031+
or_none = ""
1032+
if none_allowed:
1033+
or_none = " (or None)"
1034+
1035+
msg = f"Pass {value} as a '{dtype}'{or_none}. Got {type(value)}."
1036+
raise TypeError(msg)

google/cloud/bigquery/dataset.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from google.cloud.bigquery.routine import Routine, RoutineReference
2828
from google.cloud.bigquery.table import Table, TableReference
2929
from google.cloud.bigquery.encryption_configuration import EncryptionConfiguration
30+
from google.cloud.bigquery import external_config
3031

3132
from typing import Optional, List, Dict, Any, Union
3233

@@ -530,6 +531,8 @@ class Dataset(object):
530531
"storage_billing_model": "storageBillingModel",
531532
"max_time_travel_hours": "maxTimeTravelHours",
532533
"default_rounding_mode": "defaultRoundingMode",
534+
"resource_tags": "resourceTags",
535+
"external_catalog_dataset_options": "externalCatalogDatasetOptions",
533536
}
534537

535538
def __init__(self, dataset_ref) -> None:
@@ -801,6 +804,28 @@ def labels(self, value):
801804
raise ValueError("Pass a dict")
802805
self._properties["labels"] = value
803806

807+
@property
808+
def resource_tags(self):
809+
"""Dict[str, str]: Resource tags of the dataset.
810+
811+
Optional. The tags attached to this dataset. Tag keys are globally
812+
unique. Tag key is expected to be in the namespaced format, for
813+
example "123456789012/environment" where 123456789012 is
814+
the ID of the parent organization or project resource for this tag
815+
key. Tag value is expected to be the short name, for example
816+
"Production".
817+
818+
Raises:
819+
ValueError: for invalid value types.
820+
"""
821+
return self._properties.setdefault("resourceTags", {})
822+
823+
@resource_tags.setter
824+
def resource_tags(self, value):
825+
if not isinstance(value, dict) and value is not None:
826+
raise ValueError("Pass a dict")
827+
self._properties["resourceTags"] = value
828+
804829
@property
805830
def default_encryption_configuration(self):
806831
"""google.cloud.bigquery.encryption_configuration.EncryptionConfiguration: Custom
@@ -875,6 +900,29 @@ def storage_billing_model(self, value):
875900
)
876901
self._properties["storageBillingModel"] = value
877902

903+
@property
904+
def external_catalog_dataset_options(self):
905+
"""Options defining open source compatible datasets living in the
906+
BigQuery catalog. Contains metadata of open source database, schema
907+
or namespace represented by the current dataset."""
908+
909+
prop = _helpers._get_sub_prop(
910+
self._properties, ["externalCatalogDatasetOptions"]
911+
)
912+
913+
if prop is not None:
914+
prop = external_config.ExternalCatalogDatasetOptions.from_api_repr(prop)
915+
return prop
916+
917+
@external_catalog_dataset_options.setter
918+
def external_catalog_dataset_options(self, value):
919+
value = _helpers._isinstance_or_raise(
920+
value, external_config.ExternalCatalogDatasetOptions, none_allowed=True
921+
)
922+
self._properties[
923+
self._PROPERTY_TO_API_FIELD["external_catalog_dataset_options"]
924+
] = (value.to_api_repr() if value is not None else None)
925+
878926
@classmethod
879927
def from_string(cls, full_dataset_id: str) -> "Dataset":
880928
"""Construct a dataset from fully-qualified dataset ID.

google/cloud/bigquery/external_config.py

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Job.configuration.query.tableDefinitions.
1919
"""
2020

21-
from __future__ import absolute_import
21+
from __future__ import absolute_import, annotations
2222

2323
import base64
2424
import copy
@@ -28,6 +28,7 @@
2828
from google.cloud.bigquery._helpers import _bytes_to_json
2929
from google.cloud.bigquery._helpers import _int_or_none
3030
from google.cloud.bigquery._helpers import _str_or_none
31+
from google.cloud.bigquery import _helpers
3132
from google.cloud.bigquery.format_options import AvroOptions, ParquetOptions
3233
from google.cloud.bigquery.schema import SchemaField
3334

@@ -1003,3 +1004,76 @@ def from_api_repr(cls, resource: dict) -> "ExternalConfig":
10031004
config = cls(resource["sourceFormat"])
10041005
config._properties = copy.deepcopy(resource)
10051006
return config
1007+
1008+
1009+
class ExternalCatalogDatasetOptions:
1010+
"""Options defining open source compatible datasets living in the BigQuery catalog.
1011+
Contains metadata of open source database, schema or namespace represented
1012+
by the current dataset.
1013+
1014+
Args:
1015+
default_storage_location_uri (Optional[str]): The storage location URI for all
1016+
tables in the dataset. Equivalent to hive metastore's database
1017+
locationUri. Maximum length of 1024 characters. (str)
1018+
parameters (Optional[dict[str, Any]]): A map of key value pairs defining the parameters
1019+
and properties of the open source schema. Maximum size of 2Mib.
1020+
"""
1021+
1022+
def __init__(
1023+
self,
1024+
default_storage_location_uri: Optional[str] = None,
1025+
parameters: Optional[Dict[str, Any]] = None,
1026+
):
1027+
self._properties: Dict[str, Any] = {}
1028+
self.default_storage_location_uri = default_storage_location_uri
1029+
self.parameters = parameters
1030+
1031+
@property
1032+
def default_storage_location_uri(self) -> Optional[str]:
1033+
"""Optional. The storage location URI for all tables in the dataset.
1034+
Equivalent to hive metastore's database locationUri. Maximum length of
1035+
1024 characters."""
1036+
1037+
return self._properties.get("defaultStorageLocationUri")
1038+
1039+
@default_storage_location_uri.setter
1040+
def default_storage_location_uri(self, value: Optional[str]):
1041+
value = _helpers._isinstance_or_raise(value, str, none_allowed=True)
1042+
self._properties["defaultStorageLocationUri"] = value
1043+
1044+
@property
1045+
def parameters(self) -> Optional[Dict[str, Any]]:
1046+
"""Optional. A map of key value pairs defining the parameters and
1047+
properties of the open source schema. Maximum size of 2Mib."""
1048+
1049+
return self._properties.get("parameters")
1050+
1051+
@parameters.setter
1052+
def parameters(self, value: Optional[Dict[str, Any]]):
1053+
value = _helpers._isinstance_or_raise(value, dict, none_allowed=True)
1054+
self._properties["parameters"] = value
1055+
1056+
def to_api_repr(self) -> dict:
1057+
"""Build an API representation of this object.
1058+
1059+
Returns:
1060+
Dict[str, Any]:
1061+
A dictionary in the format used by the BigQuery API.
1062+
"""
1063+
return self._properties
1064+
1065+
@classmethod
1066+
def from_api_repr(cls, api_repr: dict) -> ExternalCatalogDatasetOptions:
1067+
"""Factory: constructs an instance of the class (cls)
1068+
given its API representation.
1069+
1070+
Args:
1071+
api_repr (Dict[str, Any]):
1072+
API representation of the object to be instantiated.
1073+
1074+
Returns:
1075+
An instance of the class initialized with data from 'resource'.
1076+
"""
1077+
config = cls()
1078+
config._properties = api_repr
1079+
return config

0 commit comments

Comments
 (0)