Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/aiplatform_v1/services/dataset_service/transports/__pycache__/__init__.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/aiplatform_v1/services/dataset_service/transports/__pycache__/base.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/aiplatform_v1/services/dataset_service/transports/__pycache__/grpc_asyncio.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/__init__.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_helpers.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_http.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_job_helpers.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_pandas_helpers.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_pyarrow_helpers.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_tqdm_helpers.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_versions_helpers.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/dataset.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/encryption_configuration.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/enums.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/exceptions.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/external_config.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/format_options.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/iam.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/model.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/opentelemetry_tracing.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/query.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/retry.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/schema.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/standard_sql.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/version.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__init__.py +87 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__pycache__/__init__.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__pycache__/_helpers.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__pycache__/connection.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__pycache__/cursor.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__pycache__/exceptions.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__pycache__/types.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/_helpers.py +522 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/connection.py +128 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/cursor.py +589 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/exceptions.py +58 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/types.py +96 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/__init__.py +89 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/__pycache__/__init__.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/__pycache__/base.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/__pycache__/copy_.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/__pycache__/extract.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/__pycache__/load.cpython-311.pyc +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/base.py +1192 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/copy_.py +282 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/extract.py +271 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/load.py +1185 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/query.py +0 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/magics/__init__.py +20 -0
- data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/magics/__pycache__/__init__.cpython-311.pyc +0 -0
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/aiplatform_v1/services/dataset_service/transports/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (1.44 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/aiplatform_v1/services/dataset_service/transports/__pycache__/base.cpython-311.pyc
ADDED
|
Binary file (22.7 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/aiplatform_v1/services/dataset_service/transports/__pycache__/grpc_asyncio.cpython-311.pyc
ADDED
|
Binary file (49.3 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (8 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_helpers.cpython-311.pyc
ADDED
|
Binary file (46.3 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_http.cpython-311.pyc
ADDED
|
Binary file (2.04 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_job_helpers.cpython-311.pyc
ADDED
|
Binary file (26.9 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_pandas_helpers.cpython-311.pyc
ADDED
|
Binary file (47.7 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_pyarrow_helpers.cpython-311.pyc
ADDED
|
Binary file (5.27 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_tqdm_helpers.cpython-311.pyc
ADDED
|
Binary file (4.87 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/_versions_helpers.cpython-311.pyc
ADDED
|
Binary file (10.4 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/dataset.cpython-311.pyc
ADDED
|
Binary file (62.3 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/encryption_configuration.cpython-311.pyc
ADDED
|
Binary file (3.8 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/enums.cpython-311.pyc
ADDED
|
Binary file (14.7 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/exceptions.cpython-311.pyc
ADDED
|
Binary file (1.77 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/external_config.cpython-311.pyc
ADDED
|
Binary file (64.2 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/format_options.cpython-311.pyc
ADDED
|
Binary file (6.74 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/iam.cpython-311.pyc
ADDED
|
Binary file (654 Bytes). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/model.cpython-311.pyc
ADDED
|
Binary file (24.2 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/opentelemetry_tracing.cpython-311.pyc
ADDED
|
Binary file (6.59 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/query.cpython-311.pyc
ADDED
|
Binary file (62.8 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/retry.cpython-311.pyc
ADDED
|
Binary file (4.67 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/schema.cpython-311.pyc
ADDED
|
Binary file (42.8 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/standard_sql.cpython-311.pyc
ADDED
|
Binary file (19.3 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/__pycache__/version.cpython-311.pyc
ADDED
|
Binary file (231 Bytes). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__init__.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Google BigQuery implementation of the Database API Specification v2.0.
|
| 16 |
+
|
| 17 |
+
This module implements the `Python Database API Specification v2.0 (DB-API)`_
|
| 18 |
+
for Google BigQuery.
|
| 19 |
+
|
| 20 |
+
.. _Python Database API Specification v2.0 (DB-API):
|
| 21 |
+
https://www.python.org/dev/peps/pep-0249/
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
from google.cloud.bigquery.dbapi.connection import connect
|
| 25 |
+
from google.cloud.bigquery.dbapi.connection import Connection
|
| 26 |
+
from google.cloud.bigquery.dbapi.cursor import Cursor
|
| 27 |
+
from google.cloud.bigquery.dbapi.exceptions import Warning
|
| 28 |
+
from google.cloud.bigquery.dbapi.exceptions import Error
|
| 29 |
+
from google.cloud.bigquery.dbapi.exceptions import InterfaceError
|
| 30 |
+
from google.cloud.bigquery.dbapi.exceptions import DatabaseError
|
| 31 |
+
from google.cloud.bigquery.dbapi.exceptions import DataError
|
| 32 |
+
from google.cloud.bigquery.dbapi.exceptions import OperationalError
|
| 33 |
+
from google.cloud.bigquery.dbapi.exceptions import IntegrityError
|
| 34 |
+
from google.cloud.bigquery.dbapi.exceptions import InternalError
|
| 35 |
+
from google.cloud.bigquery.dbapi.exceptions import ProgrammingError
|
| 36 |
+
from google.cloud.bigquery.dbapi.exceptions import NotSupportedError
|
| 37 |
+
from google.cloud.bigquery.dbapi.types import Binary
|
| 38 |
+
from google.cloud.bigquery.dbapi.types import Date
|
| 39 |
+
from google.cloud.bigquery.dbapi.types import DateFromTicks
|
| 40 |
+
from google.cloud.bigquery.dbapi.types import Time
|
| 41 |
+
from google.cloud.bigquery.dbapi.types import TimeFromTicks
|
| 42 |
+
from google.cloud.bigquery.dbapi.types import Timestamp
|
| 43 |
+
from google.cloud.bigquery.dbapi.types import TimestampFromTicks
|
| 44 |
+
from google.cloud.bigquery.dbapi.types import BINARY
|
| 45 |
+
from google.cloud.bigquery.dbapi.types import DATETIME
|
| 46 |
+
from google.cloud.bigquery.dbapi.types import NUMBER
|
| 47 |
+
from google.cloud.bigquery.dbapi.types import ROWID
|
| 48 |
+
from google.cloud.bigquery.dbapi.types import STRING
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
apilevel = "2.0"
|
| 52 |
+
|
| 53 |
+
# Threads may share the module and connections, but not cursors.
|
| 54 |
+
threadsafety = 2
|
| 55 |
+
|
| 56 |
+
paramstyle = "pyformat"
|
| 57 |
+
|
| 58 |
+
__all__ = [
|
| 59 |
+
"apilevel",
|
| 60 |
+
"threadsafety",
|
| 61 |
+
"paramstyle",
|
| 62 |
+
"connect",
|
| 63 |
+
"Connection",
|
| 64 |
+
"Cursor",
|
| 65 |
+
"Warning",
|
| 66 |
+
"Error",
|
| 67 |
+
"InterfaceError",
|
| 68 |
+
"DatabaseError",
|
| 69 |
+
"DataError",
|
| 70 |
+
"OperationalError",
|
| 71 |
+
"IntegrityError",
|
| 72 |
+
"InternalError",
|
| 73 |
+
"ProgrammingError",
|
| 74 |
+
"NotSupportedError",
|
| 75 |
+
"Binary",
|
| 76 |
+
"Date",
|
| 77 |
+
"DateFromTicks",
|
| 78 |
+
"Time",
|
| 79 |
+
"TimeFromTicks",
|
| 80 |
+
"Timestamp",
|
| 81 |
+
"TimestampFromTicks",
|
| 82 |
+
"BINARY",
|
| 83 |
+
"DATETIME",
|
| 84 |
+
"NUMBER",
|
| 85 |
+
"ROWID",
|
| 86 |
+
"STRING",
|
| 87 |
+
]
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (2.15 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__pycache__/_helpers.cpython-311.pyc
ADDED
|
Binary file (21.6 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__pycache__/connection.cpython-311.pyc
ADDED
|
Binary file (5.18 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__pycache__/cursor.cpython-311.pyc
ADDED
|
Binary file (21.5 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__pycache__/exceptions.cpython-311.pyc
ADDED
|
Binary file (3 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/__pycache__/types.cpython-311.pyc
ADDED
|
Binary file (3.34 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/_helpers.py
ADDED
|
@@ -0,0 +1,522 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
from collections import abc as collections_abc
|
| 17 |
+
import datetime
|
| 18 |
+
import decimal
|
| 19 |
+
import functools
|
| 20 |
+
import numbers
|
| 21 |
+
import re
|
| 22 |
+
import typing
|
| 23 |
+
|
| 24 |
+
from google.cloud import bigquery
|
| 25 |
+
from google.cloud.bigquery import table, query
|
| 26 |
+
from google.cloud.bigquery.dbapi import exceptions
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
_NUMERIC_SERVER_MIN = decimal.Decimal("-9.9999999999999999999999999999999999999E+28")
|
| 30 |
+
_NUMERIC_SERVER_MAX = decimal.Decimal("9.9999999999999999999999999999999999999E+28")
|
| 31 |
+
|
| 32 |
+
type_parameters_re = re.compile(
|
| 33 |
+
r"""
|
| 34 |
+
\(
|
| 35 |
+
\s*[0-9]+\s*
|
| 36 |
+
(,
|
| 37 |
+
\s*[0-9]+\s*
|
| 38 |
+
)*
|
| 39 |
+
\)
|
| 40 |
+
""",
|
| 41 |
+
re.VERBOSE,
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def _parameter_type(name, value, query_parameter_type=None, value_doc=""):
|
| 46 |
+
if query_parameter_type:
|
| 47 |
+
# Strip type parameters
|
| 48 |
+
query_parameter_type = type_parameters_re.sub("", query_parameter_type)
|
| 49 |
+
try:
|
| 50 |
+
parameter_type = getattr(
|
| 51 |
+
query.SqlParameterScalarTypes, query_parameter_type.upper()
|
| 52 |
+
)._type
|
| 53 |
+
except AttributeError:
|
| 54 |
+
raise exceptions.ProgrammingError(
|
| 55 |
+
f"The given parameter type, {query_parameter_type},"
|
| 56 |
+
f" for {name} is not a valid BigQuery scalar type."
|
| 57 |
+
)
|
| 58 |
+
else:
|
| 59 |
+
parameter_type = bigquery_scalar_type(value)
|
| 60 |
+
if parameter_type is None:
|
| 61 |
+
raise exceptions.ProgrammingError(
|
| 62 |
+
f"Encountered parameter {name} with "
|
| 63 |
+
f"{value_doc} value {value} of unexpected type."
|
| 64 |
+
)
|
| 65 |
+
return parameter_type
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def scalar_to_query_parameter(value, name=None, query_parameter_type=None):
|
| 69 |
+
"""Convert a scalar value into a query parameter.
|
| 70 |
+
|
| 71 |
+
Args:
|
| 72 |
+
value (Any):
|
| 73 |
+
A scalar value to convert into a query parameter.
|
| 74 |
+
|
| 75 |
+
name (str):
|
| 76 |
+
(Optional) Name of the query parameter.
|
| 77 |
+
query_parameter_type (Optional[str]): Given type for the parameter.
|
| 78 |
+
|
| 79 |
+
Returns:
|
| 80 |
+
google.cloud.bigquery.ScalarQueryParameter:
|
| 81 |
+
A query parameter corresponding with the type and value of the plain
|
| 82 |
+
Python object.
|
| 83 |
+
|
| 84 |
+
Raises:
|
| 85 |
+
google.cloud.bigquery.dbapi.exceptions.ProgrammingError:
|
| 86 |
+
if the type cannot be determined.
|
| 87 |
+
"""
|
| 88 |
+
return bigquery.ScalarQueryParameter(
|
| 89 |
+
name, _parameter_type(name, value, query_parameter_type), value
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def array_to_query_parameter(value, name=None, query_parameter_type=None):
|
| 94 |
+
"""Convert an array-like value into a query parameter.
|
| 95 |
+
|
| 96 |
+
Args:
|
| 97 |
+
value (Sequence[Any]): The elements of the array (should not be a
|
| 98 |
+
string-like Sequence).
|
| 99 |
+
name (Optional[str]): Name of the query parameter.
|
| 100 |
+
query_parameter_type (Optional[str]): Given type for the parameter.
|
| 101 |
+
|
| 102 |
+
Returns:
|
| 103 |
+
A query parameter corresponding with the type and value of the plain
|
| 104 |
+
Python object.
|
| 105 |
+
|
| 106 |
+
Raises:
|
| 107 |
+
google.cloud.bigquery.dbapi.exceptions.ProgrammingError:
|
| 108 |
+
if the type of array elements cannot be determined.
|
| 109 |
+
"""
|
| 110 |
+
if not array_like(value):
|
| 111 |
+
raise exceptions.ProgrammingError(
|
| 112 |
+
"The value of parameter {} must be a sequence that is "
|
| 113 |
+
"not string-like.".format(name)
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
if query_parameter_type or value:
|
| 117 |
+
array_type = _parameter_type(
|
| 118 |
+
name,
|
| 119 |
+
value[0] if value else None,
|
| 120 |
+
query_parameter_type,
|
| 121 |
+
value_doc="array element ",
|
| 122 |
+
)
|
| 123 |
+
else:
|
| 124 |
+
raise exceptions.ProgrammingError(
|
| 125 |
+
"Encountered an empty array-like value of parameter {}, cannot "
|
| 126 |
+
"determine array elements type.".format(name)
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
return bigquery.ArrayQueryParameter(name, array_type, value)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def _parse_struct_fields(
|
| 133 |
+
fields,
|
| 134 |
+
base,
|
| 135 |
+
parse_struct_field=re.compile(
|
| 136 |
+
r"""
|
| 137 |
+
(?:(\w+)\s+) # field name
|
| 138 |
+
([A-Z0-9<> ,()]+) # Field type
|
| 139 |
+
$""",
|
| 140 |
+
re.VERBOSE | re.IGNORECASE,
|
| 141 |
+
).match,
|
| 142 |
+
):
|
| 143 |
+
# Split a string of struct fields. They're defined by commas, but
|
| 144 |
+
# we have to avoid splitting on commas internal to fields. For
|
| 145 |
+
# example:
|
| 146 |
+
# name string, children array<struct<name string, bdate date>>
|
| 147 |
+
#
|
| 148 |
+
# only has 2 top-level fields.
|
| 149 |
+
fields = fields.split(",")
|
| 150 |
+
fields = list(reversed(fields)) # in the off chance that there are very many
|
| 151 |
+
while fields:
|
| 152 |
+
field = fields.pop()
|
| 153 |
+
while fields and field.count("<") != field.count(">"):
|
| 154 |
+
field += "," + fields.pop()
|
| 155 |
+
|
| 156 |
+
m = parse_struct_field(field.strip())
|
| 157 |
+
if not m:
|
| 158 |
+
raise exceptions.ProgrammingError(
|
| 159 |
+
f"Invalid struct field, {field}, in {base}"
|
| 160 |
+
)
|
| 161 |
+
yield m.group(1, 2)
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
SCALAR, ARRAY, STRUCT = ("s", "a", "r")
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def _parse_type(
|
| 168 |
+
type_,
|
| 169 |
+
name,
|
| 170 |
+
base,
|
| 171 |
+
complex_query_parameter_parse=re.compile(
|
| 172 |
+
r"""
|
| 173 |
+
\s*
|
| 174 |
+
(ARRAY|STRUCT|RECORD) # Type
|
| 175 |
+
\s*
|
| 176 |
+
<([A-Z0-9_<> ,()]+)> # Subtype(s)
|
| 177 |
+
\s*$
|
| 178 |
+
""",
|
| 179 |
+
re.IGNORECASE | re.VERBOSE,
|
| 180 |
+
).match,
|
| 181 |
+
):
|
| 182 |
+
if "<" not in type_:
|
| 183 |
+
# Scalar
|
| 184 |
+
|
| 185 |
+
# Strip type parameters
|
| 186 |
+
type_ = type_parameters_re.sub("", type_).strip()
|
| 187 |
+
try:
|
| 188 |
+
type_ = getattr(query.SqlParameterScalarTypes, type_.upper())
|
| 189 |
+
except AttributeError:
|
| 190 |
+
raise exceptions.ProgrammingError(
|
| 191 |
+
f"The given parameter type, {type_},"
|
| 192 |
+
f"{' for ' + name if name else ''}"
|
| 193 |
+
f" is not a valid BigQuery scalar type, in {base}."
|
| 194 |
+
)
|
| 195 |
+
if name:
|
| 196 |
+
type_ = type_.with_name(name)
|
| 197 |
+
return SCALAR, type_
|
| 198 |
+
|
| 199 |
+
m = complex_query_parameter_parse(type_)
|
| 200 |
+
if not m:
|
| 201 |
+
raise exceptions.ProgrammingError(f"Invalid parameter type, {type_}")
|
| 202 |
+
tname, sub = m.group(1, 2)
|
| 203 |
+
if tname.upper() == "ARRAY":
|
| 204 |
+
sub_type = complex_query_parameter_type(None, sub, base)
|
| 205 |
+
if isinstance(sub_type, query.ArrayQueryParameterType):
|
| 206 |
+
raise exceptions.ProgrammingError(f"Array can't contain an array in {base}")
|
| 207 |
+
sub_type._complex__src = sub
|
| 208 |
+
return ARRAY, sub_type
|
| 209 |
+
else:
|
| 210 |
+
return STRUCT, _parse_struct_fields(sub, base)
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def complex_query_parameter_type(name: typing.Optional[str], type_: str, base: str):
|
| 214 |
+
"""Construct a parameter type (`StructQueryParameterType`) for a complex type
|
| 215 |
+
|
| 216 |
+
or a non-complex type that's part of a complex type.
|
| 217 |
+
|
| 218 |
+
Examples:
|
| 219 |
+
|
| 220 |
+
array<struct<x float64, y float64>>
|
| 221 |
+
|
| 222 |
+
struct<name string, children array<struct<name string, bdate date>>>
|
| 223 |
+
|
| 224 |
+
This is used for computing array types.
|
| 225 |
+
"""
|
| 226 |
+
|
| 227 |
+
type_type, sub_type = _parse_type(type_, name, base)
|
| 228 |
+
if type_type == SCALAR:
|
| 229 |
+
result_type = sub_type
|
| 230 |
+
elif type_type == ARRAY:
|
| 231 |
+
result_type = query.ArrayQueryParameterType(sub_type, name=name)
|
| 232 |
+
elif type_type == STRUCT:
|
| 233 |
+
fields = [
|
| 234 |
+
complex_query_parameter_type(field_name, field_type, base)
|
| 235 |
+
for field_name, field_type in sub_type
|
| 236 |
+
]
|
| 237 |
+
result_type = query.StructQueryParameterType(*fields, name=name)
|
| 238 |
+
else: # pragma: NO COVER
|
| 239 |
+
raise AssertionError("Bad type_type", type_type) # Can't happen :)
|
| 240 |
+
|
| 241 |
+
return result_type
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def complex_query_parameter(
|
| 245 |
+
name: typing.Optional[str], value, type_: str, base: typing.Optional[str] = None
|
| 246 |
+
):
|
| 247 |
+
"""
|
| 248 |
+
Construct a query parameter for a complex type (array or struct record)
|
| 249 |
+
|
| 250 |
+
or for a subtype, which may not be complex
|
| 251 |
+
|
| 252 |
+
Examples:
|
| 253 |
+
|
| 254 |
+
array<struct<x float64, y float64>>
|
| 255 |
+
|
| 256 |
+
struct<name string, children array<struct<name string, bdate date>>>
|
| 257 |
+
|
| 258 |
+
"""
|
| 259 |
+
param: typing.Union[
|
| 260 |
+
query.ScalarQueryParameter,
|
| 261 |
+
query.ArrayQueryParameter,
|
| 262 |
+
query.StructQueryParameter,
|
| 263 |
+
]
|
| 264 |
+
|
| 265 |
+
base = base or type_
|
| 266 |
+
|
| 267 |
+
type_type, sub_type = _parse_type(type_, name, base)
|
| 268 |
+
|
| 269 |
+
if type_type == SCALAR:
|
| 270 |
+
param = query.ScalarQueryParameter(name, sub_type._type, value)
|
| 271 |
+
elif type_type == ARRAY:
|
| 272 |
+
if not array_like(value):
|
| 273 |
+
raise exceptions.ProgrammingError(
|
| 274 |
+
f"Array type with non-array-like value"
|
| 275 |
+
f" with type {type(value).__name__}"
|
| 276 |
+
)
|
| 277 |
+
param = query.ArrayQueryParameter(
|
| 278 |
+
name,
|
| 279 |
+
sub_type,
|
| 280 |
+
(
|
| 281 |
+
value
|
| 282 |
+
if isinstance(sub_type, query.ScalarQueryParameterType)
|
| 283 |
+
else [
|
| 284 |
+
complex_query_parameter(None, v, sub_type._complex__src, base)
|
| 285 |
+
for v in value
|
| 286 |
+
]
|
| 287 |
+
),
|
| 288 |
+
)
|
| 289 |
+
elif type_type == STRUCT:
|
| 290 |
+
if not isinstance(value, collections_abc.Mapping):
|
| 291 |
+
raise exceptions.ProgrammingError(f"Non-mapping value for type {type_}")
|
| 292 |
+
value_keys = set(value)
|
| 293 |
+
fields = []
|
| 294 |
+
for field_name, field_type in sub_type:
|
| 295 |
+
if field_name not in value:
|
| 296 |
+
raise exceptions.ProgrammingError(
|
| 297 |
+
f"No field value for {field_name} in {type_}"
|
| 298 |
+
)
|
| 299 |
+
value_keys.remove(field_name)
|
| 300 |
+
fields.append(
|
| 301 |
+
complex_query_parameter(field_name, value[field_name], field_type, base)
|
| 302 |
+
)
|
| 303 |
+
if value_keys:
|
| 304 |
+
raise exceptions.ProgrammingError(f"Extra data keys for {type_}")
|
| 305 |
+
|
| 306 |
+
param = query.StructQueryParameter(name, *fields)
|
| 307 |
+
else: # pragma: NO COVER
|
| 308 |
+
raise AssertionError("Bad type_type", type_type) # Can't happen :)
|
| 309 |
+
|
| 310 |
+
return param
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
def _dispatch_parameter(type_, value, name=None):
|
| 314 |
+
if type_ is not None and "<" in type_:
|
| 315 |
+
param = complex_query_parameter(name, value, type_)
|
| 316 |
+
elif isinstance(value, collections_abc.Mapping):
|
| 317 |
+
raise NotImplementedError(
|
| 318 |
+
f"STRUCT-like parameter values are not supported"
|
| 319 |
+
f"{' (parameter ' + name + ')' if name else ''},"
|
| 320 |
+
f" unless an explicit type is give in the parameter placeholder"
|
| 321 |
+
f" (e.g. '%({name if name else ''}:struct<...>)s')."
|
| 322 |
+
)
|
| 323 |
+
elif array_like(value):
|
| 324 |
+
param = array_to_query_parameter(value, name, type_)
|
| 325 |
+
else:
|
| 326 |
+
param = scalar_to_query_parameter(value, name, type_)
|
| 327 |
+
|
| 328 |
+
return param
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def to_query_parameters_list(parameters, parameter_types):
|
| 332 |
+
"""Converts a sequence of parameter values into query parameters.
|
| 333 |
+
|
| 334 |
+
Args:
|
| 335 |
+
parameters (Sequence[Any]): Sequence of query parameter values.
|
| 336 |
+
parameter_types:
|
| 337 |
+
A list of parameter types, one for each parameter.
|
| 338 |
+
Unknown types are provided as None.
|
| 339 |
+
|
| 340 |
+
Returns:
|
| 341 |
+
List[google.cloud.bigquery.query._AbstractQueryParameter]:
|
| 342 |
+
A list of query parameters.
|
| 343 |
+
"""
|
| 344 |
+
return [
|
| 345 |
+
_dispatch_parameter(type_, value)
|
| 346 |
+
for value, type_ in zip(parameters, parameter_types)
|
| 347 |
+
]
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
def to_query_parameters_dict(parameters, query_parameter_types):
|
| 351 |
+
"""Converts a dictionary of parameter values into query parameters.
|
| 352 |
+
|
| 353 |
+
Args:
|
| 354 |
+
parameters (Mapping[str, Any]): Dictionary of query parameter values.
|
| 355 |
+
parameter_types:
|
| 356 |
+
A dictionary of parameter types. It needn't have a key for each
|
| 357 |
+
parameter.
|
| 358 |
+
|
| 359 |
+
Returns:
|
| 360 |
+
List[google.cloud.bigquery.query._AbstractQueryParameter]:
|
| 361 |
+
A list of named query parameters.
|
| 362 |
+
"""
|
| 363 |
+
return [
|
| 364 |
+
_dispatch_parameter(query_parameter_types.get(name), value, name)
|
| 365 |
+
for name, value in parameters.items()
|
| 366 |
+
]
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
def to_query_parameters(parameters, parameter_types):
|
| 370 |
+
"""Converts DB-API parameter values into query parameters.
|
| 371 |
+
|
| 372 |
+
Args:
|
| 373 |
+
parameters (Union[Mapping[str, Any], Sequence[Any]]):
|
| 374 |
+
A dictionary or sequence of query parameter values.
|
| 375 |
+
parameter_types (Union[Mapping[str, str], Sequence[str]]):
|
| 376 |
+
A dictionary or list of parameter types.
|
| 377 |
+
|
| 378 |
+
If parameters is a mapping, then this must be a dictionary
|
| 379 |
+
of parameter types. It needn't have a key for each
|
| 380 |
+
parameter.
|
| 381 |
+
|
| 382 |
+
If parameters is a sequence, then this must be a list of
|
| 383 |
+
parameter types, one for each paramater. Unknown types
|
| 384 |
+
are provided as None.
|
| 385 |
+
|
| 386 |
+
Returns:
|
| 387 |
+
List[google.cloud.bigquery.query._AbstractQueryParameter]:
|
| 388 |
+
A list of query parameters.
|
| 389 |
+
"""
|
| 390 |
+
if parameters is None:
|
| 391 |
+
return []
|
| 392 |
+
|
| 393 |
+
if isinstance(parameters, collections_abc.Mapping):
|
| 394 |
+
return to_query_parameters_dict(parameters, parameter_types)
|
| 395 |
+
else:
|
| 396 |
+
return to_query_parameters_list(parameters, parameter_types)
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
def bigquery_scalar_type(value):
|
| 400 |
+
"""Return a BigQuery name of the scalar type that matches the given value.
|
| 401 |
+
|
| 402 |
+
If the scalar type name could not be determined (e.g. for non-scalar
|
| 403 |
+
values), ``None`` is returned.
|
| 404 |
+
|
| 405 |
+
Args:
|
| 406 |
+
value (Any)
|
| 407 |
+
|
| 408 |
+
Returns:
|
| 409 |
+
Optional[str]: The BigQuery scalar type name.
|
| 410 |
+
"""
|
| 411 |
+
if isinstance(value, bool):
|
| 412 |
+
return "BOOL"
|
| 413 |
+
elif isinstance(value, numbers.Integral):
|
| 414 |
+
return "INT64"
|
| 415 |
+
elif isinstance(value, numbers.Real):
|
| 416 |
+
return "FLOAT64"
|
| 417 |
+
elif isinstance(value, decimal.Decimal):
|
| 418 |
+
vtuple = value.as_tuple()
|
| 419 |
+
# NUMERIC values have precision of 38 (number of digits) and scale of 9 (number
|
| 420 |
+
# of fractional digits), and their max absolute value must be strictly smaller
|
| 421 |
+
# than 1.0E+29.
|
| 422 |
+
# https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#decimal_types
|
| 423 |
+
if (
|
| 424 |
+
len(vtuple.digits) <= 38 # max precision: 38
|
| 425 |
+
and vtuple.exponent >= -9 # max scale: 9
|
| 426 |
+
and _NUMERIC_SERVER_MIN <= value <= _NUMERIC_SERVER_MAX
|
| 427 |
+
):
|
| 428 |
+
return "NUMERIC"
|
| 429 |
+
else:
|
| 430 |
+
return "BIGNUMERIC"
|
| 431 |
+
|
| 432 |
+
elif isinstance(value, str):
|
| 433 |
+
return "STRING"
|
| 434 |
+
elif isinstance(value, bytes):
|
| 435 |
+
return "BYTES"
|
| 436 |
+
elif isinstance(value, datetime.datetime):
|
| 437 |
+
return "DATETIME" if value.tzinfo is None else "TIMESTAMP"
|
| 438 |
+
elif isinstance(value, datetime.date):
|
| 439 |
+
return "DATE"
|
| 440 |
+
elif isinstance(value, datetime.time):
|
| 441 |
+
return "TIME"
|
| 442 |
+
|
| 443 |
+
return None
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
def array_like(value):
|
| 447 |
+
"""Determine if the given value is array-like.
|
| 448 |
+
|
| 449 |
+
Examples of array-like values (as interpreted by this function) are
|
| 450 |
+
sequences such as ``list`` and ``tuple``, but not strings and other
|
| 451 |
+
iterables such as sets.
|
| 452 |
+
|
| 453 |
+
Args:
|
| 454 |
+
value (Any)
|
| 455 |
+
|
| 456 |
+
Returns:
|
| 457 |
+
bool: ``True`` if the value is considered array-like, ``False`` otherwise.
|
| 458 |
+
"""
|
| 459 |
+
return isinstance(value, collections_abc.Sequence) and not isinstance(
|
| 460 |
+
value, (str, bytes, bytearray)
|
| 461 |
+
)
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
def to_bq_table_rows(rows_iterable):
|
| 465 |
+
"""Convert table rows to BigQuery table Row instances.
|
| 466 |
+
|
| 467 |
+
Args:
|
| 468 |
+
rows_iterable (Iterable[Mapping]):
|
| 469 |
+
An iterable of row data items to convert to ``Row`` instances.
|
| 470 |
+
|
| 471 |
+
Returns:
|
| 472 |
+
Iterable[google.cloud.bigquery.table.Row]
|
| 473 |
+
"""
|
| 474 |
+
|
| 475 |
+
def to_table_row(row):
|
| 476 |
+
# NOTE: We fetch ARROW values, thus we need to convert them to Python
|
| 477 |
+
# objects with as_py().
|
| 478 |
+
values = tuple(value.as_py() for value in row.values())
|
| 479 |
+
keys_to_index = {key: i for i, key in enumerate(row.keys())}
|
| 480 |
+
return table.Row(values, keys_to_index)
|
| 481 |
+
|
| 482 |
+
return (to_table_row(row_data) for row_data in rows_iterable)
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
def raise_on_closed(
|
| 486 |
+
exc_msg, exc_class=exceptions.ProgrammingError, closed_attr_name="_closed"
|
| 487 |
+
):
|
| 488 |
+
"""Make public instance methods raise an error if the instance is closed."""
|
| 489 |
+
|
| 490 |
+
def _raise_on_closed(method):
|
| 491 |
+
"""Make a non-static method raise an error if its containing instance is closed."""
|
| 492 |
+
|
| 493 |
+
def with_closed_check(self, *args, **kwargs):
|
| 494 |
+
if getattr(self, closed_attr_name):
|
| 495 |
+
raise exc_class(exc_msg)
|
| 496 |
+
return method(self, *args, **kwargs)
|
| 497 |
+
|
| 498 |
+
functools.update_wrapper(with_closed_check, method)
|
| 499 |
+
return with_closed_check
|
| 500 |
+
|
| 501 |
+
def decorate_public_methods(klass):
|
| 502 |
+
"""Apply ``_raise_on_closed()`` decorator to public instance methods."""
|
| 503 |
+
for name in dir(klass):
|
| 504 |
+
if name.startswith("_") and name != "__iter__":
|
| 505 |
+
continue
|
| 506 |
+
|
| 507 |
+
member = getattr(klass, name)
|
| 508 |
+
if not callable(member):
|
| 509 |
+
continue
|
| 510 |
+
|
| 511 |
+
# We need to check for class/static methods directly in the instance
|
| 512 |
+
# __dict__, not via the retrieved attribute (`member`), as the
|
| 513 |
+
# latter is already a callable *produced* by one of these descriptors.
|
| 514 |
+
if isinstance(klass.__dict__[name], (staticmethod, classmethod)):
|
| 515 |
+
continue
|
| 516 |
+
|
| 517 |
+
member = _raise_on_closed(member)
|
| 518 |
+
setattr(klass, name, member)
|
| 519 |
+
|
| 520 |
+
return klass
|
| 521 |
+
|
| 522 |
+
return decorate_public_methods
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/connection.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Connection for the Google BigQuery DB-API."""
|
| 16 |
+
|
| 17 |
+
import weakref
|
| 18 |
+
|
| 19 |
+
from google.cloud import bigquery
|
| 20 |
+
from google.cloud.bigquery.dbapi import cursor
|
| 21 |
+
from google.cloud.bigquery.dbapi import _helpers
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@_helpers.raise_on_closed("Operating on a closed connection.")
|
| 25 |
+
class Connection(object):
|
| 26 |
+
"""DB-API Connection to Google BigQuery.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
client (Optional[google.cloud.bigquery.Client]):
|
| 30 |
+
A REST API client used to connect to BigQuery. If not passed, a
|
| 31 |
+
client is created using default options inferred from the environment.
|
| 32 |
+
bqstorage_client(\
|
| 33 |
+
Optional[google.cloud.bigquery_storage_v1.BigQueryReadClient] \
|
| 34 |
+
):
|
| 35 |
+
A client that uses the faster BigQuery Storage API to fetch rows from
|
| 36 |
+
BigQuery. If not passed, it is created using the same credentials
|
| 37 |
+
as ``client`` (provided that BigQuery Storage dependencies are installed).
|
| 38 |
+
prefer_bqstorage_client (Optional[bool]):
|
| 39 |
+
Prefer the BigQuery Storage client over the REST client. If Storage
|
| 40 |
+
client isn't available, fall back to the REST client. Defaults to
|
| 41 |
+
``True``.
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
def __init__(
|
| 45 |
+
self,
|
| 46 |
+
client=None,
|
| 47 |
+
bqstorage_client=None,
|
| 48 |
+
prefer_bqstorage_client=True,
|
| 49 |
+
):
|
| 50 |
+
if client is None:
|
| 51 |
+
client = bigquery.Client()
|
| 52 |
+
self._owns_client = True
|
| 53 |
+
else:
|
| 54 |
+
self._owns_client = False
|
| 55 |
+
|
| 56 |
+
# A warning is already raised by the BQ Storage client factory factory if
|
| 57 |
+
# instantiation fails, or if the given BQ Storage client instance is outdated.
|
| 58 |
+
if not prefer_bqstorage_client:
|
| 59 |
+
bqstorage_client = None
|
| 60 |
+
self._owns_bqstorage_client = False
|
| 61 |
+
elif bqstorage_client is None:
|
| 62 |
+
bqstorage_client = client._ensure_bqstorage_client()
|
| 63 |
+
self._owns_bqstorage_client = bqstorage_client is not None
|
| 64 |
+
else:
|
| 65 |
+
self._owns_bqstorage_client = False
|
| 66 |
+
bqstorage_client = client._ensure_bqstorage_client(bqstorage_client)
|
| 67 |
+
|
| 68 |
+
self._client = client
|
| 69 |
+
self._bqstorage_client = bqstorage_client
|
| 70 |
+
|
| 71 |
+
self._closed = False
|
| 72 |
+
self._cursors_created = weakref.WeakSet()
|
| 73 |
+
|
| 74 |
+
def close(self):
|
| 75 |
+
"""Close the connection and any cursors created from it.
|
| 76 |
+
|
| 77 |
+
Any BigQuery clients explicitly passed to the constructor are *not*
|
| 78 |
+
closed, only those created by the connection instance itself.
|
| 79 |
+
"""
|
| 80 |
+
self._closed = True
|
| 81 |
+
|
| 82 |
+
if self._owns_client:
|
| 83 |
+
self._client.close()
|
| 84 |
+
|
| 85 |
+
if self._owns_bqstorage_client:
|
| 86 |
+
# There is no close() on the BQ Storage client itself.
|
| 87 |
+
self._bqstorage_client._transport.grpc_channel.close()
|
| 88 |
+
|
| 89 |
+
for cursor_ in self._cursors_created:
|
| 90 |
+
if not cursor_._closed:
|
| 91 |
+
cursor_.close()
|
| 92 |
+
|
| 93 |
+
def commit(self):
|
| 94 |
+
"""No-op, but for consistency raise an error if connection is closed."""
|
| 95 |
+
|
| 96 |
+
def cursor(self):
|
| 97 |
+
"""Return a new cursor object.
|
| 98 |
+
|
| 99 |
+
Returns:
|
| 100 |
+
google.cloud.bigquery.dbapi.Cursor: A DB-API cursor that uses this connection.
|
| 101 |
+
"""
|
| 102 |
+
new_cursor = cursor.Cursor(self)
|
| 103 |
+
self._cursors_created.add(new_cursor)
|
| 104 |
+
return new_cursor
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def connect(client=None, bqstorage_client=None, prefer_bqstorage_client=True):
|
| 108 |
+
"""Construct a DB-API connection to Google BigQuery.
|
| 109 |
+
|
| 110 |
+
Args:
|
| 111 |
+
client (Optional[google.cloud.bigquery.Client]):
|
| 112 |
+
A REST API client used to connect to BigQuery. If not passed, a
|
| 113 |
+
client is created using default options inferred from the environment.
|
| 114 |
+
bqstorage_client(\
|
| 115 |
+
Optional[google.cloud.bigquery_storage_v1.BigQueryReadClient] \
|
| 116 |
+
):
|
| 117 |
+
A client that uses the faster BigQuery Storage API to fetch rows from
|
| 118 |
+
BigQuery. If not passed, it is created using the same credentials
|
| 119 |
+
as ``client`` (provided that BigQuery Storage dependencies are installed).
|
| 120 |
+
prefer_bqstorage_client (Optional[bool]):
|
| 121 |
+
Prefer the BigQuery Storage client over the REST client. If Storage
|
| 122 |
+
client isn't available, fall back to the REST client. Defaults to
|
| 123 |
+
``True``.
|
| 124 |
+
|
| 125 |
+
Returns:
|
| 126 |
+
google.cloud.bigquery.dbapi.Connection: A new DB-API connection to BigQu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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Cursor for the Google BigQuery DB-API."""
|
| 16 |
+
|
| 17 |
+
from __future__ import annotations
|
| 18 |
+
|
| 19 |
+
import collections
|
| 20 |
+
from collections import abc as collections_abc
|
| 21 |
+
import re
|
| 22 |
+
from typing import Optional
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
from google.cloud.bigquery_storage import ArrowSerializationOptions
|
| 26 |
+
except ImportError:
|
| 27 |
+
_ARROW_COMPRESSION_SUPPORT = False
|
| 28 |
+
else:
|
| 29 |
+
# Having BQ Storage available implies that pyarrow >=1.0.0 is available, too.
|
| 30 |
+
_ARROW_COMPRESSION_SUPPORT = True
|
| 31 |
+
|
| 32 |
+
from google.cloud.bigquery import job
|
| 33 |
+
from google.cloud.bigquery.dbapi import _helpers
|
| 34 |
+
from google.cloud.bigquery.dbapi import exceptions
|
| 35 |
+
import google.cloud.exceptions # type: ignore
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# Per PEP 249: A 7-item sequence containing information describing one result
|
| 39 |
+
# column. The first two items (name and type_code) are mandatory, the other
|
| 40 |
+
# five are optional and are set to None if no meaningful values can be
|
| 41 |
+
# provided.
|
| 42 |
+
Column = collections.namedtuple(
|
| 43 |
+
"Column",
|
| 44 |
+
[
|
| 45 |
+
"name",
|
| 46 |
+
"type_code",
|
| 47 |
+
"display_size",
|
| 48 |
+
"internal_size",
|
| 49 |
+
"precision",
|
| 50 |
+
"scale",
|
| 51 |
+
"null_ok",
|
| 52 |
+
],
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
@_helpers.raise_on_closed("Operating on a closed cursor.")
|
| 57 |
+
class Cursor(object):
|
| 58 |
+
"""DB-API Cursor to Google BigQuery.
|
| 59 |
+
|
| 60 |
+
Args:
|
| 61 |
+
connection (google.cloud.bigquery.dbapi.Connection):
|
| 62 |
+
A DB-API connection to Google BigQuery.
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
def __init__(self, connection):
|
| 66 |
+
self.connection = connection
|
| 67 |
+
self.description = None
|
| 68 |
+
# Per PEP 249: The attribute is -1 in case no .execute*() has been
|
| 69 |
+
# performed on the cursor or the rowcount of the last operation
|
| 70 |
+
# cannot be determined by the interface.
|
| 71 |
+
self.rowcount = -1
|
| 72 |
+
# Per PEP 249: The arraysize attribute defaults to 1, meaning to fetch
|
| 73 |
+
# a single row at a time. However, we deviate from that, and set the
|
| 74 |
+
# default to None, allowing the backend to automatically determine the
|
| 75 |
+
# most appropriate size.
|
| 76 |
+
self.arraysize = None
|
| 77 |
+
self._query_data = None
|
| 78 |
+
self._query_rows = None
|
| 79 |
+
self._closed = False
|
| 80 |
+
|
| 81 |
+
@property
|
| 82 |
+
def query_job(self) -> Optional[job.QueryJob]:
|
| 83 |
+
"""google.cloud.bigquery.job.query.QueryJob | None: The query job
|
| 84 |
+
created by the last ``execute*()`` call, if a query job was created.
|
| 85 |
+
|
| 86 |
+
.. note::
|
| 87 |
+
If the last ``execute*()`` call was ``executemany()``, this is the
|
| 88 |
+
last job created by ``executemany()``."""
|
| 89 |
+
rows = self._query_rows
|
| 90 |
+
|
| 91 |
+
if rows is None:
|
| 92 |
+
return None
|
| 93 |
+
|
| 94 |
+
job_id = rows.job_id
|
| 95 |
+
project = rows.project
|
| 96 |
+
location = rows.location
|
| 97 |
+
client = self.connection._client
|
| 98 |
+
|
| 99 |
+
if job_id is None:
|
| 100 |
+
return None
|
| 101 |
+
|
| 102 |
+
return client.get_job(job_id, location=location, project=project)
|
| 103 |
+
|
| 104 |
+
def close(self):
|
| 105 |
+
"""Mark the cursor as closed, preventing its further use."""
|
| 106 |
+
self._closed = True
|
| 107 |
+
|
| 108 |
+
def _set_description(self, schema):
|
| 109 |
+
"""Set description from schema.
|
| 110 |
+
|
| 111 |
+
Args:
|
| 112 |
+
schema (Sequence[google.cloud.bigquery.schema.SchemaField]):
|
| 113 |
+
A description of fields in the schema.
|
| 114 |
+
"""
|
| 115 |
+
if schema is None:
|
| 116 |
+
self.description = None
|
| 117 |
+
return
|
| 118 |
+
|
| 119 |
+
self.description = tuple(
|
| 120 |
+
Column(
|
| 121 |
+
name=field.name,
|
| 122 |
+
type_code=field.field_type,
|
| 123 |
+
display_size=None,
|
| 124 |
+
internal_size=None,
|
| 125 |
+
precision=None,
|
| 126 |
+
scale=None,
|
| 127 |
+
null_ok=field.is_nullable,
|
| 128 |
+
)
|
| 129 |
+
for field in schema
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
def _set_rowcount(self, rows):
|
| 133 |
+
"""Set the rowcount from a RowIterator.
|
| 134 |
+
|
| 135 |
+
Normally, this sets rowcount to the number of rows returned by the
|
| 136 |
+
query, but if it was a DML statement, it sets rowcount to the number
|
| 137 |
+
of modified rows.
|
| 138 |
+
|
| 139 |
+
Args:
|
| 140 |
+
query_results (google.cloud.bigquery.query._QueryResults):
|
| 141 |
+
Results of a query.
|
| 142 |
+
"""
|
| 143 |
+
total_rows = 0
|
| 144 |
+
num_dml_affected_rows = rows.num_dml_affected_rows
|
| 145 |
+
|
| 146 |
+
if rows.total_rows is not None and rows.total_rows > 0:
|
| 147 |
+
total_rows = rows.total_rows
|
| 148 |
+
if num_dml_affected_rows is not None and num_dml_affected_rows > 0:
|
| 149 |
+
total_rows = num_dml_affected_rows
|
| 150 |
+
self.rowcount = total_rows
|
| 151 |
+
|
| 152 |
+
def execute(self, operation, parameters=None, job_id=None, job_config=None):
|
| 153 |
+
"""Prepare and execute a database operation.
|
| 154 |
+
|
| 155 |
+
.. note::
|
| 156 |
+
When setting query parameters, values which are "text"
|
| 157 |
+
(``unicode`` in Python2, ``str`` in Python3) will use
|
| 158 |
+
the 'STRING' BigQuery type. Values which are "bytes" (``str`` in
|
| 159 |
+
Python2, ``bytes`` in Python3), will use using the 'BYTES' type.
|
| 160 |
+
|
| 161 |
+
A `~datetime.datetime` parameter without timezone information uses
|
| 162 |
+
the 'DATETIME' BigQuery type (example: Global Pi Day Celebration
|
| 163 |
+
March 14, 2017 at 1:59pm). A `~datetime.datetime` parameter with
|
| 164 |
+
timezone information uses the 'TIMESTAMP' BigQuery type (example:
|
| 165 |
+
a wedding on April 29, 2011 at 11am, British Summer Time).
|
| 166 |
+
|
| 167 |
+
For more information about BigQuery data types, see:
|
| 168 |
+
https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types
|
| 169 |
+
|
| 170 |
+
``STRUCT``/``RECORD`` and ``REPEATED`` query parameters are not
|
| 171 |
+
yet supported. See:
|
| 172 |
+
https://github.com/GoogleCloudPlatform/google-cloud-python/issues/3524
|
| 173 |
+
|
| 174 |
+
Args:
|
| 175 |
+
operation (str): A Google BigQuery query string.
|
| 176 |
+
|
| 177 |
+
parameters (Union[Mapping[str, Any], Sequence[Any]]):
|
| 178 |
+
(Optional) dictionary or sequence of parameter values.
|
| 179 |
+
|
| 180 |
+
job_id (str | None):
|
| 181 |
+
(Optional and discouraged) The job ID to use when creating
|
| 182 |
+
the query job. For best performance and reliability, manually
|
| 183 |
+
setting a job ID is discouraged.
|
| 184 |
+
|
| 185 |
+
job_config (google.cloud.bigquery.job.QueryJobConfig):
|
| 186 |
+
(Optional) Extra configuration options for the query job.
|
| 187 |
+
"""
|
| 188 |
+
formatted_operation, parameter_types = _format_operation(operation, parameters)
|
| 189 |
+
self._execute(
|
| 190 |
+
formatted_operation, parameters, job_id, job_config, parameter_types
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
def _execute(
|
| 194 |
+
self, formatted_operation, parameters, job_id, job_config, parameter_types
|
| 195 |
+
):
|
| 196 |
+
self._query_data = None
|
| 197 |
+
self._query_results = None
|
| 198 |
+
client = self.connection._client
|
| 199 |
+
|
| 200 |
+
# The DB-API uses the pyformat formatting, since the way BigQuery does
|
| 201 |
+
# query parameters was not one of the standard options. Convert both
|
| 202 |
+
# the query and the parameters to the format expected by the client
|
| 203 |
+
# libraries.
|
| 204 |
+
query_parameters = _helpers.to_query_parameters(parameters, parameter_types)
|
| 205 |
+
|
| 206 |
+
config = job_config or job.QueryJobConfig()
|
| 207 |
+
config.query_parameters = query_parameters
|
| 208 |
+
|
| 209 |
+
# Start the query and wait for the query to finish.
|
| 210 |
+
try:
|
| 211 |
+
if job_id is not None:
|
| 212 |
+
rows = client.query(
|
| 213 |
+
formatted_operation,
|
| 214 |
+
job_config=job_config,
|
| 215 |
+
job_id=job_id,
|
| 216 |
+
job_retry=None,
|
| 217 |
+
).result(
|
| 218 |
+
page_size=self.arraysize,
|
| 219 |
+
)
|
| 220 |
+
else:
|
| 221 |
+
rows = client.query_and_wait(
|
| 222 |
+
formatted_operation,
|
| 223 |
+
job_config=config,
|
| 224 |
+
page_size=self.arraysize,
|
| 225 |
+
)
|
| 226 |
+
except google.cloud.exceptions.GoogleCloudError as exc:
|
| 227 |
+
raise exceptions.DatabaseError(exc)
|
| 228 |
+
|
| 229 |
+
self._query_rows = rows
|
| 230 |
+
self._set_description(rows.schema)
|
| 231 |
+
|
| 232 |
+
if config.dry_run:
|
| 233 |
+
self.rowcount = 0
|
| 234 |
+
else:
|
| 235 |
+
self._set_rowcount(rows)
|
| 236 |
+
|
| 237 |
+
def executemany(self, operation, seq_of_parameters):
|
| 238 |
+
"""Prepare and execute a database operation multiple times.
|
| 239 |
+
|
| 240 |
+
Args:
|
| 241 |
+
operation (str): A Google BigQuery query string.
|
| 242 |
+
|
| 243 |
+
seq_of_parameters (Union[Sequence[Mapping[str, Any], Sequence[Any]]]):
|
| 244 |
+
Sequence of many sets of parameter values.
|
| 245 |
+
"""
|
| 246 |
+
if seq_of_parameters:
|
| 247 |
+
rowcount = 0
|
| 248 |
+
# There's no reason to format the line more than once, as
|
| 249 |
+
# the operation only barely depends on the parameters. So
|
| 250 |
+
# we just use the first set of parameters. If there are
|
| 251 |
+
# different numbers or types of parameters, we'll error
|
| 252 |
+
# anyway.
|
| 253 |
+
formatted_operation, parameter_types = _format_operation(
|
| 254 |
+
operation, seq_of_parameters[0]
|
| 255 |
+
)
|
| 256 |
+
for parameters in seq_of_parameters:
|
| 257 |
+
self._execute(
|
| 258 |
+
formatted_operation, parameters, None, None, parameter_types
|
| 259 |
+
)
|
| 260 |
+
rowcount += self.rowcount
|
| 261 |
+
|
| 262 |
+
self.rowcount = rowcount
|
| 263 |
+
|
| 264 |
+
def _try_fetch(self, size=None):
|
| 265 |
+
"""Try to start fetching data, if not yet started.
|
| 266 |
+
|
| 267 |
+
Mutates self to indicate that iteration has started.
|
| 268 |
+
"""
|
| 269 |
+
if self._query_data is not None:
|
| 270 |
+
# Already started fetching the data.
|
| 271 |
+
return
|
| 272 |
+
|
| 273 |
+
rows = self._query_rows
|
| 274 |
+
if rows is None:
|
| 275 |
+
raise exceptions.InterfaceError(
|
| 276 |
+
"No query results: execute() must be called before fetch."
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
bqstorage_client = self.connection._bqstorage_client
|
| 280 |
+
if rows._should_use_bqstorage(
|
| 281 |
+
bqstorage_client,
|
| 282 |
+
create_bqstorage_client=False,
|
| 283 |
+
):
|
| 284 |
+
rows_iterable = self._bqstorage_fetch(bqstorage_client)
|
| 285 |
+
self._query_data = _helpers.to_bq_table_rows(rows_iterable)
|
| 286 |
+
return
|
| 287 |
+
|
| 288 |
+
self._query_data = iter(rows)
|
| 289 |
+
|
| 290 |
+
def _bqstorage_fetch(self, bqstorage_client):
|
| 291 |
+
"""Start fetching data with the BigQuery Storage API.
|
| 292 |
+
|
| 293 |
+
The method assumes that the data about the relevant query job already
|
| 294 |
+
exists internally.
|
| 295 |
+
|
| 296 |
+
Args:
|
| 297 |
+
bqstorage_client(\
|
| 298 |
+
google.cloud.bigquery_storage_v1.BigQueryReadClient \
|
| 299 |
+
):
|
| 300 |
+
A client tha know how to talk to the BigQuery Storage API.
|
| 301 |
+
|
| 302 |
+
Returns:
|
| 303 |
+
Iterable[Mapping]:
|
| 304 |
+
A sequence of rows, represented as dictionaries.
|
| 305 |
+
"""
|
| 306 |
+
# Hitting this code path with a BQ Storage client instance implies that
|
| 307 |
+
# bigquery_storage can indeed be imported here without errors.
|
| 308 |
+
from google.cloud import bigquery_storage
|
| 309 |
+
|
| 310 |
+
table_reference = self._query_rows._table
|
| 311 |
+
|
| 312 |
+
requested_session = bigquery_storage.types.ReadSession(
|
| 313 |
+
table=table_reference.to_bqstorage(),
|
| 314 |
+
data_format=bigquery_storage.types.DataFormat.ARROW,
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
if _ARROW_COMPRESSION_SUPPORT:
|
| 318 |
+
requested_session.read_options.arrow_serialization_options.buffer_compression = (
|
| 319 |
+
ArrowSerializationOptions.CompressionCodec.LZ4_FRAME
|
| 320 |
+
)
|
| 321 |
+
|
| 322 |
+
read_session = bqstorage_client.create_read_session(
|
| 323 |
+
parent="projects/{}".format(table_reference.project),
|
| 324 |
+
read_session=requested_session,
|
| 325 |
+
# a single stream only, as DB API is not well-suited for multithreading
|
| 326 |
+
max_stream_count=1,
|
| 327 |
+
retry=None,
|
| 328 |
+
timeout=None,
|
| 329 |
+
)
|
| 330 |
+
|
| 331 |
+
if not read_session.streams:
|
| 332 |
+
return iter([]) # empty table, nothing to read
|
| 333 |
+
|
| 334 |
+
stream_name = read_session.streams[0].name
|
| 335 |
+
read_rows_stream = bqstorage_client.read_rows(stream_name)
|
| 336 |
+
|
| 337 |
+
rows_iterable = read_rows_stream.rows(read_session)
|
| 338 |
+
return rows_iterable
|
| 339 |
+
|
| 340 |
+
def fetchone(self):
|
| 341 |
+
"""Fetch a single row from the results of the last ``execute*()`` call.
|
| 342 |
+
|
| 343 |
+
.. note::
|
| 344 |
+
If a dry run query was executed, no rows are returned.
|
| 345 |
+
|
| 346 |
+
Returns:
|
| 347 |
+
Tuple:
|
| 348 |
+
A tuple representing a row or ``None`` if no more data is
|
| 349 |
+
available.
|
| 350 |
+
|
| 351 |
+
Raises:
|
| 352 |
+
google.cloud.bigquery.dbapi.InterfaceError: if called before ``execute()``.
|
| 353 |
+
"""
|
| 354 |
+
self._try_fetch()
|
| 355 |
+
try:
|
| 356 |
+
return next(self._query_data)
|
| 357 |
+
except StopIteration:
|
| 358 |
+
return None
|
| 359 |
+
|
| 360 |
+
def fetchmany(self, size=None):
|
| 361 |
+
"""Fetch multiple results from the last ``execute*()`` call.
|
| 362 |
+
|
| 363 |
+
.. note::
|
| 364 |
+
If a dry run query was executed, no rows are returned.
|
| 365 |
+
|
| 366 |
+
.. note::
|
| 367 |
+
The size parameter is not used for the request/response size.
|
| 368 |
+
Set the ``arraysize`` attribute before calling ``execute()`` to
|
| 369 |
+
set the batch size.
|
| 370 |
+
|
| 371 |
+
Args:
|
| 372 |
+
size (int):
|
| 373 |
+
(Optional) Maximum number of rows to return. Defaults to the
|
| 374 |
+
``arraysize`` property value. If ``arraysize`` is not set, it
|
| 375 |
+
defaults to ``1``.
|
| 376 |
+
|
| 377 |
+
Returns:
|
| 378 |
+
List[Tuple]: A list of rows.
|
| 379 |
+
|
| 380 |
+
Raises:
|
| 381 |
+
google.cloud.bigquery.dbapi.InterfaceError: if called before ``execute()``.
|
| 382 |
+
"""
|
| 383 |
+
if size is None:
|
| 384 |
+
# Since self.arraysize can be None (a deviation from PEP 249),
|
| 385 |
+
# use an actual PEP 249 default of 1 in such case (*some* number
|
| 386 |
+
# is needed here).
|
| 387 |
+
size = self.arraysize if self.arraysize else 1
|
| 388 |
+
|
| 389 |
+
self._try_fetch(size=size)
|
| 390 |
+
rows = []
|
| 391 |
+
|
| 392 |
+
for row in self._query_data:
|
| 393 |
+
rows.append(row)
|
| 394 |
+
if len(rows) >= size:
|
| 395 |
+
break
|
| 396 |
+
|
| 397 |
+
return rows
|
| 398 |
+
|
| 399 |
+
def fetchall(self):
|
| 400 |
+
"""Fetch all remaining results from the last ``execute*()`` call.
|
| 401 |
+
|
| 402 |
+
.. note::
|
| 403 |
+
If a dry run query was executed, no rows are returned.
|
| 404 |
+
|
| 405 |
+
Returns:
|
| 406 |
+
List[Tuple]: A list of all the rows in the results.
|
| 407 |
+
|
| 408 |
+
Raises:
|
| 409 |
+
google.cloud.bigquery.dbapi.InterfaceError: if called before ``execute()``.
|
| 410 |
+
"""
|
| 411 |
+
self._try_fetch()
|
| 412 |
+
return list(self._query_data)
|
| 413 |
+
|
| 414 |
+
def setinputsizes(self, sizes):
|
| 415 |
+
"""No-op, but for consistency raise an error if cursor is closed."""
|
| 416 |
+
|
| 417 |
+
def setoutputsize(self, size, column=None):
|
| 418 |
+
"""No-op, but for consistency raise an error if cursor is closed."""
|
| 419 |
+
|
| 420 |
+
def __iter__(self):
|
| 421 |
+
self._try_fetch()
|
| 422 |
+
return iter(self._query_data)
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
def _format_operation_list(operation, parameters):
|
| 426 |
+
"""Formats parameters in operation in the way BigQuery expects.
|
| 427 |
+
|
| 428 |
+
The input operation will be a query like ``SELECT %s`` and the output
|
| 429 |
+
will be a query like ``SELECT ?``.
|
| 430 |
+
|
| 431 |
+
Args:
|
| 432 |
+
operation (str): A Google BigQuery query string.
|
| 433 |
+
|
| 434 |
+
parameters (Sequence[Any]): Sequence of parameter values.
|
| 435 |
+
|
| 436 |
+
Returns:
|
| 437 |
+
str: A formatted query string.
|
| 438 |
+
|
| 439 |
+
Raises:
|
| 440 |
+
google.cloud.bigquery.dbapi.ProgrammingError:
|
| 441 |
+
if a parameter used in the operation is not found in the
|
| 442 |
+
``parameters`` argument.
|
| 443 |
+
"""
|
| 444 |
+
formatted_params = ["?" for _ in parameters]
|
| 445 |
+
|
| 446 |
+
try:
|
| 447 |
+
return operation % tuple(formatted_params)
|
| 448 |
+
except (TypeError, ValueError) as exc:
|
| 449 |
+
raise exceptions.ProgrammingError(exc)
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
def _format_operation_dict(operation, parameters):
|
| 453 |
+
"""Formats parameters in operation in the way BigQuery expects.
|
| 454 |
+
|
| 455 |
+
The input operation will be a query like ``SELECT %(namedparam)s`` and
|
| 456 |
+
the output will be a query like ``SELECT @namedparam``.
|
| 457 |
+
|
| 458 |
+
Args:
|
| 459 |
+
operation (str): A Google BigQuery query string.
|
| 460 |
+
|
| 461 |
+
parameters (Mapping[str, Any]): Dictionary of parameter values.
|
| 462 |
+
|
| 463 |
+
Returns:
|
| 464 |
+
str: A formatted query string.
|
| 465 |
+
|
| 466 |
+
Raises:
|
| 467 |
+
google.cloud.bigquery.dbapi.ProgrammingError:
|
| 468 |
+
if a parameter used in the operation is not found in the
|
| 469 |
+
``parameters`` argument.
|
| 470 |
+
"""
|
| 471 |
+
formatted_params = {}
|
| 472 |
+
for name in parameters:
|
| 473 |
+
escaped_name = name.replace("`", r"\`")
|
| 474 |
+
formatted_params[name] = "@`{}`".format(escaped_name)
|
| 475 |
+
|
| 476 |
+
try:
|
| 477 |
+
return operation % formatted_params
|
| 478 |
+
except (KeyError, ValueError, TypeError) as exc:
|
| 479 |
+
raise exceptions.ProgrammingError(exc)
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
def _format_operation(operation, parameters):
|
| 483 |
+
"""Formats parameters in operation in way BigQuery expects.
|
| 484 |
+
|
| 485 |
+
Args:
|
| 486 |
+
operation (str): A Google BigQuery query string.
|
| 487 |
+
|
| 488 |
+
parameters (Union[Mapping[str, Any], Sequence[Any]]):
|
| 489 |
+
Optional parameter values.
|
| 490 |
+
|
| 491 |
+
Returns:
|
| 492 |
+
str: A formatted query string.
|
| 493 |
+
|
| 494 |
+
Raises:
|
| 495 |
+
google.cloud.bigquery.dbapi.ProgrammingError:
|
| 496 |
+
if a parameter used in the operation is not found in the
|
| 497 |
+
``parameters`` argument.
|
| 498 |
+
"""
|
| 499 |
+
if parameters is None or len(parameters) == 0:
|
| 500 |
+
return operation.replace("%%", "%"), None # Still do percent de-escaping.
|
| 501 |
+
|
| 502 |
+
operation, parameter_types = _extract_types(operation)
|
| 503 |
+
if parameter_types is None:
|
| 504 |
+
raise exceptions.ProgrammingError(
|
| 505 |
+
f"Parameters were provided, but {repr(operation)} has no placeholders."
|
| 506 |
+
)
|
| 507 |
+
|
| 508 |
+
if isinstance(parameters, collections_abc.Mapping):
|
| 509 |
+
return _format_operation_dict(operation, parameters), parameter_types
|
| 510 |
+
|
| 511 |
+
return _format_operation_list(operation, parameters), parameter_types
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def _extract_types(
|
| 515 |
+
operation,
|
| 516 |
+
extra_type_sub=re.compile(
|
| 517 |
+
r"""
|
| 518 |
+
(%*) # Extra %s. We'll deal with these in the replacement code
|
| 519 |
+
|
| 520 |
+
% # Beginning of replacement, %s, %(...)s
|
| 521 |
+
|
| 522 |
+
(?:\( # Begin of optional name and/or type
|
| 523 |
+
([^:)]*) # name
|
| 524 |
+
(?:: # ':' introduces type
|
| 525 |
+
( # start of type group
|
| 526 |
+
[a-zA-Z0-9_<>, ]+ # First part, no parens
|
| 527 |
+
|
| 528 |
+
(?: # start sets of parens + non-paren text
|
| 529 |
+
\([0-9 ,]+\) # comma-separated groups of digits in parens
|
| 530 |
+
# (e.g. string(10))
|
| 531 |
+
(?=[, >)]) # Must be followed by ,>) or space
|
| 532 |
+
[a-zA-Z0-9<>, ]* # Optional non-paren chars
|
| 533 |
+
)* # Can be zero or more of parens and following text
|
| 534 |
+
) # end of type group
|
| 535 |
+
)? # close type clause ":type"
|
| 536 |
+
\))? # End of optional name and/or type
|
| 537 |
+
|
| 538 |
+
s # End of replacement
|
| 539 |
+
""",
|
| 540 |
+
re.VERBOSE,
|
| 541 |
+
).sub,
|
| 542 |
+
):
|
| 543 |
+
"""Remove type information from parameter placeholders.
|
| 544 |
+
|
| 545 |
+
For every parameter of the form %(name:type)s, replace with %(name)s and add the
|
| 546 |
+
item name->type to dict that's returned.
|
| 547 |
+
|
| 548 |
+
Returns operation without type information and a dictionary of names and types.
|
| 549 |
+
"""
|
| 550 |
+
parameter_types = None
|
| 551 |
+
|
| 552 |
+
def repl(m):
|
| 553 |
+
nonlocal parameter_types
|
| 554 |
+
prefix, name, type_ = m.groups()
|
| 555 |
+
if len(prefix) % 2:
|
| 556 |
+
# The prefix has an odd number of %s, the last of which
|
| 557 |
+
# escapes the % we're looking for, so we don't want to
|
| 558 |
+
# change anything.
|
| 559 |
+
return m.group(0)
|
| 560 |
+
|
| 561 |
+
try:
|
| 562 |
+
if name:
|
| 563 |
+
if not parameter_types:
|
| 564 |
+
parameter_types = {}
|
| 565 |
+
if type_:
|
| 566 |
+
if name in parameter_types:
|
| 567 |
+
if type_ != parameter_types[name]:
|
| 568 |
+
raise exceptions.ProgrammingError(
|
| 569 |
+
f"Conflicting types for {name}: "
|
| 570 |
+
f"{parameter_types[name]} and {type_}."
|
| 571 |
+
)
|
| 572 |
+
else:
|
| 573 |
+
parameter_types[name] = type_
|
| 574 |
+
else:
|
| 575 |
+
if not isinstance(parameter_types, dict):
|
| 576 |
+
raise TypeError()
|
| 577 |
+
|
| 578 |
+
return f"{prefix}%({name})s"
|
| 579 |
+
else:
|
| 580 |
+
if parameter_types is None:
|
| 581 |
+
parameter_types = []
|
| 582 |
+
parameter_types.append(type_)
|
| 583 |
+
return f"{prefix}%s"
|
| 584 |
+
except (AttributeError, TypeError):
|
| 585 |
+
raise exceptions.ProgrammingError(
|
| 586 |
+
f"{repr(operation)} mixes named and unamed parameters."
|
| 587 |
+
)
|
| 588 |
+
|
| 589 |
+
return extra_type_sub(repl, operation), parameter_types
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/exceptions.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Exceptions used in the Google BigQuery DB-API."""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class Warning(Exception):
|
| 19 |
+
"""Exception raised for important DB-API warnings."""
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class Error(Exception):
|
| 23 |
+
"""Exception representing all non-warning DB-API errors."""
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class InterfaceError(Error):
|
| 27 |
+
"""DB-API error related to the database interface."""
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class DatabaseError(Error):
|
| 31 |
+
"""DB-API error related to the database."""
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class DataError(DatabaseError):
|
| 35 |
+
"""DB-API error due to problems with the processed data."""
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class OperationalError(DatabaseError):
|
| 39 |
+
"""DB-API error related to the database operation.
|
| 40 |
+
|
| 41 |
+
These errors are not necessarily under the control of the programmer.
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class IntegrityError(DatabaseError):
|
| 46 |
+
"""DB-API error when integrity of the database is affected."""
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class InternalError(DatabaseError):
|
| 50 |
+
"""DB-API error when the database encounters an internal error."""
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class ProgrammingError(DatabaseError):
|
| 54 |
+
"""DB-API exception raised for programming errors."""
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class NotSupportedError(DatabaseError):
|
| 58 |
+
"""DB-API error for operations not supported by the database or API."""
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/dbapi/types.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2017 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Types used in the Google BigQuery DB-API.
|
| 16 |
+
|
| 17 |
+
See `PEP-249`_ for details.
|
| 18 |
+
|
| 19 |
+
.. _PEP-249:
|
| 20 |
+
https://www.python.org/dev/peps/pep-0249/#type-objects-and-constructors
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
import datetime
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
Date = datetime.date
|
| 27 |
+
Time = datetime.time
|
| 28 |
+
Timestamp = datetime.datetime
|
| 29 |
+
DateFromTicks = datetime.date.fromtimestamp
|
| 30 |
+
TimestampFromTicks = datetime.datetime.fromtimestamp
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def Binary(data):
|
| 34 |
+
"""Contruct a DB-API binary value.
|
| 35 |
+
|
| 36 |
+
Args:
|
| 37 |
+
data (bytes-like): An object containing binary data and that
|
| 38 |
+
can be converted to bytes with the `bytes` builtin.
|
| 39 |
+
|
| 40 |
+
Returns:
|
| 41 |
+
bytes: The binary data as a bytes object.
|
| 42 |
+
"""
|
| 43 |
+
if isinstance(data, int):
|
| 44 |
+
# This is not the conversion we're looking for, because it
|
| 45 |
+
# will simply create a bytes object of the given size.
|
| 46 |
+
raise TypeError("cannot convert `int` object to binary")
|
| 47 |
+
|
| 48 |
+
try:
|
| 49 |
+
return bytes(data)
|
| 50 |
+
except TypeError:
|
| 51 |
+
if isinstance(data, str):
|
| 52 |
+
return data.encode("utf-8")
|
| 53 |
+
else:
|
| 54 |
+
raise
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def TimeFromTicks(ticks, tz=None):
|
| 58 |
+
"""Construct a DB-API time value from the given ticks value.
|
| 59 |
+
|
| 60 |
+
Args:
|
| 61 |
+
ticks (float):
|
| 62 |
+
a number of seconds since the epoch; see the documentation of the
|
| 63 |
+
standard Python time module for details.
|
| 64 |
+
|
| 65 |
+
tz (datetime.tzinfo): (Optional) time zone to use for conversion
|
| 66 |
+
|
| 67 |
+
Returns:
|
| 68 |
+
datetime.time: time represented by ticks.
|
| 69 |
+
"""
|
| 70 |
+
dt = datetime.datetime.fromtimestamp(ticks, tz=tz)
|
| 71 |
+
return dt.timetz()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
class _DBAPITypeObject(object):
|
| 75 |
+
"""DB-API type object which compares equal to many different strings.
|
| 76 |
+
|
| 77 |
+
See `PEP-249`_ for details.
|
| 78 |
+
|
| 79 |
+
.. _PEP-249:
|
| 80 |
+
https://www.python.org/dev/peps/pep-0249/#implementation-hints-for-module-authors
|
| 81 |
+
"""
|
| 82 |
+
|
| 83 |
+
def __init__(self, *values):
|
| 84 |
+
self.values = values
|
| 85 |
+
|
| 86 |
+
def __eq__(self, other):
|
| 87 |
+
return other in self.values
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
STRING = "STRING"
|
| 91 |
+
BINARY = _DBAPITypeObject("BYTES", "RECORD", "STRUCT")
|
| 92 |
+
NUMBER = _DBAPITypeObject(
|
| 93 |
+
"INTEGER", "INT64", "FLOAT", "FLOAT64", "NUMERIC", "BIGNUMERIC", "BOOLEAN", "BOOL"
|
| 94 |
+
)
|
| 95 |
+
DATETIME = _DBAPITypeObject("TIMESTAMP", "DATE", "TIME", "DATETIME")
|
| 96 |
+
ROWID = "ROWID"
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/__init__.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2015 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Define API Jobs."""
|
| 16 |
+
|
| 17 |
+
from google.cloud.bigquery.job.base import _AsyncJob
|
| 18 |
+
from google.cloud.bigquery.job.base import _error_result_to_exception
|
| 19 |
+
from google.cloud.bigquery.job.base import _DONE_STATE
|
| 20 |
+
from google.cloud.bigquery.job.base import _JobConfig
|
| 21 |
+
from google.cloud.bigquery.job.base import _JobReference
|
| 22 |
+
from google.cloud.bigquery.job.base import ReservationUsage
|
| 23 |
+
from google.cloud.bigquery.job.base import ScriptStatistics
|
| 24 |
+
from google.cloud.bigquery.job.base import ScriptStackFrame
|
| 25 |
+
from google.cloud.bigquery.job.base import TransactionInfo
|
| 26 |
+
from google.cloud.bigquery.job.base import UnknownJob
|
| 27 |
+
from google.cloud.bigquery.job.copy_ import CopyJob
|
| 28 |
+
from google.cloud.bigquery.job.copy_ import CopyJobConfig
|
| 29 |
+
from google.cloud.bigquery.job.copy_ import OperationType
|
| 30 |
+
from google.cloud.bigquery.job.extract import ExtractJob
|
| 31 |
+
from google.cloud.bigquery.job.extract import ExtractJobConfig
|
| 32 |
+
from google.cloud.bigquery.job.load import LoadJob
|
| 33 |
+
from google.cloud.bigquery.job.load import LoadJobConfig
|
| 34 |
+
from google.cloud.bigquery.job.query import _contains_order_by
|
| 35 |
+
from google.cloud.bigquery.job.query import DmlStats
|
| 36 |
+
from google.cloud.bigquery.job.query import QueryJob
|
| 37 |
+
from google.cloud.bigquery.job.query import QueryJobConfig
|
| 38 |
+
from google.cloud.bigquery.job.query import QueryPlanEntry
|
| 39 |
+
from google.cloud.bigquery.job.query import QueryPlanEntryStep
|
| 40 |
+
from google.cloud.bigquery.job.query import ScriptOptions
|
| 41 |
+
from google.cloud.bigquery.job.query import TimelineEntry
|
| 42 |
+
from google.cloud.bigquery.job.query import IncrementalResultStats
|
| 43 |
+
from google.cloud.bigquery.enums import Compression
|
| 44 |
+
from google.cloud.bigquery.enums import CreateDisposition
|
| 45 |
+
from google.cloud.bigquery.enums import DestinationFormat
|
| 46 |
+
from google.cloud.bigquery.enums import Encoding
|
| 47 |
+
from google.cloud.bigquery.enums import QueryPriority
|
| 48 |
+
from google.cloud.bigquery.enums import SchemaUpdateOption
|
| 49 |
+
from google.cloud.bigquery.enums import SourceFormat
|
| 50 |
+
from google.cloud.bigquery.enums import WriteDisposition
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
# Include classes previously in job.py for backwards compatibility.
|
| 54 |
+
__all__ = [
|
| 55 |
+
"_AsyncJob",
|
| 56 |
+
"_error_result_to_exception",
|
| 57 |
+
"_DONE_STATE",
|
| 58 |
+
"_JobConfig",
|
| 59 |
+
"_JobReference",
|
| 60 |
+
"ReservationUsage",
|
| 61 |
+
"ScriptStatistics",
|
| 62 |
+
"ScriptStackFrame",
|
| 63 |
+
"UnknownJob",
|
| 64 |
+
"CopyJob",
|
| 65 |
+
"CopyJobConfig",
|
| 66 |
+
"OperationType",
|
| 67 |
+
"ExtractJob",
|
| 68 |
+
"ExtractJobConfig",
|
| 69 |
+
"LoadJob",
|
| 70 |
+
"LoadJobConfig",
|
| 71 |
+
"_contains_order_by",
|
| 72 |
+
"DmlStats",
|
| 73 |
+
"QueryJob",
|
| 74 |
+
"QueryJobConfig",
|
| 75 |
+
"QueryPlanEntry",
|
| 76 |
+
"QueryPlanEntryStep",
|
| 77 |
+
"ScriptOptions",
|
| 78 |
+
"TimelineEntry",
|
| 79 |
+
"Compression",
|
| 80 |
+
"CreateDisposition",
|
| 81 |
+
"DestinationFormat",
|
| 82 |
+
"Encoding",
|
| 83 |
+
"QueryPriority",
|
| 84 |
+
"SchemaUpdateOption",
|
| 85 |
+
"SourceFormat",
|
| 86 |
+
"TransactionInfo",
|
| 87 |
+
"WriteDisposition",
|
| 88 |
+
"IncrementalResultStats",
|
| 89 |
+
]
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (2.44 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/__pycache__/base.cpython-311.pyc
ADDED
|
Binary file (51.5 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/__pycache__/copy_.cpython-311.pyc
ADDED
|
Binary file (13 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/__pycache__/extract.cpython-311.pyc
ADDED
|
Binary file (12.9 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/__pycache__/load.cpython-311.pyc
ADDED
|
Binary file (58.1 kB). View file
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2015 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Base classes and helpers for job classes."""
|
| 16 |
+
|
| 17 |
+
from collections import namedtuple
|
| 18 |
+
import copy
|
| 19 |
+
import http
|
| 20 |
+
import threading
|
| 21 |
+
import typing
|
| 22 |
+
from typing import ClassVar, Dict, Optional, Sequence
|
| 23 |
+
|
| 24 |
+
from google.api_core import retry as retries
|
| 25 |
+
from google.api_core import exceptions
|
| 26 |
+
import google.api_core.future.polling
|
| 27 |
+
|
| 28 |
+
from google.cloud.bigquery import _helpers
|
| 29 |
+
from google.cloud.bigquery._helpers import _int_or_none
|
| 30 |
+
from google.cloud.bigquery.retry import (
|
| 31 |
+
DEFAULT_GET_JOB_TIMEOUT,
|
| 32 |
+
DEFAULT_RETRY,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
_DONE_STATE = "DONE"
|
| 37 |
+
_STOPPED_REASON = "stopped"
|
| 38 |
+
_ERROR_REASON_TO_EXCEPTION = {
|
| 39 |
+
"accessDenied": http.client.FORBIDDEN,
|
| 40 |
+
"backendError": http.client.INTERNAL_SERVER_ERROR,
|
| 41 |
+
"billingNotEnabled": http.client.FORBIDDEN,
|
| 42 |
+
"billingTierLimitExceeded": http.client.BAD_REQUEST,
|
| 43 |
+
"blocked": http.client.FORBIDDEN,
|
| 44 |
+
"duplicate": http.client.CONFLICT,
|
| 45 |
+
"internalError": http.client.INTERNAL_SERVER_ERROR,
|
| 46 |
+
"invalid": http.client.BAD_REQUEST,
|
| 47 |
+
"invalidQuery": http.client.BAD_REQUEST,
|
| 48 |
+
"notFound": http.client.NOT_FOUND,
|
| 49 |
+
"notImplemented": http.client.NOT_IMPLEMENTED,
|
| 50 |
+
"policyViolation": http.client.FORBIDDEN,
|
| 51 |
+
"quotaExceeded": http.client.FORBIDDEN,
|
| 52 |
+
"rateLimitExceeded": http.client.TOO_MANY_REQUESTS,
|
| 53 |
+
"resourceInUse": http.client.BAD_REQUEST,
|
| 54 |
+
"resourcesExceeded": http.client.BAD_REQUEST,
|
| 55 |
+
"responseTooLarge": http.client.FORBIDDEN,
|
| 56 |
+
"stopped": http.client.OK,
|
| 57 |
+
"tableUnavailable": http.client.BAD_REQUEST,
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _error_result_to_exception(error_result, errors=None):
|
| 62 |
+
"""Maps BigQuery error reasons to an exception.
|
| 63 |
+
|
| 64 |
+
The reasons and their matching HTTP status codes are documented on
|
| 65 |
+
the `troubleshooting errors`_ page.
|
| 66 |
+
|
| 67 |
+
.. _troubleshooting errors: https://cloud.google.com/bigquery\
|
| 68 |
+
/troubleshooting-errors
|
| 69 |
+
|
| 70 |
+
Args:
|
| 71 |
+
error_result (Mapping[str, str]): The error result from BigQuery.
|
| 72 |
+
errors (Union[Iterable[str], None]): The detailed error messages.
|
| 73 |
+
|
| 74 |
+
Returns:
|
| 75 |
+
google.cloud.exceptions.GoogleAPICallError: The mapped exception.
|
| 76 |
+
"""
|
| 77 |
+
reason = error_result.get("reason")
|
| 78 |
+
status_code = _ERROR_REASON_TO_EXCEPTION.get(
|
| 79 |
+
reason, http.client.INTERNAL_SERVER_ERROR
|
| 80 |
+
)
|
| 81 |
+
# Manually create error message to preserve both error_result and errors.
|
| 82 |
+
# Can be removed once b/310544564 and b/318889899 are resolved.
|
| 83 |
+
concatenated_errors = ""
|
| 84 |
+
if errors:
|
| 85 |
+
concatenated_errors = "; "
|
| 86 |
+
for err in errors:
|
| 87 |
+
concatenated_errors += ", ".join(
|
| 88 |
+
[f"{key}: {value}" for key, value in err.items()]
|
| 89 |
+
)
|
| 90 |
+
concatenated_errors += "; "
|
| 91 |
+
|
| 92 |
+
# strips off the last unneeded semicolon and space
|
| 93 |
+
concatenated_errors = concatenated_errors[:-2]
|
| 94 |
+
|
| 95 |
+
error_message = error_result.get("message", "") + concatenated_errors
|
| 96 |
+
|
| 97 |
+
return exceptions.from_http_status(
|
| 98 |
+
status_code, error_message, errors=[error_result]
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
ReservationUsage = namedtuple("ReservationUsage", "name slot_ms")
|
| 103 |
+
ReservationUsage.__doc__ = "Job resource usage for a reservation."
|
| 104 |
+
ReservationUsage.name.__doc__ = (
|
| 105 |
+
'Reservation name or "unreserved" for on-demand resources usage.'
|
| 106 |
+
)
|
| 107 |
+
ReservationUsage.slot_ms.__doc__ = (
|
| 108 |
+
"Total slot milliseconds used by the reservation for a particular job."
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
class TransactionInfo(typing.NamedTuple):
|
| 113 |
+
"""[Alpha] Information of a multi-statement transaction.
|
| 114 |
+
|
| 115 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#TransactionInfo
|
| 116 |
+
|
| 117 |
+
.. versionadded:: 2.24.0
|
| 118 |
+
"""
|
| 119 |
+
|
| 120 |
+
transaction_id: str
|
| 121 |
+
"""Output only. ID of the transaction."""
|
| 122 |
+
|
| 123 |
+
@classmethod
|
| 124 |
+
def from_api_repr(cls, transaction_info: Dict[str, str]) -> "TransactionInfo":
|
| 125 |
+
return cls(transaction_info["transactionId"])
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
class _JobReference(object):
|
| 129 |
+
"""A reference to a job.
|
| 130 |
+
|
| 131 |
+
Args:
|
| 132 |
+
job_id (str): ID of the job to run.
|
| 133 |
+
project (str): ID of the project where the job runs.
|
| 134 |
+
location (str): Location of where the job runs.
|
| 135 |
+
"""
|
| 136 |
+
|
| 137 |
+
def __init__(self, job_id, project, location):
|
| 138 |
+
self._properties = {"jobId": job_id, "projectId": project}
|
| 139 |
+
# The location field must not be populated if it is None.
|
| 140 |
+
if location:
|
| 141 |
+
self._properties["location"] = location
|
| 142 |
+
|
| 143 |
+
@property
|
| 144 |
+
def job_id(self):
|
| 145 |
+
"""str: ID of the job."""
|
| 146 |
+
return self._properties.get("jobId")
|
| 147 |
+
|
| 148 |
+
@property
|
| 149 |
+
def project(self):
|
| 150 |
+
"""str: ID of the project where the job runs."""
|
| 151 |
+
return self._properties.get("projectId")
|
| 152 |
+
|
| 153 |
+
@property
|
| 154 |
+
def location(self):
|
| 155 |
+
"""str: Location where the job runs."""
|
| 156 |
+
return self._properties.get("location")
|
| 157 |
+
|
| 158 |
+
def _to_api_repr(self):
|
| 159 |
+
"""Returns the API resource representation of the job reference."""
|
| 160 |
+
return copy.deepcopy(self._properties)
|
| 161 |
+
|
| 162 |
+
@classmethod
|
| 163 |
+
def _from_api_repr(cls, resource):
|
| 164 |
+
"""Returns a job reference for an API resource representation."""
|
| 165 |
+
job_id = resource.get("jobId")
|
| 166 |
+
project = resource.get("projectId")
|
| 167 |
+
location = resource.get("location")
|
| 168 |
+
job_ref = cls(job_id, project, location)
|
| 169 |
+
return job_ref
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
class _JobConfig(object):
|
| 173 |
+
"""Abstract base class for job configuration objects.
|
| 174 |
+
|
| 175 |
+
Args:
|
| 176 |
+
job_type (str): The key to use for the job configuration.
|
| 177 |
+
"""
|
| 178 |
+
|
| 179 |
+
def __init__(self, job_type, **kwargs):
|
| 180 |
+
self._job_type = job_type
|
| 181 |
+
self._properties = {job_type: {}}
|
| 182 |
+
for prop, val in kwargs.items():
|
| 183 |
+
setattr(self, prop, val)
|
| 184 |
+
|
| 185 |
+
def __setattr__(self, name, value):
|
| 186 |
+
"""Override to be able to raise error if an unknown property is being set"""
|
| 187 |
+
if not name.startswith("_") and not hasattr(type(self), name):
|
| 188 |
+
raise AttributeError(
|
| 189 |
+
"Property {} is unknown for {}.".format(name, type(self))
|
| 190 |
+
)
|
| 191 |
+
super(_JobConfig, self).__setattr__(name, value)
|
| 192 |
+
|
| 193 |
+
@property
|
| 194 |
+
def job_timeout_ms(self):
|
| 195 |
+
"""Optional parameter. Job timeout in milliseconds. If this time limit is exceeded, BigQuery might attempt to stop the job.
|
| 196 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfiguration.FIELDS.job_timeout_ms
|
| 197 |
+
e.g.
|
| 198 |
+
|
| 199 |
+
job_config = bigquery.QueryJobConfig( job_timeout_ms = 5000 )
|
| 200 |
+
or
|
| 201 |
+
job_config.job_timeout_ms = 5000
|
| 202 |
+
|
| 203 |
+
Raises:
|
| 204 |
+
ValueError: If ``value`` type is invalid.
|
| 205 |
+
"""
|
| 206 |
+
|
| 207 |
+
# None as this is an optional parameter.
|
| 208 |
+
if self._properties.get("jobTimeoutMs"):
|
| 209 |
+
return self._properties["jobTimeoutMs"]
|
| 210 |
+
return None
|
| 211 |
+
|
| 212 |
+
@job_timeout_ms.setter
|
| 213 |
+
def job_timeout_ms(self, value):
|
| 214 |
+
try:
|
| 215 |
+
value = _int_or_none(value)
|
| 216 |
+
except ValueError as err:
|
| 217 |
+
raise ValueError("Pass an int for jobTimeoutMs, e.g. 5000").with_traceback(
|
| 218 |
+
err.__traceback__
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
if value is not None:
|
| 222 |
+
# docs indicate a string is expected by the API
|
| 223 |
+
self._properties["jobTimeoutMs"] = str(value)
|
| 224 |
+
else:
|
| 225 |
+
self._properties.pop("jobTimeoutMs", None)
|
| 226 |
+
|
| 227 |
+
@property
|
| 228 |
+
def max_slots(self) -> Optional[int]:
|
| 229 |
+
"""The maximum rate of slot consumption to allow for this job.
|
| 230 |
+
|
| 231 |
+
If set, the number of slots used to execute the job will be throttled
|
| 232 |
+
to try and keep its slot consumption below the requested rate.
|
| 233 |
+
This feature is not generally available.
|
| 234 |
+
"""
|
| 235 |
+
|
| 236 |
+
max_slots = self._properties.get("maxSlots")
|
| 237 |
+
if max_slots is not None:
|
| 238 |
+
if isinstance(max_slots, str):
|
| 239 |
+
return int(max_slots)
|
| 240 |
+
if isinstance(max_slots, int):
|
| 241 |
+
return max_slots
|
| 242 |
+
return None
|
| 243 |
+
|
| 244 |
+
@max_slots.setter
|
| 245 |
+
def max_slots(self, value):
|
| 246 |
+
try:
|
| 247 |
+
value = _int_or_none(value)
|
| 248 |
+
except ValueError as err:
|
| 249 |
+
raise ValueError("Pass an int for max slots, e.g. 100").with_traceback(
|
| 250 |
+
err.__traceback__
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
if value is not None:
|
| 254 |
+
self._properties["maxSlots"] = str(value)
|
| 255 |
+
else:
|
| 256 |
+
self._properties.pop("maxSlots", None)
|
| 257 |
+
|
| 258 |
+
@property
|
| 259 |
+
def reservation(self):
|
| 260 |
+
"""str: Optional. The reservation that job would use.
|
| 261 |
+
|
| 262 |
+
User can specify a reservation to execute the job. If reservation is
|
| 263 |
+
not set, reservation is determined based on the rules defined by the
|
| 264 |
+
reservation assignments. The expected format is
|
| 265 |
+
projects/{project}/locations/{location}/reservations/{reservation}.
|
| 266 |
+
|
| 267 |
+
Raises:
|
| 268 |
+
ValueError: If ``value`` type is not None or of string type.
|
| 269 |
+
"""
|
| 270 |
+
return self._properties.setdefault("reservation", None)
|
| 271 |
+
|
| 272 |
+
@reservation.setter
|
| 273 |
+
def reservation(self, value):
|
| 274 |
+
if value and not isinstance(value, str):
|
| 275 |
+
raise ValueError("Reservation must be None or a string.")
|
| 276 |
+
self._properties["reservation"] = value
|
| 277 |
+
|
| 278 |
+
@property
|
| 279 |
+
def labels(self):
|
| 280 |
+
"""Dict[str, str]: Labels for the job.
|
| 281 |
+
|
| 282 |
+
This method always returns a dict. Once a job has been created on the
|
| 283 |
+
server, its labels cannot be modified anymore.
|
| 284 |
+
|
| 285 |
+
Raises:
|
| 286 |
+
ValueError: If ``value`` type is invalid.
|
| 287 |
+
"""
|
| 288 |
+
return self._properties.setdefault("labels", {})
|
| 289 |
+
|
| 290 |
+
@labels.setter
|
| 291 |
+
def labels(self, value):
|
| 292 |
+
if not isinstance(value, dict):
|
| 293 |
+
raise ValueError("Pass a dict")
|
| 294 |
+
self._properties["labels"] = value
|
| 295 |
+
|
| 296 |
+
def _get_sub_prop(self, key, default=None):
|
| 297 |
+
"""Get a value in the ``self._properties[self._job_type]`` dictionary.
|
| 298 |
+
|
| 299 |
+
Most job properties are inside the dictionary related to the job type
|
| 300 |
+
(e.g. 'copy', 'extract', 'load', 'query'). Use this method to access
|
| 301 |
+
those properties::
|
| 302 |
+
|
| 303 |
+
self._get_sub_prop('destinationTable')
|
| 304 |
+
|
| 305 |
+
This is equivalent to using the ``_helpers._get_sub_prop`` function::
|
| 306 |
+
|
| 307 |
+
_helpers._get_sub_prop(
|
| 308 |
+
self._properties, ['query', 'destinationTable'])
|
| 309 |
+
|
| 310 |
+
Args:
|
| 311 |
+
key (str):
|
| 312 |
+
Key for the value to get in the
|
| 313 |
+
``self._properties[self._job_type]`` dictionary.
|
| 314 |
+
default (Optional[object]):
|
| 315 |
+
Default value to return if the key is not found.
|
| 316 |
+
Defaults to :data:`None`.
|
| 317 |
+
|
| 318 |
+
Returns:
|
| 319 |
+
object: The value if present or the default.
|
| 320 |
+
"""
|
| 321 |
+
return _helpers._get_sub_prop(
|
| 322 |
+
self._properties, [self._job_type, key], default=default
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
def _set_sub_prop(self, key, value):
|
| 326 |
+
"""Set a value in the ``self._properties[self._job_type]`` dictionary.
|
| 327 |
+
|
| 328 |
+
Most job properties are inside the dictionary related to the job type
|
| 329 |
+
(e.g. 'copy', 'extract', 'load', 'query'). Use this method to set
|
| 330 |
+
those properties::
|
| 331 |
+
|
| 332 |
+
self._set_sub_prop('useLegacySql', False)
|
| 333 |
+
|
| 334 |
+
This is equivalent to using the ``_helper._set_sub_prop`` function::
|
| 335 |
+
|
| 336 |
+
_helper._set_sub_prop(
|
| 337 |
+
self._properties, ['query', 'useLegacySql'], False)
|
| 338 |
+
|
| 339 |
+
Args:
|
| 340 |
+
key (str):
|
| 341 |
+
Key to set in the ``self._properties[self._job_type]``
|
| 342 |
+
dictionary.
|
| 343 |
+
value (object): Value to set.
|
| 344 |
+
"""
|
| 345 |
+
_helpers._set_sub_prop(self._properties, [self._job_type, key], value)
|
| 346 |
+
|
| 347 |
+
def _del_sub_prop(self, key):
|
| 348 |
+
"""Remove ``key`` from the ``self._properties[self._job_type]`` dict.
|
| 349 |
+
|
| 350 |
+
Most job properties are inside the dictionary related to the job type
|
| 351 |
+
(e.g. 'copy', 'extract', 'load', 'query'). Use this method to clear
|
| 352 |
+
those properties::
|
| 353 |
+
|
| 354 |
+
self._del_sub_prop('useLegacySql')
|
| 355 |
+
|
| 356 |
+
This is equivalent to using the ``_helper._del_sub_prop`` function::
|
| 357 |
+
|
| 358 |
+
_helper._del_sub_prop(
|
| 359 |
+
self._properties, ['query', 'useLegacySql'])
|
| 360 |
+
|
| 361 |
+
Args:
|
| 362 |
+
key (str):
|
| 363 |
+
Key to remove in the ``self._properties[self._job_type]``
|
| 364 |
+
dictionary.
|
| 365 |
+
"""
|
| 366 |
+
_helpers._del_sub_prop(self._properties, [self._job_type, key])
|
| 367 |
+
|
| 368 |
+
def to_api_repr(self) -> dict:
|
| 369 |
+
"""Build an API representation of the job config.
|
| 370 |
+
|
| 371 |
+
Returns:
|
| 372 |
+
Dict: A dictionary in the format used by the BigQuery API.
|
| 373 |
+
"""
|
| 374 |
+
return copy.deepcopy(self._properties)
|
| 375 |
+
|
| 376 |
+
def _fill_from_default(self, default_job_config=None):
|
| 377 |
+
"""Merge this job config with a default job config.
|
| 378 |
+
|
| 379 |
+
The keys in this object take precedence over the keys in the default
|
| 380 |
+
config. The merge is done at the top-level as well as for keys one
|
| 381 |
+
level below the job type.
|
| 382 |
+
|
| 383 |
+
Args:
|
| 384 |
+
default_job_config (google.cloud.bigquery.job._JobConfig):
|
| 385 |
+
The default job config that will be used to fill in self.
|
| 386 |
+
|
| 387 |
+
Returns:
|
| 388 |
+
google.cloud.bigquery.job._JobConfig: A new (merged) job config.
|
| 389 |
+
"""
|
| 390 |
+
if not default_job_config:
|
| 391 |
+
new_job_config = copy.deepcopy(self)
|
| 392 |
+
return new_job_config
|
| 393 |
+
|
| 394 |
+
if self._job_type != default_job_config._job_type:
|
| 395 |
+
raise TypeError(
|
| 396 |
+
"attempted to merge two incompatible job types: "
|
| 397 |
+
+ repr(self._job_type)
|
| 398 |
+
+ ", "
|
| 399 |
+
+ repr(default_job_config._job_type)
|
| 400 |
+
)
|
| 401 |
+
|
| 402 |
+
# cls is one of the job config subclasses that provides the job_type argument to
|
| 403 |
+
# this base class on instantiation, thus missing-parameter warning is a false
|
| 404 |
+
# positive here.
|
| 405 |
+
new_job_config = self.__class__() # pytype: disable=missing-parameter
|
| 406 |
+
|
| 407 |
+
default_job_properties = copy.deepcopy(default_job_config._properties)
|
| 408 |
+
for key in self._properties:
|
| 409 |
+
if key != self._job_type:
|
| 410 |
+
default_job_properties[key] = self._properties[key]
|
| 411 |
+
|
| 412 |
+
default_job_properties[self._job_type].update(self._properties[self._job_type])
|
| 413 |
+
new_job_config._properties = default_job_properties
|
| 414 |
+
|
| 415 |
+
return new_job_config
|
| 416 |
+
|
| 417 |
+
@classmethod
|
| 418 |
+
def from_api_repr(cls, resource: dict) -> "_JobConfig":
|
| 419 |
+
"""Factory: construct a job configuration given its API representation
|
| 420 |
+
|
| 421 |
+
Args:
|
| 422 |
+
resource (Dict):
|
| 423 |
+
A job configuration in the same representation as is returned
|
| 424 |
+
from the API.
|
| 425 |
+
|
| 426 |
+
Returns:
|
| 427 |
+
google.cloud.bigquery.job._JobConfig: Configuration parsed from ``resource``.
|
| 428 |
+
"""
|
| 429 |
+
# cls is one of the job config subclasses that provides the job_type argument to
|
| 430 |
+
# this base class on instantiation, thus missing-parameter warning is a false
|
| 431 |
+
# positive here.
|
| 432 |
+
job_config = cls() # type: ignore # pytype: disable=missing-parameter
|
| 433 |
+
job_config._properties = resource
|
| 434 |
+
return job_config
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
class _AsyncJob(google.api_core.future.polling.PollingFuture):
|
| 438 |
+
"""Base class for asynchronous jobs.
|
| 439 |
+
|
| 440 |
+
Args:
|
| 441 |
+
job_id (Union[str, _JobReference]):
|
| 442 |
+
Job's ID in the project associated with the client or a
|
| 443 |
+
fully-qualified job reference.
|
| 444 |
+
client (google.cloud.bigquery.client.Client):
|
| 445 |
+
Client which holds credentials and project configuration.
|
| 446 |
+
"""
|
| 447 |
+
|
| 448 |
+
_JOB_TYPE = "unknown"
|
| 449 |
+
_CONFIG_CLASS: ClassVar
|
| 450 |
+
|
| 451 |
+
def __init__(self, job_id, client):
|
| 452 |
+
super(_AsyncJob, self).__init__()
|
| 453 |
+
|
| 454 |
+
# The job reference can be either a plain job ID or the full resource.
|
| 455 |
+
# Populate the properties dictionary consistently depending on what has
|
| 456 |
+
# been passed in.
|
| 457 |
+
job_ref = job_id
|
| 458 |
+
if not isinstance(job_id, _JobReference):
|
| 459 |
+
job_ref = _JobReference(job_id, client.project, None)
|
| 460 |
+
self._properties = {"jobReference": job_ref._to_api_repr()}
|
| 461 |
+
|
| 462 |
+
self._client = client
|
| 463 |
+
self._result_set = False
|
| 464 |
+
self._completion_lock = threading.Lock()
|
| 465 |
+
|
| 466 |
+
@property
|
| 467 |
+
def configuration(self) -> _JobConfig:
|
| 468 |
+
"""Job-type specific configurtion."""
|
| 469 |
+
configuration: _JobConfig = self._CONFIG_CLASS() # pytype: disable=not-callable
|
| 470 |
+
configuration._properties = self._properties.setdefault("configuration", {})
|
| 471 |
+
return configuration
|
| 472 |
+
|
| 473 |
+
@property
|
| 474 |
+
def job_id(self):
|
| 475 |
+
"""str: ID of the job."""
|
| 476 |
+
return _helpers._get_sub_prop(self._properties, ["jobReference", "jobId"])
|
| 477 |
+
|
| 478 |
+
@property
|
| 479 |
+
def parent_job_id(self):
|
| 480 |
+
"""Return the ID of the parent job.
|
| 481 |
+
|
| 482 |
+
See:
|
| 483 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobStatistics.FIELDS.parent_job_id
|
| 484 |
+
|
| 485 |
+
Returns:
|
| 486 |
+
Optional[str]: parent job id.
|
| 487 |
+
"""
|
| 488 |
+
return _helpers._get_sub_prop(self._properties, ["statistics", "parentJobId"])
|
| 489 |
+
|
| 490 |
+
@property
|
| 491 |
+
def script_statistics(self) -> Optional["ScriptStatistics"]:
|
| 492 |
+
"""Statistics for a child job of a script."""
|
| 493 |
+
resource = _helpers._get_sub_prop(
|
| 494 |
+
self._properties, ["statistics", "scriptStatistics"]
|
| 495 |
+
)
|
| 496 |
+
if resource is None:
|
| 497 |
+
return None
|
| 498 |
+
return ScriptStatistics(resource)
|
| 499 |
+
|
| 500 |
+
@property
|
| 501 |
+
def session_info(self) -> Optional["SessionInfo"]:
|
| 502 |
+
"""[Preview] Information of the session if this job is part of one.
|
| 503 |
+
|
| 504 |
+
.. versionadded:: 2.29.0
|
| 505 |
+
"""
|
| 506 |
+
resource = _helpers._get_sub_prop(
|
| 507 |
+
self._properties, ["statistics", "sessionInfo"]
|
| 508 |
+
)
|
| 509 |
+
if resource is None:
|
| 510 |
+
return None
|
| 511 |
+
return SessionInfo(resource)
|
| 512 |
+
|
| 513 |
+
@property
|
| 514 |
+
def num_child_jobs(self):
|
| 515 |
+
"""The number of child jobs executed.
|
| 516 |
+
|
| 517 |
+
See:
|
| 518 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobStatistics.FIELDS.num_child_jobs
|
| 519 |
+
|
| 520 |
+
Returns:
|
| 521 |
+
int
|
| 522 |
+
"""
|
| 523 |
+
count = _helpers._get_sub_prop(self._properties, ["statistics", "numChildJobs"])
|
| 524 |
+
return int(count) if count is not None else 0
|
| 525 |
+
|
| 526 |
+
@property
|
| 527 |
+
def project(self):
|
| 528 |
+
"""Project bound to the job.
|
| 529 |
+
|
| 530 |
+
Returns:
|
| 531 |
+
str: the project (derived from the client).
|
| 532 |
+
"""
|
| 533 |
+
return _helpers._get_sub_prop(self._properties, ["jobReference", "projectId"])
|
| 534 |
+
|
| 535 |
+
@property
|
| 536 |
+
def location(self):
|
| 537 |
+
"""str: Location where the job runs."""
|
| 538 |
+
return _helpers._get_sub_prop(self._properties, ["jobReference", "location"])
|
| 539 |
+
|
| 540 |
+
@property
|
| 541 |
+
def reservation_id(self):
|
| 542 |
+
"""str: Name of the primary reservation assigned to this job.
|
| 543 |
+
|
| 544 |
+
Note that this could be different than reservations reported in
|
| 545 |
+
the reservation field if parent reservations were used to execute
|
| 546 |
+
this job.
|
| 547 |
+
"""
|
| 548 |
+
return _helpers._get_sub_prop(
|
| 549 |
+
self._properties, ["statistics", "reservation_id"]
|
| 550 |
+
)
|
| 551 |
+
|
| 552 |
+
def _require_client(self, client):
|
| 553 |
+
"""Check client or verify over-ride.
|
| 554 |
+
|
| 555 |
+
Args:
|
| 556 |
+
client (Optional[google.cloud.bigquery.client.Client]):
|
| 557 |
+
the client to use. If not passed, falls back to the
|
| 558 |
+
``client`` stored on the current dataset.
|
| 559 |
+
|
| 560 |
+
Returns:
|
| 561 |
+
google.cloud.bigquery.client.Client:
|
| 562 |
+
The client passed in or the currently bound client.
|
| 563 |
+
"""
|
| 564 |
+
if client is None:
|
| 565 |
+
client = self._client
|
| 566 |
+
return client
|
| 567 |
+
|
| 568 |
+
@property
|
| 569 |
+
def job_type(self):
|
| 570 |
+
"""Type of job.
|
| 571 |
+
|
| 572 |
+
Returns:
|
| 573 |
+
str: one of 'load', 'copy', 'extract', 'query'.
|
| 574 |
+
"""
|
| 575 |
+
return self._JOB_TYPE
|
| 576 |
+
|
| 577 |
+
@property
|
| 578 |
+
def path(self):
|
| 579 |
+
"""URL path for the job's APIs.
|
| 580 |
+
|
| 581 |
+
Returns:
|
| 582 |
+
str: the path based on project and job ID.
|
| 583 |
+
"""
|
| 584 |
+
return "/projects/%s/jobs/%s" % (self.project, self.job_id)
|
| 585 |
+
|
| 586 |
+
@property
|
| 587 |
+
def labels(self):
|
| 588 |
+
"""Dict[str, str]: Labels for the job."""
|
| 589 |
+
return self._properties.setdefault("configuration", {}).setdefault("labels", {})
|
| 590 |
+
|
| 591 |
+
@property
|
| 592 |
+
def etag(self):
|
| 593 |
+
"""ETag for the job resource.
|
| 594 |
+
|
| 595 |
+
Returns:
|
| 596 |
+
Optional[str]: the ETag (None until set from the server).
|
| 597 |
+
"""
|
| 598 |
+
return self._properties.get("etag")
|
| 599 |
+
|
| 600 |
+
@property
|
| 601 |
+
def self_link(self):
|
| 602 |
+
"""URL for the job resource.
|
| 603 |
+
|
| 604 |
+
Returns:
|
| 605 |
+
Optional[str]: the URL (None until set from the server).
|
| 606 |
+
"""
|
| 607 |
+
return self._properties.get("selfLink")
|
| 608 |
+
|
| 609 |
+
@property
|
| 610 |
+
def user_email(self):
|
| 611 |
+
"""E-mail address of user who submitted the job.
|
| 612 |
+
|
| 613 |
+
Returns:
|
| 614 |
+
Optional[str]: the URL (None until set from the server).
|
| 615 |
+
"""
|
| 616 |
+
return self._properties.get("user_email")
|
| 617 |
+
|
| 618 |
+
@property
|
| 619 |
+
def created(self):
|
| 620 |
+
"""Datetime at which the job was created.
|
| 621 |
+
|
| 622 |
+
Returns:
|
| 623 |
+
Optional[datetime.datetime]:
|
| 624 |
+
the creation time (None until set from the server).
|
| 625 |
+
"""
|
| 626 |
+
millis = _helpers._get_sub_prop(
|
| 627 |
+
self._properties, ["statistics", "creationTime"]
|
| 628 |
+
)
|
| 629 |
+
if millis is not None:
|
| 630 |
+
return _helpers._datetime_from_microseconds(millis * 1000.0)
|
| 631 |
+
|
| 632 |
+
@property
|
| 633 |
+
def started(self):
|
| 634 |
+
"""Datetime at which the job was started.
|
| 635 |
+
|
| 636 |
+
Returns:
|
| 637 |
+
Optional[datetime.datetime]:
|
| 638 |
+
the start time (None until set from the server).
|
| 639 |
+
"""
|
| 640 |
+
millis = _helpers._get_sub_prop(self._properties, ["statistics", "startTime"])
|
| 641 |
+
if millis is not None:
|
| 642 |
+
return _helpers._datetime_from_microseconds(millis * 1000.0)
|
| 643 |
+
|
| 644 |
+
@property
|
| 645 |
+
def ended(self):
|
| 646 |
+
"""Datetime at which the job finished.
|
| 647 |
+
|
| 648 |
+
Returns:
|
| 649 |
+
Optional[datetime.datetime]:
|
| 650 |
+
the end time (None until set from the server).
|
| 651 |
+
"""
|
| 652 |
+
millis = _helpers._get_sub_prop(self._properties, ["statistics", "endTime"])
|
| 653 |
+
if millis is not None:
|
| 654 |
+
return _helpers._datetime_from_microseconds(millis * 1000.0)
|
| 655 |
+
|
| 656 |
+
def _job_statistics(self):
|
| 657 |
+
"""Helper for job-type specific statistics-based properties."""
|
| 658 |
+
statistics = self._properties.get("statistics", {})
|
| 659 |
+
return statistics.get(self._JOB_TYPE, {})
|
| 660 |
+
|
| 661 |
+
@property
|
| 662 |
+
def reservation_usage(self):
|
| 663 |
+
"""Job resource usage breakdown by reservation.
|
| 664 |
+
|
| 665 |
+
Returns:
|
| 666 |
+
List[google.cloud.bigquery.job.ReservationUsage]:
|
| 667 |
+
Reservation usage stats. Can be empty if not set from the server.
|
| 668 |
+
"""
|
| 669 |
+
usage_stats_raw = _helpers._get_sub_prop(
|
| 670 |
+
self._properties, ["statistics", "reservationUsage"], default=()
|
| 671 |
+
)
|
| 672 |
+
return [
|
| 673 |
+
ReservationUsage(name=usage["name"], slot_ms=int(usage["slotMs"]))
|
| 674 |
+
for usage in usage_stats_raw
|
| 675 |
+
]
|
| 676 |
+
|
| 677 |
+
@property
|
| 678 |
+
def transaction_info(self) -> Optional[TransactionInfo]:
|
| 679 |
+
"""Information of the multi-statement transaction if this job is part of one.
|
| 680 |
+
|
| 681 |
+
Since a scripting query job can execute multiple transactions, this
|
| 682 |
+
property is only expected on child jobs. Use the
|
| 683 |
+
:meth:`google.cloud.bigquery.client.Client.list_jobs` method with the
|
| 684 |
+
``parent_job`` parameter to iterate over child jobs.
|
| 685 |
+
|
| 686 |
+
.. versionadded:: 2.24.0
|
| 687 |
+
"""
|
| 688 |
+
info = self._properties.get("statistics", {}).get("transactionInfo")
|
| 689 |
+
if info is None:
|
| 690 |
+
return None
|
| 691 |
+
else:
|
| 692 |
+
return TransactionInfo.from_api_repr(info)
|
| 693 |
+
|
| 694 |
+
@property
|
| 695 |
+
def error_result(self):
|
| 696 |
+
"""Output only. Final error result of the job.
|
| 697 |
+
|
| 698 |
+
If present, indicates that the job has completed and was unsuccessful.
|
| 699 |
+
|
| 700 |
+
See:
|
| 701 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobStatus.FIELDS.error_result
|
| 702 |
+
|
| 703 |
+
Returns:
|
| 704 |
+
Optional[Mapping]: the error information (None until set from the server).
|
| 705 |
+
"""
|
| 706 |
+
status = self._properties.get("status")
|
| 707 |
+
if status is not None:
|
| 708 |
+
return status.get("errorResult")
|
| 709 |
+
|
| 710 |
+
@property
|
| 711 |
+
def errors(self):
|
| 712 |
+
"""Output only. The first errors encountered during the running of the job.
|
| 713 |
+
|
| 714 |
+
The final message includes the number of errors that caused the process to stop.
|
| 715 |
+
Errors here do not necessarily mean that the job has not completed or was unsuccessful.
|
| 716 |
+
|
| 717 |
+
See:
|
| 718 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobStatus.FIELDS.errors
|
| 719 |
+
|
| 720 |
+
Returns:
|
| 721 |
+
Optional[List[Mapping]]:
|
| 722 |
+
the error information (None until set from the server).
|
| 723 |
+
"""
|
| 724 |
+
status = self._properties.get("status")
|
| 725 |
+
if status is not None:
|
| 726 |
+
return status.get("errors")
|
| 727 |
+
|
| 728 |
+
@property
|
| 729 |
+
def state(self):
|
| 730 |
+
"""Output only. Running state of the job.
|
| 731 |
+
|
| 732 |
+
Valid states include 'PENDING', 'RUNNING', and 'DONE'.
|
| 733 |
+
|
| 734 |
+
See:
|
| 735 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobStatus.FIELDS.state
|
| 736 |
+
|
| 737 |
+
Returns:
|
| 738 |
+
Optional[str]:
|
| 739 |
+
the state (None until set from the server).
|
| 740 |
+
"""
|
| 741 |
+
status = self._properties.get("status", {})
|
| 742 |
+
return status.get("state")
|
| 743 |
+
|
| 744 |
+
def _set_properties(self, api_response):
|
| 745 |
+
"""Update properties from resource in body of ``api_response``
|
| 746 |
+
|
| 747 |
+
Args:
|
| 748 |
+
api_response (Dict): response returned from an API call.
|
| 749 |
+
"""
|
| 750 |
+
cleaned = api_response.copy()
|
| 751 |
+
statistics = cleaned.setdefault("statistics", {})
|
| 752 |
+
if "creationTime" in statistics:
|
| 753 |
+
statistics["creationTime"] = float(statistics["creationTime"])
|
| 754 |
+
if "startTime" in statistics:
|
| 755 |
+
statistics["startTime"] = float(statistics["startTime"])
|
| 756 |
+
if "endTime" in statistics:
|
| 757 |
+
statistics["endTime"] = float(statistics["endTime"])
|
| 758 |
+
|
| 759 |
+
self._properties = cleaned
|
| 760 |
+
|
| 761 |
+
# For Future interface
|
| 762 |
+
self._set_future_result()
|
| 763 |
+
|
| 764 |
+
@classmethod
|
| 765 |
+
def _check_resource_config(cls, resource):
|
| 766 |
+
"""Helper for :meth:`from_api_repr`
|
| 767 |
+
|
| 768 |
+
Args:
|
| 769 |
+
resource (Dict): resource for the job.
|
| 770 |
+
|
| 771 |
+
Raises:
|
| 772 |
+
KeyError:
|
| 773 |
+
If the resource has no identifier, or
|
| 774 |
+
is missing the appropriate configuration.
|
| 775 |
+
"""
|
| 776 |
+
if "jobReference" not in resource or "jobId" not in resource["jobReference"]:
|
| 777 |
+
raise KeyError(
|
| 778 |
+
"Resource lacks required identity information: "
|
| 779 |
+
'["jobReference"]["jobId"]'
|
| 780 |
+
)
|
| 781 |
+
if (
|
| 782 |
+
"configuration" not in resource
|
| 783 |
+
or cls._JOB_TYPE not in resource["configuration"]
|
| 784 |
+
):
|
| 785 |
+
raise KeyError(
|
| 786 |
+
"Resource lacks required configuration: "
|
| 787 |
+
'["configuration"]["%s"]' % cls._JOB_TYPE
|
| 788 |
+
)
|
| 789 |
+
|
| 790 |
+
def to_api_repr(self):
|
| 791 |
+
"""Generate a resource for the job."""
|
| 792 |
+
return copy.deepcopy(self._properties)
|
| 793 |
+
|
| 794 |
+
_build_resource = to_api_repr # backward-compatibility alias
|
| 795 |
+
|
| 796 |
+
def _begin(self, client=None, retry=DEFAULT_RETRY, timeout=None):
|
| 797 |
+
"""API call: begin the job via a POST request
|
| 798 |
+
|
| 799 |
+
See
|
| 800 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/insert
|
| 801 |
+
|
| 802 |
+
Args:
|
| 803 |
+
client (Optional[google.cloud.bigquery.client.Client]):
|
| 804 |
+
The client to use. If not passed, falls back to the ``client``
|
| 805 |
+
associated with the job object or``NoneType``
|
| 806 |
+
retry (Optional[google.api_core.retry.Retry]):
|
| 807 |
+
How to retry the RPC.
|
| 808 |
+
timeout (Optional[float]):
|
| 809 |
+
The number of seconds to wait for the underlying HTTP transport
|
| 810 |
+
before using ``retry``.
|
| 811 |
+
|
| 812 |
+
Raises:
|
| 813 |
+
ValueError:
|
| 814 |
+
If the job has already begun.
|
| 815 |
+
"""
|
| 816 |
+
if self.state is not None:
|
| 817 |
+
raise ValueError("Job already begun.")
|
| 818 |
+
|
| 819 |
+
client = self._require_client(client)
|
| 820 |
+
path = "/projects/%s/jobs" % (self.project,)
|
| 821 |
+
|
| 822 |
+
# jobs.insert is idempotent because we ensure that every new
|
| 823 |
+
# job has an ID.
|
| 824 |
+
span_attributes = {"path": path}
|
| 825 |
+
api_response = client._call_api(
|
| 826 |
+
retry,
|
| 827 |
+
span_name="BigQuery.job.begin",
|
| 828 |
+
span_attributes=span_attributes,
|
| 829 |
+
job_ref=self,
|
| 830 |
+
method="POST",
|
| 831 |
+
path=path,
|
| 832 |
+
data=self.to_api_repr(),
|
| 833 |
+
timeout=timeout,
|
| 834 |
+
)
|
| 835 |
+
self._set_properties(api_response)
|
| 836 |
+
|
| 837 |
+
def exists(
|
| 838 |
+
self,
|
| 839 |
+
client=None,
|
| 840 |
+
retry: "retries.Retry" = DEFAULT_RETRY,
|
| 841 |
+
timeout: Optional[float] = None,
|
| 842 |
+
) -> bool:
|
| 843 |
+
"""API call: test for the existence of the job via a GET request
|
| 844 |
+
|
| 845 |
+
See
|
| 846 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/get
|
| 847 |
+
|
| 848 |
+
Args:
|
| 849 |
+
client (Optional[google.cloud.bigquery.client.Client]):
|
| 850 |
+
the client to use. If not passed, falls back to the
|
| 851 |
+
``client`` stored on the current dataset.
|
| 852 |
+
|
| 853 |
+
retry (Optional[google.api_core.retry.Retry]): How to retry the RPC.
|
| 854 |
+
timeout (Optional[float]):
|
| 855 |
+
The number of seconds to wait for the underlying HTTP transport
|
| 856 |
+
before using ``retry``.
|
| 857 |
+
|
| 858 |
+
Returns:
|
| 859 |
+
bool: Boolean indicating existence of the job.
|
| 860 |
+
"""
|
| 861 |
+
client = self._require_client(client)
|
| 862 |
+
|
| 863 |
+
extra_params = {"fields": "id"}
|
| 864 |
+
if self.location:
|
| 865 |
+
extra_params["location"] = self.location
|
| 866 |
+
|
| 867 |
+
try:
|
| 868 |
+
span_attributes = {"path": self.path}
|
| 869 |
+
|
| 870 |
+
client._call_api(
|
| 871 |
+
retry,
|
| 872 |
+
span_name="BigQuery.job.exists",
|
| 873 |
+
span_attributes=span_attributes,
|
| 874 |
+
job_ref=self,
|
| 875 |
+
method="GET",
|
| 876 |
+
path=self.path,
|
| 877 |
+
query_params=extra_params,
|
| 878 |
+
timeout=timeout,
|
| 879 |
+
)
|
| 880 |
+
except exceptions.NotFound:
|
| 881 |
+
return False
|
| 882 |
+
else:
|
| 883 |
+
return True
|
| 884 |
+
|
| 885 |
+
def reload(
|
| 886 |
+
self,
|
| 887 |
+
client=None,
|
| 888 |
+
retry: "retries.Retry" = DEFAULT_RETRY,
|
| 889 |
+
timeout: Optional[float] = DEFAULT_GET_JOB_TIMEOUT,
|
| 890 |
+
):
|
| 891 |
+
"""API call: refresh job properties via a GET request.
|
| 892 |
+
|
| 893 |
+
See
|
| 894 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/get
|
| 895 |
+
|
| 896 |
+
Args:
|
| 897 |
+
client (Optional[google.cloud.bigquery.client.Client]):
|
| 898 |
+
the client to use. If not passed, falls back to the
|
| 899 |
+
``client`` stored on the current dataset.
|
| 900 |
+
|
| 901 |
+
retry (Optional[google.api_core.retry.Retry]): How to retry the RPC.
|
| 902 |
+
timeout (Optional[float]):
|
| 903 |
+
The number of seconds to wait for the underlying HTTP transport
|
| 904 |
+
before using ``retry``.
|
| 905 |
+
"""
|
| 906 |
+
client = self._require_client(client)
|
| 907 |
+
|
| 908 |
+
got_job = client.get_job(
|
| 909 |
+
self,
|
| 910 |
+
project=self.project,
|
| 911 |
+
location=self.location,
|
| 912 |
+
retry=retry,
|
| 913 |
+
timeout=timeout,
|
| 914 |
+
)
|
| 915 |
+
self._set_properties(got_job._properties)
|
| 916 |
+
|
| 917 |
+
def cancel(
|
| 918 |
+
self,
|
| 919 |
+
client=None,
|
| 920 |
+
retry: Optional[retries.Retry] = DEFAULT_RETRY,
|
| 921 |
+
timeout: Optional[float] = None,
|
| 922 |
+
) -> bool:
|
| 923 |
+
"""API call: cancel job via a POST request
|
| 924 |
+
|
| 925 |
+
See
|
| 926 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/cancel
|
| 927 |
+
|
| 928 |
+
Args:
|
| 929 |
+
client (Optional[google.cloud.bigquery.client.Client]):
|
| 930 |
+
the client to use. If not passed, falls back to the
|
| 931 |
+
``client`` stored on the current dataset.
|
| 932 |
+
retry (Optional[google.api_core.retry.Retry]): How to retry the RPC.
|
| 933 |
+
timeout (Optional[float]):
|
| 934 |
+
The number of seconds to wait for the underlying HTTP transport
|
| 935 |
+
before using ``retry``
|
| 936 |
+
|
| 937 |
+
Returns:
|
| 938 |
+
bool: Boolean indicating that the cancel request was sent.
|
| 939 |
+
"""
|
| 940 |
+
client = self._require_client(client)
|
| 941 |
+
|
| 942 |
+
extra_params = {}
|
| 943 |
+
if self.location:
|
| 944 |
+
extra_params["location"] = self.location
|
| 945 |
+
|
| 946 |
+
path = "{}/cancel".format(self.path)
|
| 947 |
+
span_attributes = {"path": path}
|
| 948 |
+
|
| 949 |
+
api_response = client._call_api(
|
| 950 |
+
retry,
|
| 951 |
+
span_name="BigQuery.job.cancel",
|
| 952 |
+
span_attributes=span_attributes,
|
| 953 |
+
job_ref=self,
|
| 954 |
+
method="POST",
|
| 955 |
+
path=path,
|
| 956 |
+
query_params=extra_params,
|
| 957 |
+
timeout=timeout,
|
| 958 |
+
)
|
| 959 |
+
self._set_properties(api_response["job"])
|
| 960 |
+
# The Future interface requires that we return True if the *attempt*
|
| 961 |
+
# to cancel was successful.
|
| 962 |
+
return True
|
| 963 |
+
|
| 964 |
+
# The following methods implement the PollingFuture interface. Note that
|
| 965 |
+
# the methods above are from the pre-Future interface and are left for
|
| 966 |
+
# compatibility. The only "overloaded" method is :meth:`cancel`, which
|
| 967 |
+
# satisfies both interfaces.
|
| 968 |
+
|
| 969 |
+
def _set_future_result(self):
|
| 970 |
+
"""Set the result or exception from the job if it is complete."""
|
| 971 |
+
# This must be done in a lock to prevent the polling thread
|
| 972 |
+
# and main thread from both executing the completion logic
|
| 973 |
+
# at the same time.
|
| 974 |
+
with self._completion_lock:
|
| 975 |
+
# If the operation isn't complete or if the result has already been
|
| 976 |
+
# set, do not call set_result/set_exception again.
|
| 977 |
+
# Note: self._result_set is set to True in set_result and
|
| 978 |
+
# set_exception, in case those methods are invoked directly.
|
| 979 |
+
if not self.done(reload=False) or self._result_set:
|
| 980 |
+
return
|
| 981 |
+
|
| 982 |
+
if self.error_result is not None:
|
| 983 |
+
exception = _error_result_to_exception(
|
| 984 |
+
self.error_result, self.errors or ()
|
| 985 |
+
)
|
| 986 |
+
self.set_exception(exception)
|
| 987 |
+
else:
|
| 988 |
+
self.set_result(self)
|
| 989 |
+
|
| 990 |
+
def done(
|
| 991 |
+
self,
|
| 992 |
+
retry: "retries.Retry" = DEFAULT_RETRY,
|
| 993 |
+
timeout: Optional[float] = DEFAULT_GET_JOB_TIMEOUT,
|
| 994 |
+
reload: bool = True,
|
| 995 |
+
) -> bool:
|
| 996 |
+
"""Checks if the job is complete.
|
| 997 |
+
|
| 998 |
+
Args:
|
| 999 |
+
retry (Optional[google.api_core.retry.Retry]):
|
| 1000 |
+
How to retry the RPC. If the job state is ``DONE``, retrying is aborted
|
| 1001 |
+
early, as the job will not change anymore.
|
| 1002 |
+
timeout (Optional[float]):
|
| 1003 |
+
The number of seconds to wait for the underlying HTTP transport
|
| 1004 |
+
before using ``retry``.
|
| 1005 |
+
reload (Optional[bool]):
|
| 1006 |
+
If ``True``, make an API call to refresh the job state of
|
| 1007 |
+
unfinished jobs before checking. Default ``True``.
|
| 1008 |
+
|
| 1009 |
+
Returns:
|
| 1010 |
+
bool: True if the job is complete, False otherwise.
|
| 1011 |
+
"""
|
| 1012 |
+
# Do not refresh is the state is already done, as the job will not
|
| 1013 |
+
# change once complete.
|
| 1014 |
+
if self.state != _DONE_STATE and reload:
|
| 1015 |
+
self.reload(retry=retry, timeout=timeout)
|
| 1016 |
+
return self.state == _DONE_STATE
|
| 1017 |
+
|
| 1018 |
+
def result( # type: ignore # (incompatible with supertype)
|
| 1019 |
+
self,
|
| 1020 |
+
retry: Optional[retries.Retry] = DEFAULT_RETRY,
|
| 1021 |
+
timeout: Optional[float] = None,
|
| 1022 |
+
) -> "_AsyncJob":
|
| 1023 |
+
"""Start the job and wait for it to complete and get the result.
|
| 1024 |
+
|
| 1025 |
+
Args:
|
| 1026 |
+
retry (Optional[google.api_core.retry.Retry]):
|
| 1027 |
+
How to retry the RPC. If the job state is ``DONE``, retrying is aborted
|
| 1028 |
+
early, as the job will not change anymore.
|
| 1029 |
+
timeout (Optional[float]):
|
| 1030 |
+
The number of seconds to wait for the underlying HTTP transport
|
| 1031 |
+
before using ``retry``.
|
| 1032 |
+
If multiple requests are made under the hood, ``timeout``
|
| 1033 |
+
applies to each individual request.
|
| 1034 |
+
|
| 1035 |
+
Returns:
|
| 1036 |
+
_AsyncJob: This instance.
|
| 1037 |
+
|
| 1038 |
+
Raises:
|
| 1039 |
+
google.cloud.exceptions.GoogleAPICallError:
|
| 1040 |
+
if the job failed.
|
| 1041 |
+
concurrent.futures.TimeoutError:
|
| 1042 |
+
if the job did not complete in the given timeout.
|
| 1043 |
+
"""
|
| 1044 |
+
if self.state is None:
|
| 1045 |
+
self._begin(retry=retry, timeout=timeout)
|
| 1046 |
+
|
| 1047 |
+
return super(_AsyncJob, self).result(timeout=timeout, retry=retry)
|
| 1048 |
+
|
| 1049 |
+
def cancelled(self):
|
| 1050 |
+
"""Check if the job has been cancelled.
|
| 1051 |
+
|
| 1052 |
+
This always returns False. It's not possible to check if a job was
|
| 1053 |
+
cancelled in the API. This method is here to satisfy the interface
|
| 1054 |
+
for :class:`google.api_core.future.Future`.
|
| 1055 |
+
|
| 1056 |
+
Returns:
|
| 1057 |
+
bool: False
|
| 1058 |
+
"""
|
| 1059 |
+
return (
|
| 1060 |
+
self.error_result is not None
|
| 1061 |
+
and self.error_result.get("reason") == _STOPPED_REASON
|
| 1062 |
+
)
|
| 1063 |
+
|
| 1064 |
+
def __repr__(self):
|
| 1065 |
+
result = (
|
| 1066 |
+
f"{self.__class__.__name__}<"
|
| 1067 |
+
f"project={self.project}, location={self.location}, id={self.job_id}"
|
| 1068 |
+
">"
|
| 1069 |
+
)
|
| 1070 |
+
return result
|
| 1071 |
+
|
| 1072 |
+
|
| 1073 |
+
class ScriptStackFrame(object):
|
| 1074 |
+
"""Stack frame showing the line/column/procedure name where the current
|
| 1075 |
+
evaluation happened.
|
| 1076 |
+
|
| 1077 |
+
Args:
|
| 1078 |
+
resource (Map[str, Any]): JSON representation of object.
|
| 1079 |
+
"""
|
| 1080 |
+
|
| 1081 |
+
def __init__(self, resource):
|
| 1082 |
+
self._properties = resource
|
| 1083 |
+
|
| 1084 |
+
@property
|
| 1085 |
+
def procedure_id(self):
|
| 1086 |
+
"""Optional[str]: Name of the active procedure.
|
| 1087 |
+
|
| 1088 |
+
Omitted if in a top-level script.
|
| 1089 |
+
"""
|
| 1090 |
+
return self._properties.get("procedureId")
|
| 1091 |
+
|
| 1092 |
+
@property
|
| 1093 |
+
def text(self):
|
| 1094 |
+
"""str: Text of the current statement/expression."""
|
| 1095 |
+
return self._properties.get("text")
|
| 1096 |
+
|
| 1097 |
+
@property
|
| 1098 |
+
def start_line(self):
|
| 1099 |
+
"""int: One-based start line."""
|
| 1100 |
+
return _helpers._int_or_none(self._properties.get("startLine"))
|
| 1101 |
+
|
| 1102 |
+
@property
|
| 1103 |
+
def start_column(self):
|
| 1104 |
+
"""int: One-based start column."""
|
| 1105 |
+
return _helpers._int_or_none(self._properties.get("startColumn"))
|
| 1106 |
+
|
| 1107 |
+
@property
|
| 1108 |
+
def end_line(self):
|
| 1109 |
+
"""int: One-based end line."""
|
| 1110 |
+
return _helpers._int_or_none(self._properties.get("endLine"))
|
| 1111 |
+
|
| 1112 |
+
@property
|
| 1113 |
+
def end_column(self):
|
| 1114 |
+
"""int: One-based end column."""
|
| 1115 |
+
return _helpers._int_or_none(self._properties.get("endColumn"))
|
| 1116 |
+
|
| 1117 |
+
|
| 1118 |
+
class ScriptStatistics(object):
|
| 1119 |
+
"""Statistics for a child job of a script.
|
| 1120 |
+
|
| 1121 |
+
Args:
|
| 1122 |
+
resource (Map[str, Any]): JSON representation of object.
|
| 1123 |
+
"""
|
| 1124 |
+
|
| 1125 |
+
def __init__(self, resource):
|
| 1126 |
+
self._properties = resource
|
| 1127 |
+
|
| 1128 |
+
@property
|
| 1129 |
+
def stack_frames(self) -> Sequence[ScriptStackFrame]:
|
| 1130 |
+
"""Stack trace where the current evaluation happened.
|
| 1131 |
+
|
| 1132 |
+
Shows line/column/procedure name of each frame on the stack at the
|
| 1133 |
+
point where the current evaluation happened.
|
| 1134 |
+
|
| 1135 |
+
The leaf frame is first, the primary script is last.
|
| 1136 |
+
"""
|
| 1137 |
+
return [
|
| 1138 |
+
ScriptStackFrame(frame) for frame in self._properties.get("stackFrames", [])
|
| 1139 |
+
]
|
| 1140 |
+
|
| 1141 |
+
@property
|
| 1142 |
+
def evaluation_kind(self) -> Optional[str]:
|
| 1143 |
+
"""str: Indicates the type of child job.
|
| 1144 |
+
|
| 1145 |
+
Possible values include ``STATEMENT`` and ``EXPRESSION``.
|
| 1146 |
+
"""
|
| 1147 |
+
return self._properties.get("evaluationKind")
|
| 1148 |
+
|
| 1149 |
+
|
| 1150 |
+
class SessionInfo:
|
| 1151 |
+
"""[Preview] Information of the session if this job is part of one.
|
| 1152 |
+
|
| 1153 |
+
.. versionadded:: 2.29.0
|
| 1154 |
+
|
| 1155 |
+
Args:
|
| 1156 |
+
resource (Map[str, Any]): JSON representation of object.
|
| 1157 |
+
"""
|
| 1158 |
+
|
| 1159 |
+
def __init__(self, resource):
|
| 1160 |
+
self._properties = resource
|
| 1161 |
+
|
| 1162 |
+
@property
|
| 1163 |
+
def session_id(self) -> Optional[str]:
|
| 1164 |
+
"""The ID of the session."""
|
| 1165 |
+
return self._properties.get("sessionId")
|
| 1166 |
+
|
| 1167 |
+
|
| 1168 |
+
class UnknownJob(_AsyncJob):
|
| 1169 |
+
"""A job whose type cannot be determined."""
|
| 1170 |
+
|
| 1171 |
+
@classmethod
|
| 1172 |
+
def from_api_repr(cls, resource: dict, client) -> "UnknownJob":
|
| 1173 |
+
"""Construct an UnknownJob from the JSON representation.
|
| 1174 |
+
|
| 1175 |
+
Args:
|
| 1176 |
+
resource (Dict): JSON representation of a job.
|
| 1177 |
+
client (google.cloud.bigquery.client.Client):
|
| 1178 |
+
Client connected to BigQuery API.
|
| 1179 |
+
|
| 1180 |
+
Returns:
|
| 1181 |
+
UnknownJob: Job corresponding to the resource.
|
| 1182 |
+
"""
|
| 1183 |
+
job_ref_properties = resource.get(
|
| 1184 |
+
"jobReference", {"projectId": client.project, "jobId": None}
|
| 1185 |
+
)
|
| 1186 |
+
job_ref = _JobReference._from_api_repr(job_ref_properties)
|
| 1187 |
+
job = cls(job_ref, client)
|
| 1188 |
+
# Populate the job reference with the project, even if it has been
|
| 1189 |
+
# redacted, because we know it should equal that of the request.
|
| 1190 |
+
resource["jobReference"] = job_ref_properties
|
| 1191 |
+
job._properties = resource
|
| 1192 |
+
return job
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/copy_.py
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2015 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Classes for copy jobs."""
|
| 16 |
+
|
| 17 |
+
import typing
|
| 18 |
+
from typing import Optional
|
| 19 |
+
|
| 20 |
+
from google.cloud.bigquery.encryption_configuration import EncryptionConfiguration
|
| 21 |
+
from google.cloud.bigquery import _helpers
|
| 22 |
+
from google.cloud.bigquery.table import TableReference
|
| 23 |
+
|
| 24 |
+
from google.cloud.bigquery.job.base import _AsyncJob
|
| 25 |
+
from google.cloud.bigquery.job.base import _JobConfig
|
| 26 |
+
from google.cloud.bigquery.job.base import _JobReference
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class OperationType:
|
| 30 |
+
"""Different operation types supported in table copy job.
|
| 31 |
+
|
| 32 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#operationtype
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
OPERATION_TYPE_UNSPECIFIED = "OPERATION_TYPE_UNSPECIFIED"
|
| 36 |
+
"""Unspecified operation type."""
|
| 37 |
+
|
| 38 |
+
COPY = "COPY"
|
| 39 |
+
"""The source and destination table have the same table type."""
|
| 40 |
+
|
| 41 |
+
SNAPSHOT = "SNAPSHOT"
|
| 42 |
+
"""The source table type is TABLE and the destination table type is SNAPSHOT."""
|
| 43 |
+
|
| 44 |
+
CLONE = "CLONE"
|
| 45 |
+
"""The source table type is TABLE and the destination table type is CLONE."""
|
| 46 |
+
|
| 47 |
+
RESTORE = "RESTORE"
|
| 48 |
+
"""The source table type is SNAPSHOT and the destination table type is TABLE."""
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class CopyJobConfig(_JobConfig):
|
| 52 |
+
"""Configuration options for copy jobs.
|
| 53 |
+
|
| 54 |
+
All properties in this class are optional. Values which are :data:`None` ->
|
| 55 |
+
server defaults. Set properties on the constructed configuration by using
|
| 56 |
+
the property name as the name of a keyword argument.
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
def __init__(self, **kwargs) -> None:
|
| 60 |
+
super(CopyJobConfig, self).__init__("copy", **kwargs)
|
| 61 |
+
|
| 62 |
+
@property
|
| 63 |
+
def create_disposition(self):
|
| 64 |
+
"""google.cloud.bigquery.job.CreateDisposition: Specifies behavior
|
| 65 |
+
for creating tables.
|
| 66 |
+
|
| 67 |
+
See
|
| 68 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationTableCopy.FIELDS.create_disposition
|
| 69 |
+
"""
|
| 70 |
+
return self._get_sub_prop("createDisposition")
|
| 71 |
+
|
| 72 |
+
@create_disposition.setter
|
| 73 |
+
def create_disposition(self, value):
|
| 74 |
+
self._set_sub_prop("createDisposition", value)
|
| 75 |
+
|
| 76 |
+
@property
|
| 77 |
+
def write_disposition(self):
|
| 78 |
+
"""google.cloud.bigquery.job.WriteDisposition: Action that occurs if
|
| 79 |
+
the destination table already exists.
|
| 80 |
+
|
| 81 |
+
See
|
| 82 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationTableCopy.FIELDS.write_disposition
|
| 83 |
+
"""
|
| 84 |
+
return self._get_sub_prop("writeDisposition")
|
| 85 |
+
|
| 86 |
+
@write_disposition.setter
|
| 87 |
+
def write_disposition(self, value):
|
| 88 |
+
self._set_sub_prop("writeDisposition", value)
|
| 89 |
+
|
| 90 |
+
@property
|
| 91 |
+
def destination_encryption_configuration(self):
|
| 92 |
+
"""google.cloud.bigquery.encryption_configuration.EncryptionConfiguration: Custom
|
| 93 |
+
encryption configuration for the destination table.
|
| 94 |
+
|
| 95 |
+
Custom encryption configuration (e.g., Cloud KMS keys) or :data:`None`
|
| 96 |
+
if using default encryption.
|
| 97 |
+
|
| 98 |
+
See
|
| 99 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationTableCopy.FIELDS.destination_encryption_configuration
|
| 100 |
+
"""
|
| 101 |
+
prop = self._get_sub_prop("destinationEncryptionConfiguration")
|
| 102 |
+
if prop is not None:
|
| 103 |
+
prop = EncryptionConfiguration.from_api_repr(prop)
|
| 104 |
+
return prop
|
| 105 |
+
|
| 106 |
+
@destination_encryption_configuration.setter
|
| 107 |
+
def destination_encryption_configuration(self, value):
|
| 108 |
+
api_repr = value
|
| 109 |
+
if value is not None:
|
| 110 |
+
api_repr = value.to_api_repr()
|
| 111 |
+
self._set_sub_prop("destinationEncryptionConfiguration", api_repr)
|
| 112 |
+
|
| 113 |
+
@property
|
| 114 |
+
def operation_type(self) -> str:
|
| 115 |
+
"""The operation to perform with this copy job.
|
| 116 |
+
|
| 117 |
+
See
|
| 118 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationTableCopy.FIELDS.operation_type
|
| 119 |
+
"""
|
| 120 |
+
return self._get_sub_prop(
|
| 121 |
+
"operationType", OperationType.OPERATION_TYPE_UNSPECIFIED
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
@operation_type.setter
|
| 125 |
+
def operation_type(self, value: Optional[str]):
|
| 126 |
+
if value is None:
|
| 127 |
+
value = OperationType.OPERATION_TYPE_UNSPECIFIED
|
| 128 |
+
self._set_sub_prop("operationType", value)
|
| 129 |
+
|
| 130 |
+
@property
|
| 131 |
+
def destination_expiration_time(self) -> str:
|
| 132 |
+
"""google.cloud.bigquery.job.DestinationExpirationTime: The time when the
|
| 133 |
+
destination table expires. Expired tables will be deleted and their storage reclaimed.
|
| 134 |
+
|
| 135 |
+
See
|
| 136 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationTableCopy.FIELDS.destination_expiration_time
|
| 137 |
+
"""
|
| 138 |
+
return self._get_sub_prop("destinationExpirationTime")
|
| 139 |
+
|
| 140 |
+
@destination_expiration_time.setter
|
| 141 |
+
def destination_expiration_time(self, value: str):
|
| 142 |
+
self._set_sub_prop("destinationExpirationTime", value)
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
class CopyJob(_AsyncJob):
|
| 146 |
+
"""Asynchronous job: copy data into a table from other tables.
|
| 147 |
+
|
| 148 |
+
Args:
|
| 149 |
+
job_id (str): the job's ID, within the project belonging to ``client``.
|
| 150 |
+
|
| 151 |
+
sources (List[google.cloud.bigquery.table.TableReference]): Table from which data is to be loaded.
|
| 152 |
+
|
| 153 |
+
destination (google.cloud.bigquery.table.TableReference): Table into which data is to be loaded.
|
| 154 |
+
|
| 155 |
+
client (google.cloud.bigquery.client.Client):
|
| 156 |
+
A client which holds credentials and project configuration
|
| 157 |
+
for the dataset (which requires a project).
|
| 158 |
+
|
| 159 |
+
job_config (Optional[google.cloud.bigquery.job.CopyJobConfig]):
|
| 160 |
+
Extra configuration options for the copy job.
|
| 161 |
+
"""
|
| 162 |
+
|
| 163 |
+
_JOB_TYPE = "copy"
|
| 164 |
+
_CONFIG_CLASS = CopyJobConfig
|
| 165 |
+
|
| 166 |
+
def __init__(self, job_id, sources, destination, client, job_config=None):
|
| 167 |
+
super(CopyJob, self).__init__(job_id, client)
|
| 168 |
+
|
| 169 |
+
if job_config is not None:
|
| 170 |
+
self._properties["configuration"] = job_config._properties
|
| 171 |
+
|
| 172 |
+
if destination:
|
| 173 |
+
_helpers._set_sub_prop(
|
| 174 |
+
self._properties,
|
| 175 |
+
["configuration", "copy", "destinationTable"],
|
| 176 |
+
destination.to_api_repr(),
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
if sources:
|
| 180 |
+
source_resources = [source.to_api_repr() for source in sources]
|
| 181 |
+
_helpers._set_sub_prop(
|
| 182 |
+
self._properties,
|
| 183 |
+
["configuration", "copy", "sourceTables"],
|
| 184 |
+
source_resources,
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
@property
|
| 188 |
+
def configuration(self) -> CopyJobConfig:
|
| 189 |
+
"""The configuration for this copy job."""
|
| 190 |
+
return typing.cast(CopyJobConfig, super().configuration)
|
| 191 |
+
|
| 192 |
+
@property
|
| 193 |
+
def destination(self):
|
| 194 |
+
"""google.cloud.bigquery.table.TableReference: Table into which data
|
| 195 |
+
is to be loaded.
|
| 196 |
+
"""
|
| 197 |
+
return TableReference.from_api_repr(
|
| 198 |
+
_helpers._get_sub_prop(
|
| 199 |
+
self._properties, ["configuration", "copy", "destinationTable"]
|
| 200 |
+
)
|
| 201 |
+
)
|
| 202 |
+
|
| 203 |
+
@property
|
| 204 |
+
def sources(self):
|
| 205 |
+
"""List[google.cloud.bigquery.table.TableReference]): Table(s) from
|
| 206 |
+
which data is to be loaded.
|
| 207 |
+
"""
|
| 208 |
+
source_configs = _helpers._get_sub_prop(
|
| 209 |
+
self._properties, ["configuration", "copy", "sourceTables"]
|
| 210 |
+
)
|
| 211 |
+
if source_configs is None:
|
| 212 |
+
single = _helpers._get_sub_prop(
|
| 213 |
+
self._properties, ["configuration", "copy", "sourceTable"]
|
| 214 |
+
)
|
| 215 |
+
if single is None:
|
| 216 |
+
raise KeyError("Resource missing 'sourceTables' / 'sourceTable'")
|
| 217 |
+
source_configs = [single]
|
| 218 |
+
|
| 219 |
+
sources = []
|
| 220 |
+
for source_config in source_configs:
|
| 221 |
+
table_ref = TableReference.from_api_repr(source_config)
|
| 222 |
+
sources.append(table_ref)
|
| 223 |
+
return sources
|
| 224 |
+
|
| 225 |
+
@property
|
| 226 |
+
def create_disposition(self):
|
| 227 |
+
"""See
|
| 228 |
+
:attr:`google.cloud.bigquery.job.CopyJobConfig.create_disposition`.
|
| 229 |
+
"""
|
| 230 |
+
return self.configuration.create_disposition
|
| 231 |
+
|
| 232 |
+
@property
|
| 233 |
+
def write_disposition(self):
|
| 234 |
+
"""See
|
| 235 |
+
:attr:`google.cloud.bigquery.job.CopyJobConfig.write_disposition`.
|
| 236 |
+
"""
|
| 237 |
+
return self.configuration.write_disposition
|
| 238 |
+
|
| 239 |
+
@property
|
| 240 |
+
def destination_encryption_configuration(self):
|
| 241 |
+
"""google.cloud.bigquery.encryption_configuration.EncryptionConfiguration: Custom
|
| 242 |
+
encryption configuration for the destination table.
|
| 243 |
+
|
| 244 |
+
Custom encryption configuration (e.g., Cloud KMS keys) or :data:`None`
|
| 245 |
+
if using default encryption.
|
| 246 |
+
|
| 247 |
+
See
|
| 248 |
+
:attr:`google.cloud.bigquery.job.CopyJobConfig.destination_encryption_configuration`.
|
| 249 |
+
"""
|
| 250 |
+
return self.configuration.destination_encryption_configuration
|
| 251 |
+
|
| 252 |
+
def to_api_repr(self):
|
| 253 |
+
"""Generate a resource for :meth:`_begin`."""
|
| 254 |
+
# Exclude statistics, if set.
|
| 255 |
+
return {
|
| 256 |
+
"jobReference": self._properties["jobReference"],
|
| 257 |
+
"configuration": self._properties["configuration"],
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
@classmethod
|
| 261 |
+
def from_api_repr(cls, resource, client):
|
| 262 |
+
"""Factory: construct a job given its API representation
|
| 263 |
+
|
| 264 |
+
.. note::
|
| 265 |
+
|
| 266 |
+
This method assumes that the project found in the resource matches
|
| 267 |
+
the client's project.
|
| 268 |
+
|
| 269 |
+
Args:
|
| 270 |
+
resource (Dict): dataset job representation returned from the API
|
| 271 |
+
client (google.cloud.bigquery.client.Client):
|
| 272 |
+
Client which holds credentials and project
|
| 273 |
+
configuration for the dataset.
|
| 274 |
+
|
| 275 |
+
Returns:
|
| 276 |
+
google.cloud.bigquery.job.CopyJob: Job parsed from ``resource``.
|
| 277 |
+
"""
|
| 278 |
+
cls._check_resource_config(resource)
|
| 279 |
+
job_ref = _JobReference._from_api_repr(resource["jobReference"])
|
| 280 |
+
job = cls(job_ref, None, None, client=client)
|
| 281 |
+
job._set_properties(resource)
|
| 282 |
+
return job
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/extract.py
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2015 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Classes for extract (export) jobs."""
|
| 16 |
+
|
| 17 |
+
import typing
|
| 18 |
+
|
| 19 |
+
from google.cloud.bigquery import _helpers
|
| 20 |
+
from google.cloud.bigquery.model import ModelReference
|
| 21 |
+
from google.cloud.bigquery.table import Table
|
| 22 |
+
from google.cloud.bigquery.table import TableListItem
|
| 23 |
+
from google.cloud.bigquery.table import TableReference
|
| 24 |
+
from google.cloud.bigquery.job.base import _AsyncJob
|
| 25 |
+
from google.cloud.bigquery.job.base import _JobConfig
|
| 26 |
+
from google.cloud.bigquery.job.base import _JobReference
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class ExtractJobConfig(_JobConfig):
|
| 30 |
+
"""Configuration options for extract jobs.
|
| 31 |
+
|
| 32 |
+
All properties in this class are optional. Values which are :data:`None` ->
|
| 33 |
+
server defaults. Set properties on the constructed configuration by using
|
| 34 |
+
the property name as the name of a keyword argument.
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
def __init__(self, **kwargs):
|
| 38 |
+
super(ExtractJobConfig, self).__init__("extract", **kwargs)
|
| 39 |
+
|
| 40 |
+
@property
|
| 41 |
+
def compression(self):
|
| 42 |
+
"""google.cloud.bigquery.job.Compression: Compression type to use for
|
| 43 |
+
exported files.
|
| 44 |
+
|
| 45 |
+
See
|
| 46 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationExtract.FIELDS.compression
|
| 47 |
+
"""
|
| 48 |
+
return self._get_sub_prop("compression")
|
| 49 |
+
|
| 50 |
+
@compression.setter
|
| 51 |
+
def compression(self, value):
|
| 52 |
+
self._set_sub_prop("compression", value)
|
| 53 |
+
|
| 54 |
+
@property
|
| 55 |
+
def destination_format(self):
|
| 56 |
+
"""google.cloud.bigquery.job.DestinationFormat: Exported file format.
|
| 57 |
+
|
| 58 |
+
See
|
| 59 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationExtract.FIELDS.destination_format
|
| 60 |
+
"""
|
| 61 |
+
return self._get_sub_prop("destinationFormat")
|
| 62 |
+
|
| 63 |
+
@destination_format.setter
|
| 64 |
+
def destination_format(self, value):
|
| 65 |
+
self._set_sub_prop("destinationFormat", value)
|
| 66 |
+
|
| 67 |
+
@property
|
| 68 |
+
def field_delimiter(self):
|
| 69 |
+
"""str: Delimiter to use between fields in the exported data.
|
| 70 |
+
|
| 71 |
+
See
|
| 72 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationExtract.FIELDS.field_delimiter
|
| 73 |
+
"""
|
| 74 |
+
return self._get_sub_prop("fieldDelimiter")
|
| 75 |
+
|
| 76 |
+
@field_delimiter.setter
|
| 77 |
+
def field_delimiter(self, value):
|
| 78 |
+
self._set_sub_prop("fieldDelimiter", value)
|
| 79 |
+
|
| 80 |
+
@property
|
| 81 |
+
def print_header(self):
|
| 82 |
+
"""bool: Print a header row in the exported data.
|
| 83 |
+
|
| 84 |
+
See
|
| 85 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationExtract.FIELDS.print_header
|
| 86 |
+
"""
|
| 87 |
+
return self._get_sub_prop("printHeader")
|
| 88 |
+
|
| 89 |
+
@print_header.setter
|
| 90 |
+
def print_header(self, value):
|
| 91 |
+
self._set_sub_prop("printHeader", value)
|
| 92 |
+
|
| 93 |
+
@property
|
| 94 |
+
def use_avro_logical_types(self):
|
| 95 |
+
"""bool: For loads of Avro data, governs whether Avro logical types are
|
| 96 |
+
converted to their corresponding BigQuery types (e.g. TIMESTAMP) rather than
|
| 97 |
+
raw types (e.g. INTEGER).
|
| 98 |
+
"""
|
| 99 |
+
return self._get_sub_prop("useAvroLogicalTypes")
|
| 100 |
+
|
| 101 |
+
@use_avro_logical_types.setter
|
| 102 |
+
def use_avro_logical_types(self, value):
|
| 103 |
+
self._set_sub_prop("useAvroLogicalTypes", bool(value))
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
class ExtractJob(_AsyncJob):
|
| 107 |
+
"""Asynchronous job: extract data from a table into Cloud Storage.
|
| 108 |
+
|
| 109 |
+
Args:
|
| 110 |
+
job_id (str): the job's ID.
|
| 111 |
+
|
| 112 |
+
source (Union[ \
|
| 113 |
+
google.cloud.bigquery.table.TableReference, \
|
| 114 |
+
google.cloud.bigquery.model.ModelReference \
|
| 115 |
+
]):
|
| 116 |
+
Table or Model from which data is to be loaded or extracted.
|
| 117 |
+
|
| 118 |
+
destination_uris (List[str]):
|
| 119 |
+
URIs describing where the extracted data will be written in Cloud
|
| 120 |
+
Storage, using the format ``gs://<bucket_name>/<object_name_or_glob>``.
|
| 121 |
+
|
| 122 |
+
client (google.cloud.bigquery.client.Client):
|
| 123 |
+
A client which holds credentials and project configuration.
|
| 124 |
+
|
| 125 |
+
job_config (Optional[google.cloud.bigquery.job.ExtractJobConfig]):
|
| 126 |
+
Extra configuration options for the extract job.
|
| 127 |
+
"""
|
| 128 |
+
|
| 129 |
+
_JOB_TYPE = "extract"
|
| 130 |
+
_CONFIG_CLASS = ExtractJobConfig
|
| 131 |
+
|
| 132 |
+
def __init__(self, job_id, source, destination_uris, client, job_config=None):
|
| 133 |
+
super(ExtractJob, self).__init__(job_id, client)
|
| 134 |
+
|
| 135 |
+
if job_config is not None:
|
| 136 |
+
self._properties["configuration"] = job_config._properties
|
| 137 |
+
|
| 138 |
+
if source:
|
| 139 |
+
source_ref = {"projectId": source.project, "datasetId": source.dataset_id}
|
| 140 |
+
|
| 141 |
+
if isinstance(source, (Table, TableListItem, TableReference)):
|
| 142 |
+
source_ref["tableId"] = source.table_id
|
| 143 |
+
source_key = "sourceTable"
|
| 144 |
+
else:
|
| 145 |
+
source_ref["modelId"] = source.model_id
|
| 146 |
+
source_key = "sourceModel"
|
| 147 |
+
|
| 148 |
+
_helpers._set_sub_prop(
|
| 149 |
+
self._properties, ["configuration", "extract", source_key], source_ref
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
if destination_uris:
|
| 153 |
+
_helpers._set_sub_prop(
|
| 154 |
+
self._properties,
|
| 155 |
+
["configuration", "extract", "destinationUris"],
|
| 156 |
+
destination_uris,
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
@property
|
| 160 |
+
def configuration(self) -> ExtractJobConfig:
|
| 161 |
+
"""The configuration for this extract job."""
|
| 162 |
+
return typing.cast(ExtractJobConfig, super().configuration)
|
| 163 |
+
|
| 164 |
+
@property
|
| 165 |
+
def source(self):
|
| 166 |
+
"""Union[ \
|
| 167 |
+
google.cloud.bigquery.table.TableReference, \
|
| 168 |
+
google.cloud.bigquery.model.ModelReference \
|
| 169 |
+
]: Table or Model from which data is to be loaded or extracted.
|
| 170 |
+
"""
|
| 171 |
+
source_config = _helpers._get_sub_prop(
|
| 172 |
+
self._properties, ["configuration", "extract", "sourceTable"]
|
| 173 |
+
)
|
| 174 |
+
if source_config:
|
| 175 |
+
return TableReference.from_api_repr(source_config)
|
| 176 |
+
else:
|
| 177 |
+
source_config = _helpers._get_sub_prop(
|
| 178 |
+
self._properties, ["configuration", "extract", "sourceModel"]
|
| 179 |
+
)
|
| 180 |
+
return ModelReference.from_api_repr(source_config)
|
| 181 |
+
|
| 182 |
+
@property
|
| 183 |
+
def destination_uris(self):
|
| 184 |
+
"""List[str]: URIs describing where the extracted data will be
|
| 185 |
+
written in Cloud Storage, using the format
|
| 186 |
+
``gs://<bucket_name>/<object_name_or_glob>``.
|
| 187 |
+
"""
|
| 188 |
+
return _helpers._get_sub_prop(
|
| 189 |
+
self._properties, ["configuration", "extract", "destinationUris"]
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
@property
|
| 193 |
+
def compression(self):
|
| 194 |
+
"""See
|
| 195 |
+
:attr:`google.cloud.bigquery.job.ExtractJobConfig.compression`.
|
| 196 |
+
"""
|
| 197 |
+
return self.configuration.compression
|
| 198 |
+
|
| 199 |
+
@property
|
| 200 |
+
def destination_format(self):
|
| 201 |
+
"""See
|
| 202 |
+
:attr:`google.cloud.bigquery.job.ExtractJobConfig.destination_format`.
|
| 203 |
+
"""
|
| 204 |
+
return self.configuration.destination_format
|
| 205 |
+
|
| 206 |
+
@property
|
| 207 |
+
def field_delimiter(self):
|
| 208 |
+
"""See
|
| 209 |
+
:attr:`google.cloud.bigquery.job.ExtractJobConfig.field_delimiter`.
|
| 210 |
+
"""
|
| 211 |
+
return self.configuration.field_delimiter
|
| 212 |
+
|
| 213 |
+
@property
|
| 214 |
+
def print_header(self):
|
| 215 |
+
"""See
|
| 216 |
+
:attr:`google.cloud.bigquery.job.ExtractJobConfig.print_header`.
|
| 217 |
+
"""
|
| 218 |
+
return self.configuration.print_header
|
| 219 |
+
|
| 220 |
+
@property
|
| 221 |
+
def destination_uri_file_counts(self):
|
| 222 |
+
"""Return file counts from job statistics, if present.
|
| 223 |
+
|
| 224 |
+
See:
|
| 225 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobStatistics4.FIELDS.destination_uri_file_counts
|
| 226 |
+
|
| 227 |
+
Returns:
|
| 228 |
+
List[int]:
|
| 229 |
+
A list of integer counts, each representing the number of files
|
| 230 |
+
per destination URI or URI pattern specified in the extract
|
| 231 |
+
configuration. These values will be in the same order as the URIs
|
| 232 |
+
specified in the 'destinationUris' field. Returns None if job is
|
| 233 |
+
not yet complete.
|
| 234 |
+
"""
|
| 235 |
+
counts = self._job_statistics().get("destinationUriFileCounts")
|
| 236 |
+
if counts is not None:
|
| 237 |
+
return [int(count) for count in counts]
|
| 238 |
+
return None
|
| 239 |
+
|
| 240 |
+
def to_api_repr(self):
|
| 241 |
+
"""Generate a resource for :meth:`_begin`."""
|
| 242 |
+
# Exclude statistics, if set.
|
| 243 |
+
return {
|
| 244 |
+
"jobReference": self._properties["jobReference"],
|
| 245 |
+
"configuration": self._properties["configuration"],
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
@classmethod
|
| 249 |
+
def from_api_repr(cls, resource: dict, client) -> "ExtractJob":
|
| 250 |
+
"""Factory: construct a job given its API representation
|
| 251 |
+
|
| 252 |
+
.. note::
|
| 253 |
+
|
| 254 |
+
This method assumes that the project found in the resource matches
|
| 255 |
+
the client's project.
|
| 256 |
+
|
| 257 |
+
Args:
|
| 258 |
+
resource (Dict): dataset job representation returned from the API
|
| 259 |
+
|
| 260 |
+
client (google.cloud.bigquery.client.Client):
|
| 261 |
+
Client which holds credentials and project
|
| 262 |
+
configuration for the dataset.
|
| 263 |
+
|
| 264 |
+
Returns:
|
| 265 |
+
google.cloud.bigquery.job.ExtractJob: Job parsed from ``resource``.
|
| 266 |
+
"""
|
| 267 |
+
cls._check_resource_config(resource)
|
| 268 |
+
job_ref = _JobReference._from_api_repr(resource["jobReference"])
|
| 269 |
+
job = cls(job_ref, None, None, client=client)
|
| 270 |
+
job._set_properties(resource)
|
| 271 |
+
return job
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/load.py
ADDED
|
@@ -0,0 +1,1185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2015 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
"""Classes for load jobs."""
|
| 16 |
+
|
| 17 |
+
import typing
|
| 18 |
+
from typing import FrozenSet, List, Iterable, Optional, Union
|
| 19 |
+
|
| 20 |
+
from google.cloud.bigquery.encryption_configuration import EncryptionConfiguration
|
| 21 |
+
from google.cloud.bigquery.enums import SourceColumnMatch
|
| 22 |
+
from google.cloud.bigquery.external_config import HivePartitioningOptions
|
| 23 |
+
from google.cloud.bigquery.format_options import ParquetOptions
|
| 24 |
+
from google.cloud.bigquery import _helpers
|
| 25 |
+
from google.cloud.bigquery.schema import SchemaField
|
| 26 |
+
from google.cloud.bigquery.schema import _to_schema_fields
|
| 27 |
+
from google.cloud.bigquery.table import RangePartitioning
|
| 28 |
+
from google.cloud.bigquery.table import TableReference
|
| 29 |
+
from google.cloud.bigquery.table import TimePartitioning
|
| 30 |
+
from google.cloud.bigquery.job.base import _AsyncJob
|
| 31 |
+
from google.cloud.bigquery.job.base import _JobConfig
|
| 32 |
+
from google.cloud.bigquery.job.base import _JobReference
|
| 33 |
+
from google.cloud.bigquery.query import ConnectionProperty
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class ColumnNameCharacterMap:
|
| 37 |
+
"""Indicates the character map used for column names.
|
| 38 |
+
|
| 39 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#columnnamecharactermap
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
COLUMN_NAME_CHARACTER_MAP_UNSPECIFIED = "COLUMN_NAME_CHARACTER_MAP_UNSPECIFIED"
|
| 43 |
+
"""Unspecified column name character map."""
|
| 44 |
+
|
| 45 |
+
STRICT = "STRICT"
|
| 46 |
+
"""Support flexible column name and reject invalid column names."""
|
| 47 |
+
|
| 48 |
+
V1 = "V1"
|
| 49 |
+
""" Support alphanumeric + underscore characters and names must start with
|
| 50 |
+
a letter or underscore. Invalid column names will be normalized."""
|
| 51 |
+
|
| 52 |
+
V2 = "V2"
|
| 53 |
+
"""Support flexible column name. Invalid column names will be normalized."""
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class LoadJobConfig(_JobConfig):
|
| 57 |
+
"""Configuration options for load jobs.
|
| 58 |
+
|
| 59 |
+
Set properties on the constructed configuration by using the property name
|
| 60 |
+
as the name of a keyword argument. Values which are unset or :data:`None`
|
| 61 |
+
use the BigQuery REST API default values. See the `BigQuery REST API
|
| 62 |
+
reference documentation
|
| 63 |
+
<https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad>`_
|
| 64 |
+
for a list of default values.
|
| 65 |
+
|
| 66 |
+
Required options differ based on the
|
| 67 |
+
:attr:`~google.cloud.bigquery.job.LoadJobConfig.source_format` value.
|
| 68 |
+
For example, the BigQuery API's default value for
|
| 69 |
+
:attr:`~google.cloud.bigquery.job.LoadJobConfig.source_format` is ``"CSV"``.
|
| 70 |
+
When loading a CSV file, either
|
| 71 |
+
:attr:`~google.cloud.bigquery.job.LoadJobConfig.schema` must be set or
|
| 72 |
+
:attr:`~google.cloud.bigquery.job.LoadJobConfig.autodetect` must be set to
|
| 73 |
+
:data:`True`.
|
| 74 |
+
"""
|
| 75 |
+
|
| 76 |
+
def __init__(self, **kwargs) -> None:
|
| 77 |
+
super(LoadJobConfig, self).__init__("load", **kwargs)
|
| 78 |
+
|
| 79 |
+
@property
|
| 80 |
+
def allow_jagged_rows(self):
|
| 81 |
+
"""Optional[bool]: Allow missing trailing optional columns (CSV only).
|
| 82 |
+
|
| 83 |
+
See:
|
| 84 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.allow_jagged_rows
|
| 85 |
+
"""
|
| 86 |
+
return self._get_sub_prop("allowJaggedRows")
|
| 87 |
+
|
| 88 |
+
@allow_jagged_rows.setter
|
| 89 |
+
def allow_jagged_rows(self, value):
|
| 90 |
+
self._set_sub_prop("allowJaggedRows", value)
|
| 91 |
+
|
| 92 |
+
@property
|
| 93 |
+
def allow_quoted_newlines(self):
|
| 94 |
+
"""Optional[bool]: Allow quoted data containing newline characters (CSV only).
|
| 95 |
+
|
| 96 |
+
See:
|
| 97 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.allow_quoted_newlines
|
| 98 |
+
"""
|
| 99 |
+
return self._get_sub_prop("allowQuotedNewlines")
|
| 100 |
+
|
| 101 |
+
@allow_quoted_newlines.setter
|
| 102 |
+
def allow_quoted_newlines(self, value):
|
| 103 |
+
self._set_sub_prop("allowQuotedNewlines", value)
|
| 104 |
+
|
| 105 |
+
@property
|
| 106 |
+
def autodetect(self):
|
| 107 |
+
"""Optional[bool]: Automatically infer the schema from a sample of the data.
|
| 108 |
+
|
| 109 |
+
See:
|
| 110 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.autodetect
|
| 111 |
+
"""
|
| 112 |
+
return self._get_sub_prop("autodetect")
|
| 113 |
+
|
| 114 |
+
@autodetect.setter
|
| 115 |
+
def autodetect(self, value):
|
| 116 |
+
self._set_sub_prop("autodetect", value)
|
| 117 |
+
|
| 118 |
+
@property
|
| 119 |
+
def clustering_fields(self):
|
| 120 |
+
"""Optional[List[str]]: Fields defining clustering for the table
|
| 121 |
+
|
| 122 |
+
(Defaults to :data:`None`).
|
| 123 |
+
|
| 124 |
+
Clustering fields are immutable after table creation.
|
| 125 |
+
|
| 126 |
+
.. note::
|
| 127 |
+
|
| 128 |
+
BigQuery supports clustering for both partitioned and
|
| 129 |
+
non-partitioned tables.
|
| 130 |
+
"""
|
| 131 |
+
prop = self._get_sub_prop("clustering")
|
| 132 |
+
if prop is not None:
|
| 133 |
+
return list(prop.get("fields", ()))
|
| 134 |
+
|
| 135 |
+
@clustering_fields.setter
|
| 136 |
+
def clustering_fields(self, value):
|
| 137 |
+
"""Optional[List[str]]: Fields defining clustering for the table
|
| 138 |
+
|
| 139 |
+
(Defaults to :data:`None`).
|
| 140 |
+
"""
|
| 141 |
+
if value is not None:
|
| 142 |
+
self._set_sub_prop("clustering", {"fields": value})
|
| 143 |
+
else:
|
| 144 |
+
self._del_sub_prop("clustering")
|
| 145 |
+
|
| 146 |
+
@property
|
| 147 |
+
def connection_properties(self) -> List[ConnectionProperty]:
|
| 148 |
+
"""Connection properties.
|
| 149 |
+
|
| 150 |
+
See
|
| 151 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.connection_properties
|
| 152 |
+
|
| 153 |
+
.. versionadded:: 3.7.0
|
| 154 |
+
"""
|
| 155 |
+
resource = self._get_sub_prop("connectionProperties", [])
|
| 156 |
+
return [ConnectionProperty.from_api_repr(prop) for prop in resource]
|
| 157 |
+
|
| 158 |
+
@connection_properties.setter
|
| 159 |
+
def connection_properties(self, value: Iterable[ConnectionProperty]):
|
| 160 |
+
self._set_sub_prop(
|
| 161 |
+
"connectionProperties",
|
| 162 |
+
[prop.to_api_repr() for prop in value],
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
@property
|
| 166 |
+
def create_disposition(self):
|
| 167 |
+
"""Optional[google.cloud.bigquery.job.CreateDisposition]: Specifies behavior
|
| 168 |
+
for creating tables.
|
| 169 |
+
|
| 170 |
+
See:
|
| 171 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.create_disposition
|
| 172 |
+
"""
|
| 173 |
+
return self._get_sub_prop("createDisposition")
|
| 174 |
+
|
| 175 |
+
@create_disposition.setter
|
| 176 |
+
def create_disposition(self, value):
|
| 177 |
+
self._set_sub_prop("createDisposition", value)
|
| 178 |
+
|
| 179 |
+
@property
|
| 180 |
+
def create_session(self) -> Optional[bool]:
|
| 181 |
+
"""[Preview] If :data:`True`, creates a new session, where
|
| 182 |
+
:attr:`~google.cloud.bigquery.job.LoadJob.session_info` will contain a
|
| 183 |
+
random server generated session id.
|
| 184 |
+
|
| 185 |
+
If :data:`False`, runs load job with an existing ``session_id`` passed in
|
| 186 |
+
:attr:`~google.cloud.bigquery.job.LoadJobConfig.connection_properties`,
|
| 187 |
+
otherwise runs load job in non-session mode.
|
| 188 |
+
|
| 189 |
+
See
|
| 190 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.create_session
|
| 191 |
+
|
| 192 |
+
.. versionadded:: 3.7.0
|
| 193 |
+
"""
|
| 194 |
+
return self._get_sub_prop("createSession")
|
| 195 |
+
|
| 196 |
+
@create_session.setter
|
| 197 |
+
def create_session(self, value: Optional[bool]):
|
| 198 |
+
self._set_sub_prop("createSession", value)
|
| 199 |
+
|
| 200 |
+
@property
|
| 201 |
+
def decimal_target_types(self) -> Optional[FrozenSet[str]]:
|
| 202 |
+
"""Possible SQL data types to which the source decimal values are converted.
|
| 203 |
+
|
| 204 |
+
See:
|
| 205 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.decimal_target_types
|
| 206 |
+
|
| 207 |
+
.. versionadded:: 2.21.0
|
| 208 |
+
"""
|
| 209 |
+
prop = self._get_sub_prop("decimalTargetTypes")
|
| 210 |
+
if prop is not None:
|
| 211 |
+
prop = frozenset(prop)
|
| 212 |
+
return prop
|
| 213 |
+
|
| 214 |
+
@decimal_target_types.setter
|
| 215 |
+
def decimal_target_types(self, value: Optional[Iterable[str]]):
|
| 216 |
+
if value is not None:
|
| 217 |
+
self._set_sub_prop("decimalTargetTypes", list(value))
|
| 218 |
+
else:
|
| 219 |
+
self._del_sub_prop("decimalTargetTypes")
|
| 220 |
+
|
| 221 |
+
@property
|
| 222 |
+
def destination_encryption_configuration(self):
|
| 223 |
+
"""Optional[google.cloud.bigquery.encryption_configuration.EncryptionConfiguration]: Custom
|
| 224 |
+
encryption configuration for the destination table.
|
| 225 |
+
|
| 226 |
+
Custom encryption configuration (e.g., Cloud KMS keys) or :data:`None`
|
| 227 |
+
if using default encryption.
|
| 228 |
+
|
| 229 |
+
See:
|
| 230 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.destination_encryption_configuration
|
| 231 |
+
"""
|
| 232 |
+
prop = self._get_sub_prop("destinationEncryptionConfiguration")
|
| 233 |
+
if prop is not None:
|
| 234 |
+
prop = EncryptionConfiguration.from_api_repr(prop)
|
| 235 |
+
return prop
|
| 236 |
+
|
| 237 |
+
@destination_encryption_configuration.setter
|
| 238 |
+
def destination_encryption_configuration(self, value):
|
| 239 |
+
api_repr = value
|
| 240 |
+
if value is not None:
|
| 241 |
+
api_repr = value.to_api_repr()
|
| 242 |
+
self._set_sub_prop("destinationEncryptionConfiguration", api_repr)
|
| 243 |
+
else:
|
| 244 |
+
self._del_sub_prop("destinationEncryptionConfiguration")
|
| 245 |
+
|
| 246 |
+
@property
|
| 247 |
+
def destination_table_description(self):
|
| 248 |
+
"""Optional[str]: Description of the destination table.
|
| 249 |
+
|
| 250 |
+
See:
|
| 251 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#DestinationTableProperties.FIELDS.description
|
| 252 |
+
"""
|
| 253 |
+
prop = self._get_sub_prop("destinationTableProperties")
|
| 254 |
+
if prop is not None:
|
| 255 |
+
return prop["description"]
|
| 256 |
+
|
| 257 |
+
@destination_table_description.setter
|
| 258 |
+
def destination_table_description(self, value):
|
| 259 |
+
keys = [self._job_type, "destinationTableProperties", "description"]
|
| 260 |
+
if value is not None:
|
| 261 |
+
_helpers._set_sub_prop(self._properties, keys, value)
|
| 262 |
+
else:
|
| 263 |
+
_helpers._del_sub_prop(self._properties, keys)
|
| 264 |
+
|
| 265 |
+
@property
|
| 266 |
+
def destination_table_friendly_name(self):
|
| 267 |
+
"""Optional[str]: Name given to destination table.
|
| 268 |
+
|
| 269 |
+
See:
|
| 270 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#DestinationTableProperties.FIELDS.friendly_name
|
| 271 |
+
"""
|
| 272 |
+
prop = self._get_sub_prop("destinationTableProperties")
|
| 273 |
+
if prop is not None:
|
| 274 |
+
return prop["friendlyName"]
|
| 275 |
+
|
| 276 |
+
@destination_table_friendly_name.setter
|
| 277 |
+
def destination_table_friendly_name(self, value):
|
| 278 |
+
keys = [self._job_type, "destinationTableProperties", "friendlyName"]
|
| 279 |
+
if value is not None:
|
| 280 |
+
_helpers._set_sub_prop(self._properties, keys, value)
|
| 281 |
+
else:
|
| 282 |
+
_helpers._del_sub_prop(self._properties, keys)
|
| 283 |
+
|
| 284 |
+
@property
|
| 285 |
+
def encoding(self):
|
| 286 |
+
"""Optional[google.cloud.bigquery.job.Encoding]: The character encoding of the
|
| 287 |
+
data.
|
| 288 |
+
|
| 289 |
+
See:
|
| 290 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.encoding
|
| 291 |
+
"""
|
| 292 |
+
return self._get_sub_prop("encoding")
|
| 293 |
+
|
| 294 |
+
@encoding.setter
|
| 295 |
+
def encoding(self, value):
|
| 296 |
+
self._set_sub_prop("encoding", value)
|
| 297 |
+
|
| 298 |
+
@property
|
| 299 |
+
def field_delimiter(self):
|
| 300 |
+
"""Optional[str]: The separator for fields in a CSV file.
|
| 301 |
+
|
| 302 |
+
See:
|
| 303 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.field_delimiter
|
| 304 |
+
"""
|
| 305 |
+
return self._get_sub_prop("fieldDelimiter")
|
| 306 |
+
|
| 307 |
+
@field_delimiter.setter
|
| 308 |
+
def field_delimiter(self, value):
|
| 309 |
+
self._set_sub_prop("fieldDelimiter", value)
|
| 310 |
+
|
| 311 |
+
@property
|
| 312 |
+
def hive_partitioning(self):
|
| 313 |
+
"""Optional[:class:`~.external_config.HivePartitioningOptions`]: [Beta] When set, \
|
| 314 |
+
it configures hive partitioning support.
|
| 315 |
+
|
| 316 |
+
.. note::
|
| 317 |
+
**Experimental**. This feature is experimental and might change or
|
| 318 |
+
have limited support.
|
| 319 |
+
|
| 320 |
+
See:
|
| 321 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.hive_partitioning_options
|
| 322 |
+
"""
|
| 323 |
+
prop = self._get_sub_prop("hivePartitioningOptions")
|
| 324 |
+
if prop is None:
|
| 325 |
+
return None
|
| 326 |
+
return HivePartitioningOptions.from_api_repr(prop)
|
| 327 |
+
|
| 328 |
+
@hive_partitioning.setter
|
| 329 |
+
def hive_partitioning(self, value):
|
| 330 |
+
if value is not None:
|
| 331 |
+
if isinstance(value, HivePartitioningOptions):
|
| 332 |
+
value = value.to_api_repr()
|
| 333 |
+
else:
|
| 334 |
+
raise TypeError("Expected a HivePartitioningOptions instance or None.")
|
| 335 |
+
|
| 336 |
+
self._set_sub_prop("hivePartitioningOptions", value)
|
| 337 |
+
|
| 338 |
+
@property
|
| 339 |
+
def ignore_unknown_values(self):
|
| 340 |
+
"""Optional[bool]: Ignore extra values not represented in the table schema.
|
| 341 |
+
|
| 342 |
+
See:
|
| 343 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.ignore_unknown_values
|
| 344 |
+
"""
|
| 345 |
+
return self._get_sub_prop("ignoreUnknownValues")
|
| 346 |
+
|
| 347 |
+
@ignore_unknown_values.setter
|
| 348 |
+
def ignore_unknown_values(self, value):
|
| 349 |
+
self._set_sub_prop("ignoreUnknownValues", value)
|
| 350 |
+
|
| 351 |
+
@property
|
| 352 |
+
def json_extension(self):
|
| 353 |
+
"""Optional[str]: The extension to use for writing JSON data to BigQuery. Only supports GeoJSON currently.
|
| 354 |
+
|
| 355 |
+
See: https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.json_extension
|
| 356 |
+
|
| 357 |
+
"""
|
| 358 |
+
return self._get_sub_prop("jsonExtension")
|
| 359 |
+
|
| 360 |
+
@json_extension.setter
|
| 361 |
+
def json_extension(self, value):
|
| 362 |
+
self._set_sub_prop("jsonExtension", value)
|
| 363 |
+
|
| 364 |
+
@property
|
| 365 |
+
def max_bad_records(self):
|
| 366 |
+
"""Optional[int]: Number of invalid rows to ignore.
|
| 367 |
+
|
| 368 |
+
See:
|
| 369 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.max_bad_records
|
| 370 |
+
"""
|
| 371 |
+
return _helpers._int_or_none(self._get_sub_prop("maxBadRecords"))
|
| 372 |
+
|
| 373 |
+
@max_bad_records.setter
|
| 374 |
+
def max_bad_records(self, value):
|
| 375 |
+
self._set_sub_prop("maxBadRecords", value)
|
| 376 |
+
|
| 377 |
+
@property
|
| 378 |
+
def null_marker(self):
|
| 379 |
+
"""Optional[str]: Represents a null value (CSV only).
|
| 380 |
+
|
| 381 |
+
See:
|
| 382 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.null_marker
|
| 383 |
+
"""
|
| 384 |
+
return self._get_sub_prop("nullMarker")
|
| 385 |
+
|
| 386 |
+
@null_marker.setter
|
| 387 |
+
def null_marker(self, value):
|
| 388 |
+
self._set_sub_prop("nullMarker", value)
|
| 389 |
+
|
| 390 |
+
@property
|
| 391 |
+
def null_markers(self) -> Optional[List[str]]:
|
| 392 |
+
"""Optional[List[str]]: A list of strings represented as SQL NULL values in a CSV file.
|
| 393 |
+
|
| 394 |
+
.. note::
|
| 395 |
+
null_marker and null_markers can't be set at the same time.
|
| 396 |
+
If null_marker is set, null_markers has to be not set.
|
| 397 |
+
If null_markers is set, null_marker has to be not set.
|
| 398 |
+
If both null_marker and null_markers are set at the same time, a user error would be thrown.
|
| 399 |
+
Any strings listed in null_markers, including empty string would be interpreted as SQL NULL.
|
| 400 |
+
This applies to all column types.
|
| 401 |
+
|
| 402 |
+
See:
|
| 403 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.null_markers
|
| 404 |
+
"""
|
| 405 |
+
return self._get_sub_prop("nullMarkers")
|
| 406 |
+
|
| 407 |
+
@null_markers.setter
|
| 408 |
+
def null_markers(self, value: Optional[List[str]]):
|
| 409 |
+
self._set_sub_prop("nullMarkers", value)
|
| 410 |
+
|
| 411 |
+
@property
|
| 412 |
+
def preserve_ascii_control_characters(self):
|
| 413 |
+
"""Optional[bool]: Preserves the embedded ASCII control characters when sourceFormat is set to CSV.
|
| 414 |
+
|
| 415 |
+
See:
|
| 416 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.preserve_ascii_control_characters
|
| 417 |
+
"""
|
| 418 |
+
return self._get_sub_prop("preserveAsciiControlCharacters")
|
| 419 |
+
|
| 420 |
+
@preserve_ascii_control_characters.setter
|
| 421 |
+
def preserve_ascii_control_characters(self, value):
|
| 422 |
+
self._set_sub_prop("preserveAsciiControlCharacters", bool(value))
|
| 423 |
+
|
| 424 |
+
@property
|
| 425 |
+
def projection_fields(self) -> Optional[List[str]]:
|
| 426 |
+
"""Optional[List[str]]: If
|
| 427 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.source_format` is set to
|
| 428 |
+
"DATASTORE_BACKUP", indicates which entity properties to load into
|
| 429 |
+
BigQuery from a Cloud Datastore backup.
|
| 430 |
+
|
| 431 |
+
Property names are case sensitive and must be top-level properties. If
|
| 432 |
+
no properties are specified, BigQuery loads all properties. If any
|
| 433 |
+
named property isn't found in the Cloud Datastore backup, an invalid
|
| 434 |
+
error is returned in the job result.
|
| 435 |
+
|
| 436 |
+
See:
|
| 437 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.projection_fields
|
| 438 |
+
"""
|
| 439 |
+
return self._get_sub_prop("projectionFields")
|
| 440 |
+
|
| 441 |
+
@projection_fields.setter
|
| 442 |
+
def projection_fields(self, value: Optional[List[str]]):
|
| 443 |
+
self._set_sub_prop("projectionFields", value)
|
| 444 |
+
|
| 445 |
+
@property
|
| 446 |
+
def quote_character(self):
|
| 447 |
+
"""Optional[str]: Character used to quote data sections (CSV only).
|
| 448 |
+
|
| 449 |
+
See:
|
| 450 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.quote
|
| 451 |
+
"""
|
| 452 |
+
return self._get_sub_prop("quote")
|
| 453 |
+
|
| 454 |
+
@quote_character.setter
|
| 455 |
+
def quote_character(self, value):
|
| 456 |
+
self._set_sub_prop("quote", value)
|
| 457 |
+
|
| 458 |
+
@property
|
| 459 |
+
def range_partitioning(self):
|
| 460 |
+
"""Optional[google.cloud.bigquery.table.RangePartitioning]:
|
| 461 |
+
Configures range-based partitioning for destination table.
|
| 462 |
+
|
| 463 |
+
.. note::
|
| 464 |
+
**Beta**. The integer range partitioning feature is in a
|
| 465 |
+
pre-release state and might change or have limited support.
|
| 466 |
+
|
| 467 |
+
Only specify at most one of
|
| 468 |
+
:attr:`~google.cloud.bigquery.job.LoadJobConfig.time_partitioning` or
|
| 469 |
+
:attr:`~google.cloud.bigquery.job.LoadJobConfig.range_partitioning`.
|
| 470 |
+
|
| 471 |
+
Raises:
|
| 472 |
+
ValueError:
|
| 473 |
+
If the value is not
|
| 474 |
+
:class:`~google.cloud.bigquery.table.RangePartitioning` or
|
| 475 |
+
:data:`None`.
|
| 476 |
+
"""
|
| 477 |
+
resource = self._get_sub_prop("rangePartitioning")
|
| 478 |
+
if resource is not None:
|
| 479 |
+
return RangePartitioning(_properties=resource)
|
| 480 |
+
|
| 481 |
+
@range_partitioning.setter
|
| 482 |
+
def range_partitioning(self, value):
|
| 483 |
+
resource = value
|
| 484 |
+
if isinstance(value, RangePartitioning):
|
| 485 |
+
resource = value._properties
|
| 486 |
+
elif value is not None:
|
| 487 |
+
raise ValueError(
|
| 488 |
+
"Expected value to be RangePartitioning or None, got {}.".format(value)
|
| 489 |
+
)
|
| 490 |
+
self._set_sub_prop("rangePartitioning", resource)
|
| 491 |
+
|
| 492 |
+
@property
|
| 493 |
+
def reference_file_schema_uri(self):
|
| 494 |
+
"""Optional[str]:
|
| 495 |
+
When creating an external table, the user can provide a reference file with the
|
| 496 |
+
table schema. This is enabled for the following formats:
|
| 497 |
+
|
| 498 |
+
AVRO, PARQUET, ORC
|
| 499 |
+
"""
|
| 500 |
+
return self._get_sub_prop("referenceFileSchemaUri")
|
| 501 |
+
|
| 502 |
+
@reference_file_schema_uri.setter
|
| 503 |
+
def reference_file_schema_uri(self, value):
|
| 504 |
+
return self._set_sub_prop("referenceFileSchemaUri", value)
|
| 505 |
+
|
| 506 |
+
@property
|
| 507 |
+
def schema(self):
|
| 508 |
+
"""Optional[Sequence[Union[ \
|
| 509 |
+
:class:`~google.cloud.bigquery.schema.SchemaField`, \
|
| 510 |
+
Mapping[str, Any] \
|
| 511 |
+
]]]: Schema of the destination table.
|
| 512 |
+
|
| 513 |
+
See:
|
| 514 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.schema
|
| 515 |
+
"""
|
| 516 |
+
schema = _helpers._get_sub_prop(self._properties, ["load", "schema", "fields"])
|
| 517 |
+
if schema is None:
|
| 518 |
+
return
|
| 519 |
+
return [SchemaField.from_api_repr(field) for field in schema]
|
| 520 |
+
|
| 521 |
+
@schema.setter
|
| 522 |
+
def schema(self, value):
|
| 523 |
+
if value is None:
|
| 524 |
+
self._del_sub_prop("schema")
|
| 525 |
+
return
|
| 526 |
+
|
| 527 |
+
value = _to_schema_fields(value)
|
| 528 |
+
|
| 529 |
+
_helpers._set_sub_prop(
|
| 530 |
+
self._properties,
|
| 531 |
+
["load", "schema", "fields"],
|
| 532 |
+
[field.to_api_repr() for field in value],
|
| 533 |
+
)
|
| 534 |
+
|
| 535 |
+
@property
|
| 536 |
+
def schema_update_options(self):
|
| 537 |
+
"""Optional[List[google.cloud.bigquery.job.SchemaUpdateOption]]: Specifies
|
| 538 |
+
updates to the destination table schema to allow as a side effect of
|
| 539 |
+
the load job.
|
| 540 |
+
"""
|
| 541 |
+
return self._get_sub_prop("schemaUpdateOptions")
|
| 542 |
+
|
| 543 |
+
@schema_update_options.setter
|
| 544 |
+
def schema_update_options(self, values):
|
| 545 |
+
self._set_sub_prop("schemaUpdateOptions", values)
|
| 546 |
+
|
| 547 |
+
@property
|
| 548 |
+
def skip_leading_rows(self):
|
| 549 |
+
"""Optional[int]: Number of rows to skip when reading data (CSV only).
|
| 550 |
+
|
| 551 |
+
See:
|
| 552 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.skip_leading_rows
|
| 553 |
+
"""
|
| 554 |
+
return _helpers._int_or_none(self._get_sub_prop("skipLeadingRows"))
|
| 555 |
+
|
| 556 |
+
@skip_leading_rows.setter
|
| 557 |
+
def skip_leading_rows(self, value):
|
| 558 |
+
self._set_sub_prop("skipLeadingRows", str(value))
|
| 559 |
+
|
| 560 |
+
@property
|
| 561 |
+
def source_format(self):
|
| 562 |
+
"""Optional[google.cloud.bigquery.job.SourceFormat]: File format of the data.
|
| 563 |
+
|
| 564 |
+
See:
|
| 565 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.source_format
|
| 566 |
+
"""
|
| 567 |
+
return self._get_sub_prop("sourceFormat")
|
| 568 |
+
|
| 569 |
+
@source_format.setter
|
| 570 |
+
def source_format(self, value):
|
| 571 |
+
self._set_sub_prop("sourceFormat", value)
|
| 572 |
+
|
| 573 |
+
@property
|
| 574 |
+
def source_column_match(self) -> Optional[SourceColumnMatch]:
|
| 575 |
+
"""Optional[google.cloud.bigquery.enums.SourceColumnMatch]: Controls the
|
| 576 |
+
strategy used to match loaded columns to the schema. If not set, a sensible
|
| 577 |
+
default is chosen based on how the schema is provided. If autodetect is
|
| 578 |
+
used, then columns are matched by name. Otherwise, columns are matched by
|
| 579 |
+
position. This is done to keep the behavior backward-compatible.
|
| 580 |
+
|
| 581 |
+
Acceptable values are:
|
| 582 |
+
|
| 583 |
+
SOURCE_COLUMN_MATCH_UNSPECIFIED: Unspecified column name match option.
|
| 584 |
+
POSITION: matches by position. This assumes that the columns are ordered
|
| 585 |
+
the same way as the schema.
|
| 586 |
+
NAME: matches by name. This reads the header row as column names and
|
| 587 |
+
reorders columns to match the field names in the schema.
|
| 588 |
+
|
| 589 |
+
See:
|
| 590 |
+
|
| 591 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.source_column_match
|
| 592 |
+
"""
|
| 593 |
+
value = self._get_sub_prop("sourceColumnMatch")
|
| 594 |
+
return SourceColumnMatch(value) if value is not None else None
|
| 595 |
+
|
| 596 |
+
@source_column_match.setter
|
| 597 |
+
def source_column_match(self, value: Union[SourceColumnMatch, str, None]):
|
| 598 |
+
if value is not None and not isinstance(value, (SourceColumnMatch, str)):
|
| 599 |
+
raise TypeError(
|
| 600 |
+
"value must be a google.cloud.bigquery.enums.SourceColumnMatch, str, or None"
|
| 601 |
+
)
|
| 602 |
+
if isinstance(value, SourceColumnMatch):
|
| 603 |
+
value = value.value
|
| 604 |
+
self._set_sub_prop("sourceColumnMatch", value if value else None)
|
| 605 |
+
|
| 606 |
+
@property
|
| 607 |
+
def date_format(self) -> Optional[str]:
|
| 608 |
+
"""Optional[str]: Date format used for parsing DATE values.
|
| 609 |
+
|
| 610 |
+
See:
|
| 611 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.date_format
|
| 612 |
+
"""
|
| 613 |
+
return self._get_sub_prop("dateFormat")
|
| 614 |
+
|
| 615 |
+
@date_format.setter
|
| 616 |
+
def date_format(self, value: Optional[str]):
|
| 617 |
+
self._set_sub_prop("dateFormat", value)
|
| 618 |
+
|
| 619 |
+
@property
|
| 620 |
+
def datetime_format(self) -> Optional[str]:
|
| 621 |
+
"""Optional[str]: Date format used for parsing DATETIME values.
|
| 622 |
+
|
| 623 |
+
See:
|
| 624 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.datetime_format
|
| 625 |
+
"""
|
| 626 |
+
return self._get_sub_prop("datetimeFormat")
|
| 627 |
+
|
| 628 |
+
@datetime_format.setter
|
| 629 |
+
def datetime_format(self, value: Optional[str]):
|
| 630 |
+
self._set_sub_prop("datetimeFormat", value)
|
| 631 |
+
|
| 632 |
+
@property
|
| 633 |
+
def time_zone(self) -> Optional[str]:
|
| 634 |
+
"""Optional[str]: Default time zone that will apply when parsing timestamp
|
| 635 |
+
values that have no specific time zone.
|
| 636 |
+
|
| 637 |
+
See:
|
| 638 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.time_zone
|
| 639 |
+
"""
|
| 640 |
+
return self._get_sub_prop("timeZone")
|
| 641 |
+
|
| 642 |
+
@time_zone.setter
|
| 643 |
+
def time_zone(self, value: Optional[str]):
|
| 644 |
+
self._set_sub_prop("timeZone", value)
|
| 645 |
+
|
| 646 |
+
@property
|
| 647 |
+
def time_format(self) -> Optional[str]:
|
| 648 |
+
"""Optional[str]: Date format used for parsing TIME values.
|
| 649 |
+
|
| 650 |
+
See:
|
| 651 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.time_format
|
| 652 |
+
"""
|
| 653 |
+
return self._get_sub_prop("timeFormat")
|
| 654 |
+
|
| 655 |
+
@time_format.setter
|
| 656 |
+
def time_format(self, value: Optional[str]):
|
| 657 |
+
self._set_sub_prop("timeFormat", value)
|
| 658 |
+
|
| 659 |
+
@property
|
| 660 |
+
def timestamp_format(self) -> Optional[str]:
|
| 661 |
+
"""Optional[str]: Date format used for parsing TIMESTAMP values.
|
| 662 |
+
|
| 663 |
+
See:
|
| 664 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.timestamp_format
|
| 665 |
+
"""
|
| 666 |
+
return self._get_sub_prop("timestampFormat")
|
| 667 |
+
|
| 668 |
+
@timestamp_format.setter
|
| 669 |
+
def timestamp_format(self, value: Optional[str]):
|
| 670 |
+
self._set_sub_prop("timestampFormat", value)
|
| 671 |
+
|
| 672 |
+
@property
|
| 673 |
+
def time_partitioning(self):
|
| 674 |
+
"""Optional[google.cloud.bigquery.table.TimePartitioning]: Specifies time-based
|
| 675 |
+
partitioning for the destination table.
|
| 676 |
+
|
| 677 |
+
Only specify at most one of
|
| 678 |
+
:attr:`~google.cloud.bigquery.job.LoadJobConfig.time_partitioning` or
|
| 679 |
+
:attr:`~google.cloud.bigquery.job.LoadJobConfig.range_partitioning`.
|
| 680 |
+
"""
|
| 681 |
+
prop = self._get_sub_prop("timePartitioning")
|
| 682 |
+
if prop is not None:
|
| 683 |
+
prop = TimePartitioning.from_api_repr(prop)
|
| 684 |
+
return prop
|
| 685 |
+
|
| 686 |
+
@time_partitioning.setter
|
| 687 |
+
def time_partitioning(self, value):
|
| 688 |
+
api_repr = value
|
| 689 |
+
if value is not None:
|
| 690 |
+
api_repr = value.to_api_repr()
|
| 691 |
+
self._set_sub_prop("timePartitioning", api_repr)
|
| 692 |
+
else:
|
| 693 |
+
self._del_sub_prop("timePartitioning")
|
| 694 |
+
|
| 695 |
+
@property
|
| 696 |
+
def use_avro_logical_types(self):
|
| 697 |
+
"""Optional[bool]: For loads of Avro data, governs whether Avro logical types are
|
| 698 |
+
converted to their corresponding BigQuery types (e.g. TIMESTAMP) rather than
|
| 699 |
+
raw types (e.g. INTEGER).
|
| 700 |
+
"""
|
| 701 |
+
return self._get_sub_prop("useAvroLogicalTypes")
|
| 702 |
+
|
| 703 |
+
@use_avro_logical_types.setter
|
| 704 |
+
def use_avro_logical_types(self, value):
|
| 705 |
+
self._set_sub_prop("useAvroLogicalTypes", bool(value))
|
| 706 |
+
|
| 707 |
+
@property
|
| 708 |
+
def write_disposition(self):
|
| 709 |
+
"""Optional[google.cloud.bigquery.job.WriteDisposition]: Action that occurs if
|
| 710 |
+
the destination table already exists.
|
| 711 |
+
|
| 712 |
+
See:
|
| 713 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.write_disposition
|
| 714 |
+
"""
|
| 715 |
+
return self._get_sub_prop("writeDisposition")
|
| 716 |
+
|
| 717 |
+
@write_disposition.setter
|
| 718 |
+
def write_disposition(self, value):
|
| 719 |
+
self._set_sub_prop("writeDisposition", value)
|
| 720 |
+
|
| 721 |
+
@property
|
| 722 |
+
def parquet_options(self):
|
| 723 |
+
"""Optional[google.cloud.bigquery.format_options.ParquetOptions]: Additional
|
| 724 |
+
properties to set if ``sourceFormat`` is set to PARQUET.
|
| 725 |
+
|
| 726 |
+
See:
|
| 727 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.parquet_options
|
| 728 |
+
"""
|
| 729 |
+
prop = self._get_sub_prop("parquetOptions")
|
| 730 |
+
if prop is not None:
|
| 731 |
+
prop = ParquetOptions.from_api_repr(prop)
|
| 732 |
+
return prop
|
| 733 |
+
|
| 734 |
+
@parquet_options.setter
|
| 735 |
+
def parquet_options(self, value):
|
| 736 |
+
if value is not None:
|
| 737 |
+
self._set_sub_prop("parquetOptions", value.to_api_repr())
|
| 738 |
+
else:
|
| 739 |
+
self._del_sub_prop("parquetOptions")
|
| 740 |
+
|
| 741 |
+
@property
|
| 742 |
+
def column_name_character_map(self) -> str:
|
| 743 |
+
"""Optional[google.cloud.bigquery.job.ColumnNameCharacterMap]:
|
| 744 |
+
Character map supported for column names in CSV/Parquet loads. Defaults
|
| 745 |
+
to STRICT and can be overridden by Project Config Service. Using this
|
| 746 |
+
option with unsupported load formats will result in an error.
|
| 747 |
+
|
| 748 |
+
See
|
| 749 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.column_name_character_map
|
| 750 |
+
"""
|
| 751 |
+
return self._get_sub_prop(
|
| 752 |
+
"columnNameCharacterMap",
|
| 753 |
+
ColumnNameCharacterMap.COLUMN_NAME_CHARACTER_MAP_UNSPECIFIED,
|
| 754 |
+
)
|
| 755 |
+
|
| 756 |
+
@column_name_character_map.setter
|
| 757 |
+
def column_name_character_map(self, value: Optional[str]):
|
| 758 |
+
if value is None:
|
| 759 |
+
value = ColumnNameCharacterMap.COLUMN_NAME_CHARACTER_MAP_UNSPECIFIED
|
| 760 |
+
self._set_sub_prop("columnNameCharacterMap", value)
|
| 761 |
+
|
| 762 |
+
@property
|
| 763 |
+
def timestamp_target_precision(self) -> Optional[List[int]]:
|
| 764 |
+
"""Optional[list[int]]: [Private Preview] Precisions (maximum number of
|
| 765 |
+
total digits in base 10) for seconds of TIMESTAMP types that are
|
| 766 |
+
allowed to the destination table for autodetection mode.
|
| 767 |
+
|
| 768 |
+
Available for the formats: CSV.
|
| 769 |
+
|
| 770 |
+
For the CSV Format, Possible values include:
|
| 771 |
+
None, [], or [6]: timestamp(6) for all auto detected TIMESTAMP
|
| 772 |
+
columns.
|
| 773 |
+
[6, 12]: timestamp(6) for all auto detected TIMESTAMP columns that
|
| 774 |
+
have less than 6 digits of subseconds. timestamp(12) for all auto
|
| 775 |
+
detected TIMESTAMP columns that have more than 6 digits of
|
| 776 |
+
subseconds.
|
| 777 |
+
[12]: timestamp(12) for all auto detected TIMESTAMP columns.
|
| 778 |
+
|
| 779 |
+
The order of the elements in this array is ignored. Inputs that have
|
| 780 |
+
higher precision than the highest target precision in this array will
|
| 781 |
+
be truncated.
|
| 782 |
+
"""
|
| 783 |
+
return self._get_sub_prop("timestampTargetPrecision")
|
| 784 |
+
|
| 785 |
+
@timestamp_target_precision.setter
|
| 786 |
+
def timestamp_target_precision(self, value: Optional[List[int]]):
|
| 787 |
+
if value is not None:
|
| 788 |
+
self._set_sub_prop("timestampTargetPrecision", value)
|
| 789 |
+
else:
|
| 790 |
+
self._del_sub_prop("timestampTargetPrecision")
|
| 791 |
+
|
| 792 |
+
|
| 793 |
+
class LoadJob(_AsyncJob):
|
| 794 |
+
"""Asynchronous job for loading data into a table.
|
| 795 |
+
|
| 796 |
+
Can load from Google Cloud Storage URIs or from a file.
|
| 797 |
+
|
| 798 |
+
Args:
|
| 799 |
+
job_id (str): the job's ID
|
| 800 |
+
|
| 801 |
+
source_uris (Optional[Sequence[str]]):
|
| 802 |
+
URIs of one or more data files to be loaded. See
|
| 803 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.source_uris
|
| 804 |
+
for supported URI formats. Pass None for jobs that load from a file.
|
| 805 |
+
|
| 806 |
+
destination (google.cloud.bigquery.table.TableReference): reference to table into which data is to be loaded.
|
| 807 |
+
|
| 808 |
+
client (google.cloud.bigquery.client.Client):
|
| 809 |
+
A client which holds credentials and project configuration
|
| 810 |
+
for the dataset (which requires a project).
|
| 811 |
+
"""
|
| 812 |
+
|
| 813 |
+
_JOB_TYPE = "load"
|
| 814 |
+
_CONFIG_CLASS = LoadJobConfig
|
| 815 |
+
|
| 816 |
+
def __init__(self, job_id, source_uris, destination, client, job_config=None):
|
| 817 |
+
super(LoadJob, self).__init__(job_id, client)
|
| 818 |
+
|
| 819 |
+
if job_config is not None:
|
| 820 |
+
self._properties["configuration"] = job_config._properties
|
| 821 |
+
|
| 822 |
+
if source_uris is not None:
|
| 823 |
+
_helpers._set_sub_prop(
|
| 824 |
+
self._properties, ["configuration", "load", "sourceUris"], source_uris
|
| 825 |
+
)
|
| 826 |
+
|
| 827 |
+
if destination is not None:
|
| 828 |
+
_helpers._set_sub_prop(
|
| 829 |
+
self._properties,
|
| 830 |
+
["configuration", "load", "destinationTable"],
|
| 831 |
+
destination.to_api_repr(),
|
| 832 |
+
)
|
| 833 |
+
|
| 834 |
+
@property
|
| 835 |
+
def configuration(self) -> LoadJobConfig:
|
| 836 |
+
"""The configuration for this load job."""
|
| 837 |
+
return typing.cast(LoadJobConfig, super().configuration)
|
| 838 |
+
|
| 839 |
+
@property
|
| 840 |
+
def destination(self):
|
| 841 |
+
"""google.cloud.bigquery.table.TableReference: table where loaded rows are written
|
| 842 |
+
|
| 843 |
+
See:
|
| 844 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.destination_table
|
| 845 |
+
"""
|
| 846 |
+
dest_config = _helpers._get_sub_prop(
|
| 847 |
+
self._properties, ["configuration", "load", "destinationTable"]
|
| 848 |
+
)
|
| 849 |
+
return TableReference.from_api_repr(dest_config)
|
| 850 |
+
|
| 851 |
+
@property
|
| 852 |
+
def source_uris(self):
|
| 853 |
+
"""Optional[Sequence[str]]: URIs of data files to be loaded. See
|
| 854 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.source_uris
|
| 855 |
+
for supported URI formats. None for jobs that load from a file.
|
| 856 |
+
"""
|
| 857 |
+
return _helpers._get_sub_prop(
|
| 858 |
+
self._properties, ["configuration", "load", "sourceUris"]
|
| 859 |
+
)
|
| 860 |
+
|
| 861 |
+
@property
|
| 862 |
+
def allow_jagged_rows(self):
|
| 863 |
+
"""See
|
| 864 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.allow_jagged_rows`.
|
| 865 |
+
"""
|
| 866 |
+
return self.configuration.allow_jagged_rows
|
| 867 |
+
|
| 868 |
+
@property
|
| 869 |
+
def allow_quoted_newlines(self):
|
| 870 |
+
"""See
|
| 871 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.allow_quoted_newlines`.
|
| 872 |
+
"""
|
| 873 |
+
return self.configuration.allow_quoted_newlines
|
| 874 |
+
|
| 875 |
+
@property
|
| 876 |
+
def autodetect(self):
|
| 877 |
+
"""See
|
| 878 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.autodetect`.
|
| 879 |
+
"""
|
| 880 |
+
return self.configuration.autodetect
|
| 881 |
+
|
| 882 |
+
@property
|
| 883 |
+
def connection_properties(self) -> List[ConnectionProperty]:
|
| 884 |
+
"""See
|
| 885 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.connection_properties`.
|
| 886 |
+
|
| 887 |
+
.. versionadded:: 3.7.0
|
| 888 |
+
"""
|
| 889 |
+
return self.configuration.connection_properties
|
| 890 |
+
|
| 891 |
+
@property
|
| 892 |
+
def create_disposition(self):
|
| 893 |
+
"""See
|
| 894 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.create_disposition`.
|
| 895 |
+
"""
|
| 896 |
+
return self.configuration.create_disposition
|
| 897 |
+
|
| 898 |
+
@property
|
| 899 |
+
def create_session(self) -> Optional[bool]:
|
| 900 |
+
"""See
|
| 901 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.create_session`.
|
| 902 |
+
|
| 903 |
+
.. versionadded:: 3.7.0
|
| 904 |
+
"""
|
| 905 |
+
return self.configuration.create_session
|
| 906 |
+
|
| 907 |
+
@property
|
| 908 |
+
def encoding(self):
|
| 909 |
+
"""See
|
| 910 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.encoding`.
|
| 911 |
+
"""
|
| 912 |
+
return self.configuration.encoding
|
| 913 |
+
|
| 914 |
+
@property
|
| 915 |
+
def field_delimiter(self):
|
| 916 |
+
"""See
|
| 917 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.field_delimiter`.
|
| 918 |
+
"""
|
| 919 |
+
return self.configuration.field_delimiter
|
| 920 |
+
|
| 921 |
+
@property
|
| 922 |
+
def ignore_unknown_values(self):
|
| 923 |
+
"""See
|
| 924 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.ignore_unknown_values`.
|
| 925 |
+
"""
|
| 926 |
+
return self.configuration.ignore_unknown_values
|
| 927 |
+
|
| 928 |
+
@property
|
| 929 |
+
def max_bad_records(self):
|
| 930 |
+
"""See
|
| 931 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.max_bad_records`.
|
| 932 |
+
"""
|
| 933 |
+
return self.configuration.max_bad_records
|
| 934 |
+
|
| 935 |
+
@property
|
| 936 |
+
def null_marker(self):
|
| 937 |
+
"""See
|
| 938 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.null_marker`.
|
| 939 |
+
"""
|
| 940 |
+
return self.configuration.null_marker
|
| 941 |
+
|
| 942 |
+
@property
|
| 943 |
+
def null_markers(self):
|
| 944 |
+
"""See
|
| 945 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.null_markers`.
|
| 946 |
+
"""
|
| 947 |
+
return self.configuration.null_markers
|
| 948 |
+
|
| 949 |
+
@property
|
| 950 |
+
def quote_character(self):
|
| 951 |
+
"""See
|
| 952 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.quote_character`.
|
| 953 |
+
"""
|
| 954 |
+
return self.configuration.quote_character
|
| 955 |
+
|
| 956 |
+
@property
|
| 957 |
+
def reference_file_schema_uri(self):
|
| 958 |
+
"""See:
|
| 959 |
+
attr:`google.cloud.bigquery.job.LoadJobConfig.reference_file_schema_uri`.
|
| 960 |
+
"""
|
| 961 |
+
return self.configuration.reference_file_schema_uri
|
| 962 |
+
|
| 963 |
+
@property
|
| 964 |
+
def skip_leading_rows(self):
|
| 965 |
+
"""See
|
| 966 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.skip_leading_rows`.
|
| 967 |
+
"""
|
| 968 |
+
return self.configuration.skip_leading_rows
|
| 969 |
+
|
| 970 |
+
@property
|
| 971 |
+
def source_format(self):
|
| 972 |
+
"""See
|
| 973 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.source_format`.
|
| 974 |
+
"""
|
| 975 |
+
return self.configuration.source_format
|
| 976 |
+
|
| 977 |
+
@property
|
| 978 |
+
def write_disposition(self):
|
| 979 |
+
"""See
|
| 980 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.write_disposition`.
|
| 981 |
+
"""
|
| 982 |
+
return self.configuration.write_disposition
|
| 983 |
+
|
| 984 |
+
@property
|
| 985 |
+
def schema(self):
|
| 986 |
+
"""See
|
| 987 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.schema`.
|
| 988 |
+
"""
|
| 989 |
+
return self.configuration.schema
|
| 990 |
+
|
| 991 |
+
@property
|
| 992 |
+
def destination_encryption_configuration(self):
|
| 993 |
+
"""google.cloud.bigquery.encryption_configuration.EncryptionConfiguration: Custom
|
| 994 |
+
encryption configuration for the destination table.
|
| 995 |
+
|
| 996 |
+
Custom encryption configuration (e.g., Cloud KMS keys)
|
| 997 |
+
or :data:`None` if using default encryption.
|
| 998 |
+
|
| 999 |
+
See
|
| 1000 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.destination_encryption_configuration`.
|
| 1001 |
+
"""
|
| 1002 |
+
return self.configuration.destination_encryption_configuration
|
| 1003 |
+
|
| 1004 |
+
@property
|
| 1005 |
+
def destination_table_description(self):
|
| 1006 |
+
"""Optional[str] name given to destination table.
|
| 1007 |
+
|
| 1008 |
+
See:
|
| 1009 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#DestinationTableProperties.FIELDS.description
|
| 1010 |
+
"""
|
| 1011 |
+
return self.configuration.destination_table_description
|
| 1012 |
+
|
| 1013 |
+
@property
|
| 1014 |
+
def destination_table_friendly_name(self):
|
| 1015 |
+
"""Optional[str] name given to destination table.
|
| 1016 |
+
|
| 1017 |
+
See:
|
| 1018 |
+
https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#DestinationTableProperties.FIELDS.friendly_name
|
| 1019 |
+
"""
|
| 1020 |
+
return self.configuration.destination_table_friendly_name
|
| 1021 |
+
|
| 1022 |
+
@property
|
| 1023 |
+
def range_partitioning(self):
|
| 1024 |
+
"""See
|
| 1025 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.range_partitioning`.
|
| 1026 |
+
"""
|
| 1027 |
+
return self.configuration.range_partitioning
|
| 1028 |
+
|
| 1029 |
+
@property
|
| 1030 |
+
def time_partitioning(self):
|
| 1031 |
+
"""See
|
| 1032 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.time_partitioning`.
|
| 1033 |
+
"""
|
| 1034 |
+
return self.configuration.time_partitioning
|
| 1035 |
+
|
| 1036 |
+
@property
|
| 1037 |
+
def use_avro_logical_types(self):
|
| 1038 |
+
"""See
|
| 1039 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.use_avro_logical_types`.
|
| 1040 |
+
"""
|
| 1041 |
+
return self.configuration.use_avro_logical_types
|
| 1042 |
+
|
| 1043 |
+
@property
|
| 1044 |
+
def clustering_fields(self):
|
| 1045 |
+
"""See
|
| 1046 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.clustering_fields`.
|
| 1047 |
+
"""
|
| 1048 |
+
return self.configuration.clustering_fields
|
| 1049 |
+
|
| 1050 |
+
@property
|
| 1051 |
+
def source_column_match(self) -> Optional[SourceColumnMatch]:
|
| 1052 |
+
"""See
|
| 1053 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.source_column_match`.
|
| 1054 |
+
"""
|
| 1055 |
+
return self.configuration.source_column_match
|
| 1056 |
+
|
| 1057 |
+
@property
|
| 1058 |
+
def date_format(self):
|
| 1059 |
+
"""See
|
| 1060 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.date_format`.
|
| 1061 |
+
"""
|
| 1062 |
+
return self.configuration.date_format
|
| 1063 |
+
|
| 1064 |
+
@property
|
| 1065 |
+
def datetime_format(self):
|
| 1066 |
+
"""See
|
| 1067 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.datetime_format`.
|
| 1068 |
+
"""
|
| 1069 |
+
return self.configuration.datetime_format
|
| 1070 |
+
|
| 1071 |
+
@property
|
| 1072 |
+
def time_zone(self):
|
| 1073 |
+
"""See
|
| 1074 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.time_zone`.
|
| 1075 |
+
"""
|
| 1076 |
+
return self.configuration.time_zone
|
| 1077 |
+
|
| 1078 |
+
@property
|
| 1079 |
+
def time_format(self):
|
| 1080 |
+
"""See
|
| 1081 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.time_format`.
|
| 1082 |
+
"""
|
| 1083 |
+
return self.configuration.time_format
|
| 1084 |
+
|
| 1085 |
+
@property
|
| 1086 |
+
def timestamp_format(self):
|
| 1087 |
+
"""See
|
| 1088 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.timestamp_format`.
|
| 1089 |
+
"""
|
| 1090 |
+
return self.configuration.timestamp_format
|
| 1091 |
+
|
| 1092 |
+
@property
|
| 1093 |
+
def schema_update_options(self):
|
| 1094 |
+
"""See
|
| 1095 |
+
:attr:`google.cloud.bigquery.job.LoadJobConfig.schema_update_options`.
|
| 1096 |
+
"""
|
| 1097 |
+
return self.configuration.schema_update_options
|
| 1098 |
+
|
| 1099 |
+
@property
|
| 1100 |
+
def input_file_bytes(self):
|
| 1101 |
+
"""Count of bytes loaded from source files.
|
| 1102 |
+
|
| 1103 |
+
Returns:
|
| 1104 |
+
Optional[int]: the count (None until set from the server).
|
| 1105 |
+
|
| 1106 |
+
Raises:
|
| 1107 |
+
ValueError: for invalid value types.
|
| 1108 |
+
"""
|
| 1109 |
+
return _helpers._int_or_none(
|
| 1110 |
+
_helpers._get_sub_prop(
|
| 1111 |
+
self._properties, ["statistics", "load", "inputFileBytes"]
|
| 1112 |
+
)
|
| 1113 |
+
)
|
| 1114 |
+
|
| 1115 |
+
@property
|
| 1116 |
+
def input_files(self):
|
| 1117 |
+
"""Count of source files.
|
| 1118 |
+
|
| 1119 |
+
Returns:
|
| 1120 |
+
Optional[int]: the count (None until set from the server).
|
| 1121 |
+
"""
|
| 1122 |
+
return _helpers._int_or_none(
|
| 1123 |
+
_helpers._get_sub_prop(
|
| 1124 |
+
self._properties, ["statistics", "load", "inputFiles"]
|
| 1125 |
+
)
|
| 1126 |
+
)
|
| 1127 |
+
|
| 1128 |
+
@property
|
| 1129 |
+
def output_bytes(self):
|
| 1130 |
+
"""Count of bytes saved to destination table.
|
| 1131 |
+
|
| 1132 |
+
Returns:
|
| 1133 |
+
Optional[int]: the count (None until set from the server).
|
| 1134 |
+
"""
|
| 1135 |
+
return _helpers._int_or_none(
|
| 1136 |
+
_helpers._get_sub_prop(
|
| 1137 |
+
self._properties, ["statistics", "load", "outputBytes"]
|
| 1138 |
+
)
|
| 1139 |
+
)
|
| 1140 |
+
|
| 1141 |
+
@property
|
| 1142 |
+
def output_rows(self):
|
| 1143 |
+
"""Count of rows saved to destination table.
|
| 1144 |
+
|
| 1145 |
+
Returns:
|
| 1146 |
+
Optional[int]: the count (None until set from the server).
|
| 1147 |
+
"""
|
| 1148 |
+
return _helpers._int_or_none(
|
| 1149 |
+
_helpers._get_sub_prop(
|
| 1150 |
+
self._properties, ["statistics", "load", "outputRows"]
|
| 1151 |
+
)
|
| 1152 |
+
)
|
| 1153 |
+
|
| 1154 |
+
def to_api_repr(self):
|
| 1155 |
+
"""Generate a resource for :meth:`_begin`."""
|
| 1156 |
+
# Exclude statistics, if set.
|
| 1157 |
+
return {
|
| 1158 |
+
"jobReference": self._properties["jobReference"],
|
| 1159 |
+
"configuration": self._properties["configuration"],
|
| 1160 |
+
}
|
| 1161 |
+
|
| 1162 |
+
@classmethod
|
| 1163 |
+
def from_api_repr(cls, resource: dict, client) -> "LoadJob":
|
| 1164 |
+
"""Factory: construct a job given its API representation
|
| 1165 |
+
|
| 1166 |
+
.. note::
|
| 1167 |
+
|
| 1168 |
+
This method assumes that the project found in the resource matches
|
| 1169 |
+
the client's project.
|
| 1170 |
+
|
| 1171 |
+
Args:
|
| 1172 |
+
resource (Dict): dataset job representation returned from the API
|
| 1173 |
+
|
| 1174 |
+
client (google.cloud.bigquery.client.Client):
|
| 1175 |
+
Client which holds credentials and project
|
| 1176 |
+
configuration for the dataset.
|
| 1177 |
+
|
| 1178 |
+
Returns:
|
| 1179 |
+
google.cloud.bigquery.job.LoadJob: Job parsed from ``resource``.
|
| 1180 |
+
"""
|
| 1181 |
+
cls._check_resource_config(resource)
|
| 1182 |
+
job_ref = _JobReference._from_api_repr(resource["jobReference"])
|
| 1183 |
+
job = cls(job_ref, None, None, client)
|
| 1184 |
+
job._set_properties(resource)
|
| 1185 |
+
return job
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/job/query.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/magics/__init__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020 Google LLC
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
from google.cloud.bigquery.magics.magics import context
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# For backwards compatibility we need to make the context available in the path
|
| 19 |
+
# google.cloud.bigquery.magics.context
|
| 20 |
+
__all__ = ("context",)
|
data/conda_envs/evalclaw/lib/python3.11/site-packages/google/cloud/bigquery/magics/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (317 Bytes). View file
|
|
|