apache-airflow-providers-google 15.1.0rc1__py3-none-any.whl → 19.1.0rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. airflow/providers/google/3rd-party-licenses/NOTICE +2 -12
  2. airflow/providers/google/__init__.py +3 -3
  3. airflow/providers/google/ads/hooks/ads.py +39 -5
  4. airflow/providers/google/ads/operators/ads.py +2 -2
  5. airflow/providers/google/ads/transfers/ads_to_gcs.py +2 -2
  6. airflow/providers/google/assets/gcs.py +1 -11
  7. airflow/providers/google/cloud/bundles/__init__.py +16 -0
  8. airflow/providers/google/cloud/bundles/gcs.py +161 -0
  9. airflow/providers/google/cloud/hooks/bigquery.py +166 -281
  10. airflow/providers/google/cloud/hooks/cloud_composer.py +287 -14
  11. airflow/providers/google/cloud/hooks/cloud_logging.py +109 -0
  12. airflow/providers/google/cloud/hooks/cloud_run.py +17 -9
  13. airflow/providers/google/cloud/hooks/cloud_sql.py +101 -22
  14. airflow/providers/google/cloud/hooks/cloud_storage_transfer_service.py +27 -6
  15. airflow/providers/google/cloud/hooks/compute_ssh.py +5 -1
  16. airflow/providers/google/cloud/hooks/datacatalog.py +9 -1
  17. airflow/providers/google/cloud/hooks/dataflow.py +71 -94
  18. airflow/providers/google/cloud/hooks/datafusion.py +1 -1
  19. airflow/providers/google/cloud/hooks/dataplex.py +1 -1
  20. airflow/providers/google/cloud/hooks/dataprep.py +1 -1
  21. airflow/providers/google/cloud/hooks/dataproc.py +72 -71
  22. airflow/providers/google/cloud/hooks/gcs.py +111 -14
  23. airflow/providers/google/cloud/hooks/gen_ai.py +196 -0
  24. airflow/providers/google/cloud/hooks/kubernetes_engine.py +2 -2
  25. airflow/providers/google/cloud/hooks/looker.py +6 -1
  26. airflow/providers/google/cloud/hooks/mlengine.py +3 -2
  27. airflow/providers/google/cloud/hooks/secret_manager.py +102 -10
  28. airflow/providers/google/cloud/hooks/spanner.py +73 -8
  29. airflow/providers/google/cloud/hooks/stackdriver.py +10 -8
  30. airflow/providers/google/cloud/hooks/translate.py +1 -1
  31. airflow/providers/google/cloud/hooks/vertex_ai/auto_ml.py +0 -209
  32. airflow/providers/google/cloud/hooks/vertex_ai/batch_prediction_job.py +2 -2
  33. airflow/providers/google/cloud/hooks/vertex_ai/custom_job.py +27 -1
  34. airflow/providers/google/cloud/hooks/vertex_ai/experiment_service.py +202 -0
  35. airflow/providers/google/cloud/hooks/vertex_ai/feature_store.py +307 -7
  36. airflow/providers/google/cloud/hooks/vertex_ai/generative_model.py +79 -75
  37. airflow/providers/google/cloud/hooks/vertex_ai/ray.py +223 -0
  38. airflow/providers/google/cloud/hooks/vision.py +2 -2
  39. airflow/providers/google/cloud/hooks/workflows.py +1 -1
  40. airflow/providers/google/cloud/links/alloy_db.py +0 -46
  41. airflow/providers/google/cloud/links/base.py +77 -13
  42. airflow/providers/google/cloud/links/bigquery.py +0 -47
  43. airflow/providers/google/cloud/links/bigquery_dts.py +0 -20
  44. airflow/providers/google/cloud/links/bigtable.py +0 -48
  45. airflow/providers/google/cloud/links/cloud_build.py +0 -73
  46. airflow/providers/google/cloud/links/cloud_functions.py +0 -33
  47. airflow/providers/google/cloud/links/cloud_memorystore.py +0 -58
  48. airflow/providers/google/cloud/links/{life_sciences.py → cloud_run.py} +5 -27
  49. airflow/providers/google/cloud/links/cloud_sql.py +0 -33
  50. airflow/providers/google/cloud/links/cloud_storage_transfer.py +17 -44
  51. airflow/providers/google/cloud/links/cloud_tasks.py +7 -26
  52. airflow/providers/google/cloud/links/compute.py +0 -58
  53. airflow/providers/google/cloud/links/data_loss_prevention.py +0 -169
  54. airflow/providers/google/cloud/links/datacatalog.py +23 -54
  55. airflow/providers/google/cloud/links/dataflow.py +0 -34
  56. airflow/providers/google/cloud/links/dataform.py +0 -64
  57. airflow/providers/google/cloud/links/datafusion.py +1 -96
  58. airflow/providers/google/cloud/links/dataplex.py +0 -154
  59. airflow/providers/google/cloud/links/dataprep.py +0 -24
  60. airflow/providers/google/cloud/links/dataproc.py +11 -95
  61. airflow/providers/google/cloud/links/datastore.py +0 -31
  62. airflow/providers/google/cloud/links/kubernetes_engine.py +9 -60
  63. airflow/providers/google/cloud/links/managed_kafka.py +0 -70
  64. airflow/providers/google/cloud/links/mlengine.py +0 -70
  65. airflow/providers/google/cloud/links/pubsub.py +0 -32
  66. airflow/providers/google/cloud/links/spanner.py +0 -33
  67. airflow/providers/google/cloud/links/stackdriver.py +0 -30
  68. airflow/providers/google/cloud/links/translate.py +17 -187
  69. airflow/providers/google/cloud/links/vertex_ai.py +28 -195
  70. airflow/providers/google/cloud/links/workflows.py +0 -52
  71. airflow/providers/google/cloud/log/gcs_task_handler.py +17 -9
  72. airflow/providers/google/cloud/log/stackdriver_task_handler.py +9 -6
  73. airflow/providers/google/cloud/openlineage/CloudStorageTransferJobFacet.json +68 -0
  74. airflow/providers/google/cloud/openlineage/CloudStorageTransferRunFacet.json +60 -0
  75. airflow/providers/google/cloud/openlineage/DataFusionRunFacet.json +32 -0
  76. airflow/providers/google/cloud/openlineage/facets.py +102 -1
  77. airflow/providers/google/cloud/openlineage/mixins.py +10 -8
  78. airflow/providers/google/cloud/openlineage/utils.py +15 -1
  79. airflow/providers/google/cloud/operators/alloy_db.py +70 -55
  80. airflow/providers/google/cloud/operators/bigquery.py +73 -636
  81. airflow/providers/google/cloud/operators/bigquery_dts.py +3 -5
  82. airflow/providers/google/cloud/operators/bigtable.py +36 -7
  83. airflow/providers/google/cloud/operators/cloud_base.py +21 -1
  84. airflow/providers/google/cloud/operators/cloud_batch.py +2 -2
  85. airflow/providers/google/cloud/operators/cloud_build.py +75 -32
  86. airflow/providers/google/cloud/operators/cloud_composer.py +128 -40
  87. airflow/providers/google/cloud/operators/cloud_logging_sink.py +341 -0
  88. airflow/providers/google/cloud/operators/cloud_memorystore.py +69 -43
  89. airflow/providers/google/cloud/operators/cloud_run.py +23 -5
  90. airflow/providers/google/cloud/operators/cloud_sql.py +8 -16
  91. airflow/providers/google/cloud/operators/cloud_storage_transfer_service.py +92 -11
  92. airflow/providers/google/cloud/operators/compute.py +8 -40
  93. airflow/providers/google/cloud/operators/datacatalog.py +157 -21
  94. airflow/providers/google/cloud/operators/dataflow.py +38 -15
  95. airflow/providers/google/cloud/operators/dataform.py +15 -5
  96. airflow/providers/google/cloud/operators/datafusion.py +41 -20
  97. airflow/providers/google/cloud/operators/dataplex.py +193 -109
  98. airflow/providers/google/cloud/operators/dataprep.py +1 -5
  99. airflow/providers/google/cloud/operators/dataproc.py +78 -35
  100. airflow/providers/google/cloud/operators/dataproc_metastore.py +96 -88
  101. airflow/providers/google/cloud/operators/datastore.py +22 -6
  102. airflow/providers/google/cloud/operators/dlp.py +6 -29
  103. airflow/providers/google/cloud/operators/functions.py +16 -7
  104. airflow/providers/google/cloud/operators/gcs.py +10 -8
  105. airflow/providers/google/cloud/operators/gen_ai.py +389 -0
  106. airflow/providers/google/cloud/operators/kubernetes_engine.py +60 -99
  107. airflow/providers/google/cloud/operators/looker.py +1 -1
  108. airflow/providers/google/cloud/operators/managed_kafka.py +107 -52
  109. airflow/providers/google/cloud/operators/natural_language.py +1 -1
  110. airflow/providers/google/cloud/operators/pubsub.py +60 -14
  111. airflow/providers/google/cloud/operators/spanner.py +25 -12
  112. airflow/providers/google/cloud/operators/speech_to_text.py +1 -2
  113. airflow/providers/google/cloud/operators/stackdriver.py +1 -9
  114. airflow/providers/google/cloud/operators/tasks.py +1 -12
  115. airflow/providers/google/cloud/operators/text_to_speech.py +1 -2
  116. airflow/providers/google/cloud/operators/translate.py +40 -16
  117. airflow/providers/google/cloud/operators/translate_speech.py +1 -2
  118. airflow/providers/google/cloud/operators/vertex_ai/auto_ml.py +39 -19
  119. airflow/providers/google/cloud/operators/vertex_ai/batch_prediction_job.py +29 -9
  120. airflow/providers/google/cloud/operators/vertex_ai/custom_job.py +54 -26
  121. airflow/providers/google/cloud/operators/vertex_ai/dataset.py +70 -8
  122. airflow/providers/google/cloud/operators/vertex_ai/endpoint_service.py +43 -9
  123. airflow/providers/google/cloud/operators/vertex_ai/experiment_service.py +435 -0
  124. airflow/providers/google/cloud/operators/vertex_ai/feature_store.py +532 -1
  125. airflow/providers/google/cloud/operators/vertex_ai/generative_model.py +135 -116
  126. airflow/providers/google/cloud/operators/vertex_ai/hyperparameter_tuning_job.py +11 -9
  127. airflow/providers/google/cloud/operators/vertex_ai/model_service.py +57 -11
  128. airflow/providers/google/cloud/operators/vertex_ai/pipeline_job.py +30 -7
  129. airflow/providers/google/cloud/operators/vertex_ai/ray.py +393 -0
  130. airflow/providers/google/cloud/operators/video_intelligence.py +1 -1
  131. airflow/providers/google/cloud/operators/vision.py +2 -2
  132. airflow/providers/google/cloud/operators/workflows.py +18 -15
  133. airflow/providers/google/cloud/sensors/bigquery.py +2 -2
  134. airflow/providers/google/cloud/sensors/bigquery_dts.py +2 -2
  135. airflow/providers/google/cloud/sensors/bigtable.py +11 -4
  136. airflow/providers/google/cloud/sensors/cloud_composer.py +533 -29
  137. airflow/providers/google/cloud/sensors/cloud_storage_transfer_service.py +2 -2
  138. airflow/providers/google/cloud/sensors/dataflow.py +26 -9
  139. airflow/providers/google/cloud/sensors/dataform.py +2 -2
  140. airflow/providers/google/cloud/sensors/datafusion.py +4 -4
  141. airflow/providers/google/cloud/sensors/dataplex.py +2 -2
  142. airflow/providers/google/cloud/sensors/dataprep.py +2 -2
  143. airflow/providers/google/cloud/sensors/dataproc.py +2 -2
  144. airflow/providers/google/cloud/sensors/dataproc_metastore.py +2 -2
  145. airflow/providers/google/cloud/sensors/gcs.py +4 -4
  146. airflow/providers/google/cloud/sensors/looker.py +2 -2
  147. airflow/providers/google/cloud/sensors/pubsub.py +4 -4
  148. airflow/providers/google/cloud/sensors/tasks.py +2 -2
  149. airflow/providers/google/cloud/sensors/vertex_ai/feature_store.py +2 -2
  150. airflow/providers/google/cloud/sensors/workflows.py +2 -2
  151. airflow/providers/google/cloud/transfers/adls_to_gcs.py +1 -1
  152. airflow/providers/google/cloud/transfers/azure_blob_to_gcs.py +2 -2
  153. airflow/providers/google/cloud/transfers/azure_fileshare_to_gcs.py +2 -2
  154. airflow/providers/google/cloud/transfers/bigquery_to_bigquery.py +11 -8
  155. airflow/providers/google/cloud/transfers/bigquery_to_gcs.py +4 -4
  156. airflow/providers/google/cloud/transfers/bigquery_to_mssql.py +7 -3
  157. airflow/providers/google/cloud/transfers/bigquery_to_mysql.py +12 -1
  158. airflow/providers/google/cloud/transfers/bigquery_to_postgres.py +24 -10
  159. airflow/providers/google/cloud/transfers/bigquery_to_sql.py +104 -5
  160. airflow/providers/google/cloud/transfers/calendar_to_gcs.py +1 -1
  161. airflow/providers/google/cloud/transfers/cassandra_to_gcs.py +2 -2
  162. airflow/providers/google/cloud/transfers/facebook_ads_to_gcs.py +3 -3
  163. airflow/providers/google/cloud/transfers/gcs_to_bigquery.py +20 -12
  164. airflow/providers/google/cloud/transfers/gcs_to_gcs.py +2 -2
  165. airflow/providers/google/cloud/transfers/gcs_to_local.py +5 -3
  166. airflow/providers/google/cloud/transfers/gcs_to_sftp.py +10 -4
  167. airflow/providers/google/cloud/transfers/gdrive_to_gcs.py +6 -2
  168. airflow/providers/google/cloud/transfers/gdrive_to_local.py +2 -2
  169. airflow/providers/google/cloud/transfers/http_to_gcs.py +193 -0
  170. airflow/providers/google/cloud/transfers/local_to_gcs.py +2 -2
  171. airflow/providers/google/cloud/transfers/mssql_to_gcs.py +1 -1
  172. airflow/providers/google/cloud/transfers/oracle_to_gcs.py +36 -11
  173. airflow/providers/google/cloud/transfers/postgres_to_gcs.py +42 -9
  174. airflow/providers/google/cloud/transfers/s3_to_gcs.py +12 -6
  175. airflow/providers/google/cloud/transfers/salesforce_to_gcs.py +2 -2
  176. airflow/providers/google/cloud/transfers/sftp_to_gcs.py +13 -4
  177. airflow/providers/google/cloud/transfers/sheets_to_gcs.py +3 -3
  178. airflow/providers/google/cloud/transfers/sql_to_gcs.py +10 -10
  179. airflow/providers/google/cloud/triggers/bigquery.py +75 -34
  180. airflow/providers/google/cloud/triggers/cloud_build.py +1 -1
  181. airflow/providers/google/cloud/triggers/cloud_composer.py +302 -46
  182. airflow/providers/google/cloud/triggers/cloud_run.py +2 -2
  183. airflow/providers/google/cloud/triggers/cloud_storage_transfer_service.py +91 -1
  184. airflow/providers/google/cloud/triggers/dataflow.py +122 -0
  185. airflow/providers/google/cloud/triggers/datafusion.py +1 -1
  186. airflow/providers/google/cloud/triggers/dataplex.py +14 -2
  187. airflow/providers/google/cloud/triggers/dataproc.py +122 -52
  188. airflow/providers/google/cloud/triggers/kubernetes_engine.py +45 -27
  189. airflow/providers/google/cloud/triggers/mlengine.py +1 -1
  190. airflow/providers/google/cloud/triggers/pubsub.py +15 -19
  191. airflow/providers/google/cloud/utils/bigquery_get_data.py +1 -1
  192. airflow/providers/google/cloud/utils/credentials_provider.py +1 -1
  193. airflow/providers/google/cloud/utils/field_validator.py +1 -2
  194. airflow/providers/google/common/auth_backend/google_openid.py +4 -4
  195. airflow/providers/google/common/deprecated.py +2 -1
  196. airflow/providers/google/common/hooks/base_google.py +27 -8
  197. airflow/providers/google/common/links/storage.py +0 -22
  198. airflow/providers/google/common/utils/get_secret.py +31 -0
  199. airflow/providers/google/common/utils/id_token_credentials.py +3 -4
  200. airflow/providers/google/firebase/operators/firestore.py +2 -2
  201. airflow/providers/google/get_provider_info.py +56 -52
  202. airflow/providers/google/go_module_utils.py +35 -3
  203. airflow/providers/google/leveldb/hooks/leveldb.py +26 -1
  204. airflow/providers/google/leveldb/operators/leveldb.py +2 -2
  205. airflow/providers/google/marketing_platform/hooks/display_video.py +3 -109
  206. airflow/providers/google/marketing_platform/links/analytics_admin.py +5 -14
  207. airflow/providers/google/marketing_platform/operators/analytics_admin.py +1 -2
  208. airflow/providers/google/marketing_platform/operators/campaign_manager.py +5 -5
  209. airflow/providers/google/marketing_platform/operators/display_video.py +28 -489
  210. airflow/providers/google/marketing_platform/operators/search_ads.py +2 -2
  211. airflow/providers/google/marketing_platform/sensors/campaign_manager.py +2 -2
  212. airflow/providers/google/marketing_platform/sensors/display_video.py +3 -63
  213. airflow/providers/google/suite/hooks/calendar.py +1 -1
  214. airflow/providers/google/suite/hooks/sheets.py +15 -1
  215. airflow/providers/google/suite/operators/sheets.py +8 -3
  216. airflow/providers/google/suite/sensors/drive.py +2 -2
  217. airflow/providers/google/suite/transfers/gcs_to_gdrive.py +2 -2
  218. airflow/providers/google/suite/transfers/gcs_to_sheets.py +1 -1
  219. airflow/providers/google/suite/transfers/local_to_drive.py +3 -3
  220. airflow/providers/google/suite/transfers/sql_to_sheets.py +5 -4
  221. airflow/providers/google/version_compat.py +15 -1
  222. {apache_airflow_providers_google-15.1.0rc1.dist-info → apache_airflow_providers_google-19.1.0rc1.dist-info}/METADATA +92 -48
  223. apache_airflow_providers_google-19.1.0rc1.dist-info/RECORD +331 -0
  224. apache_airflow_providers_google-19.1.0rc1.dist-info/licenses/NOTICE +5 -0
  225. airflow/providers/google/cloud/hooks/automl.py +0 -673
  226. airflow/providers/google/cloud/hooks/life_sciences.py +0 -159
  227. airflow/providers/google/cloud/links/automl.py +0 -193
  228. airflow/providers/google/cloud/operators/automl.py +0 -1362
  229. airflow/providers/google/cloud/operators/life_sciences.py +0 -119
  230. airflow/providers/google/cloud/operators/mlengine.py +0 -112
  231. apache_airflow_providers_google-15.1.0rc1.dist-info/RECORD +0 -321
  232. {apache_airflow_providers_google-15.1.0rc1.dist-info → apache_airflow_providers_google-19.1.0rc1.dist-info}/WHEEL +0 -0
  233. {apache_airflow_providers_google-15.1.0rc1.dist-info → apache_airflow_providers_google-19.1.0rc1.dist-info}/entry_points.txt +0 -0
  234. {airflow/providers/google → apache_airflow_providers_google-19.1.0rc1.dist-info/licenses}/LICENSE +0 -0
@@ -20,17 +20,18 @@
20
20
 
21
21
  from __future__ import annotations
22
22
 
23
- import asyncio
24
23
  import json
25
24
  import logging
26
25
  import re
27
26
  import time
28
27
  import uuid
28
+ import warnings
29
29
  from collections.abc import Iterable, Mapping, Sequence
30
30
  from copy import deepcopy
31
31
  from datetime import datetime, timedelta
32
- from typing import TYPE_CHECKING, Any, NoReturn, Union, cast
32
+ from typing import TYPE_CHECKING, Any, Literal, NoReturn, cast, overload
33
33
 
34
+ import pendulum
34
35
  from aiohttp import ClientSession as ClientSession
35
36
  from gcloud.aio.bigquery import Job, Table as Table_async
36
37
  from google.cloud.bigquery import (
@@ -58,7 +59,11 @@ from pandas_gbq import read_gbq
58
59
  from pandas_gbq.gbq import GbqConnector # noqa: F401 used in ``airflow.contrib.hooks.bigquery``
59
60
  from sqlalchemy import create_engine
60
61
 
61
- from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
62
+ from airflow.exceptions import (
63
+ AirflowException,
64
+ AirflowOptionalProviderFeatureException,
65
+ AirflowProviderDeprecationWarning,
66
+ )
62
67
  from airflow.providers.common.compat.lineage.hook import get_hook_lineage_collector
63
68
  from airflow.providers.common.sql.hooks.sql import DbApiHook
64
69
  from airflow.providers.google.cloud.utils.bigquery import bq_cast
@@ -66,24 +71,30 @@ from airflow.providers.google.cloud.utils.credentials_provider import _get_scope
66
71
  from airflow.providers.google.common.consts import CLIENT_INFO
67
72
  from airflow.providers.google.common.deprecated import deprecated
68
73
  from airflow.providers.google.common.hooks.base_google import (
74
+ _UNSET,
69
75
  PROVIDE_PROJECT_ID,
70
76
  GoogleBaseAsyncHook,
71
77
  GoogleBaseHook,
72
78
  get_field,
73
79
  )
80
+ from airflow.providers.google.version_compat import AIRFLOW_V_3_0_PLUS
74
81
  from airflow.utils.hashlib_wrapper import md5
75
82
  from airflow.utils.helpers import convert_camel_to_snake
76
83
  from airflow.utils.log.logging_mixin import LoggingMixin
84
+ from airflow.utils.types import DagRunType
77
85
 
78
86
  if TYPE_CHECKING:
79
87
  import pandas as pd
88
+ import polars as pl
80
89
  from google.api_core.page_iterator import HTTPIterator
81
90
  from google.api_core.retry import Retry
82
91
  from requests import Session
83
92
 
93
+ from airflow.sdk import Context
94
+
84
95
  log = logging.getLogger(__name__)
85
96
 
86
- BigQueryJob = Union[CopyJob, QueryJob, LoadJob, ExtractJob]
97
+ BigQueryJob = CopyJob | QueryJob | LoadJob | ExtractJob
87
98
 
88
99
 
89
100
  class BigQueryHook(GoogleBaseHook, DbApiHook):
@@ -151,21 +162,47 @@ class BigQueryHook(GoogleBaseHook, DbApiHook):
151
162
 
152
163
  def __init__(
153
164
  self,
154
- use_legacy_sql: bool = True,
155
- location: str | None = None,
156
- priority: str = "INTERACTIVE",
157
- api_resource_configs: dict | None = None,
165
+ use_legacy_sql: bool | object = _UNSET,
166
+ location: str | None | object = _UNSET,
167
+ priority: str | object = _UNSET,
168
+ api_resource_configs: dict | None | object = _UNSET,
158
169
  impersonation_scopes: str | Sequence[str] | None = None,
159
- labels: dict | None = None,
170
+ labels: dict | None | object = _UNSET,
160
171
  **kwargs,
161
172
  ) -> None:
162
173
  super().__init__(**kwargs)
163
- self.use_legacy_sql: bool = self._get_field("use_legacy_sql", use_legacy_sql)
164
- self.location: str | None = self._get_field("location", location)
165
- self.priority: str = self._get_field("priority", priority)
174
+ # Use sentinel pattern to distinguish "not provided" from "explicitly provided"
175
+ if use_legacy_sql is _UNSET:
176
+ value = self._get_field("use_legacy_sql", _UNSET)
177
+ self.use_legacy_sql: bool = value if value is not None else True
178
+ else:
179
+ self.use_legacy_sql = use_legacy_sql # type: ignore[assignment]
180
+
181
+ if location is _UNSET:
182
+ self.location: str | None = self._get_field("location", _UNSET)
183
+ else:
184
+ self.location = location # type: ignore[assignment]
185
+
186
+ if priority is _UNSET:
187
+ value = self._get_field("priority", _UNSET)
188
+ self.priority: str = value if value is not None else "INTERACTIVE"
189
+ else:
190
+ self.priority = priority # type: ignore[assignment]
191
+
166
192
  self.running_job_id: str | None = None
167
- self.api_resource_configs: dict = self._get_field("api_resource_configs", api_resource_configs or {})
168
- self.labels = self._get_field("labels", labels or {})
193
+
194
+ if api_resource_configs is _UNSET:
195
+ value = self._get_field("api_resource_configs", _UNSET)
196
+ self.api_resource_configs: dict = value if value is not None else {}
197
+ else:
198
+ self.api_resource_configs = api_resource_configs or {} # type: ignore[assignment]
199
+
200
+ if labels is _UNSET:
201
+ value = self._get_field("labels", _UNSET)
202
+ self.labels = value if value is not None else {}
203
+ else:
204
+ self.labels = labels or {} # type: ignore[assignment]
205
+
169
206
  self.impersonation_scopes: str | Sequence[str] | None = impersonation_scopes
170
207
 
171
208
  def get_conn(self) -> BigQueryConnection:
@@ -275,15 +312,57 @@ class BigQueryHook(GoogleBaseHook, DbApiHook):
275
312
  """
276
313
  raise NotImplementedError()
277
314
 
278
- def get_pandas_df(
315
+ def _get_pandas_df(
279
316
  self,
280
317
  sql: str,
281
318
  parameters: Iterable | Mapping[str, Any] | None = None,
282
319
  dialect: str | None = None,
283
320
  **kwargs,
284
321
  ) -> pd.DataFrame:
322
+ if dialect is None:
323
+ dialect = "legacy" if self.use_legacy_sql else "standard"
324
+
325
+ credentials, project_id = self.get_credentials_and_project_id()
326
+
327
+ return read_gbq(sql, project_id=project_id, dialect=dialect, credentials=credentials, **kwargs)
328
+
329
+ def _get_polars_df(self, sql, parameters=None, dialect=None, **kwargs) -> pl.DataFrame:
330
+ try:
331
+ import polars as pl
332
+ except ImportError:
333
+ raise AirflowOptionalProviderFeatureException(
334
+ "Polars is not installed. Please install it with `pip install polars`."
335
+ )
336
+
337
+ if dialect is None:
338
+ dialect = "legacy" if self.use_legacy_sql else "standard"
339
+
340
+ credentials, project_id = self.get_credentials_and_project_id()
341
+
342
+ pandas_df = read_gbq(sql, project_id=project_id, dialect=dialect, credentials=credentials, **kwargs)
343
+ return pl.from_pandas(pandas_df)
344
+
345
+ @overload
346
+ def get_df(
347
+ self, sql, parameters=None, dialect=None, *, df_type: Literal["pandas"] = "pandas", **kwargs
348
+ ) -> pd.DataFrame: ...
349
+
350
+ @overload
351
+ def get_df(
352
+ self, sql, parameters=None, dialect=None, *, df_type: Literal["polars"], **kwargs
353
+ ) -> pl.DataFrame: ...
354
+
355
+ def get_df(
356
+ self,
357
+ sql,
358
+ parameters=None,
359
+ dialect=None,
360
+ *,
361
+ df_type: Literal["pandas", "polars"] = "pandas",
362
+ **kwargs,
363
+ ) -> pd.DataFrame | pl.DataFrame:
285
364
  """
286
- Get a Pandas DataFrame for the BigQuery results.
365
+ Get a DataFrame for the BigQuery results.
287
366
 
288
367
  The DbApiHook method must be overridden because Pandas doesn't support
289
368
  PEP 249 connections, except for SQLite.
@@ -299,12 +378,19 @@ class BigQueryHook(GoogleBaseHook, DbApiHook):
299
378
  defaults to use `self.use_legacy_sql` if not specified
300
379
  :param kwargs: (optional) passed into pandas_gbq.read_gbq method
301
380
  """
302
- if dialect is None:
303
- dialect = "legacy" if self.use_legacy_sql else "standard"
381
+ if df_type == "polars":
382
+ return self._get_polars_df(sql, parameters, dialect, **kwargs)
304
383
 
305
- credentials, project_id = self.get_credentials_and_project_id()
384
+ if df_type == "pandas":
385
+ return self._get_pandas_df(sql, parameters, dialect, **kwargs)
306
386
 
307
- return read_gbq(sql, project_id=project_id, dialect=dialect, credentials=credentials, **kwargs)
387
+ @deprecated(
388
+ planned_removal_date="November 30, 2025",
389
+ use_instead="airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.get_df",
390
+ category=AirflowProviderDeprecationWarning,
391
+ )
392
+ def get_pandas_df(self, sql, parameters=None, dialect=None, **kwargs):
393
+ return self._get_pandas_df(sql, parameters, dialect, **kwargs)
308
394
 
309
395
  @GoogleBaseHook.fallback_to_default_project_id
310
396
  def table_exists(self, dataset_id: str, table_id: str, project_id: str) -> bool:
@@ -346,135 +432,6 @@ class BigQueryHook(GoogleBaseHook, DbApiHook):
346
432
  except NotFound:
347
433
  return False
348
434
 
349
- @deprecated(
350
- planned_removal_date="July 30, 2025",
351
- use_instead="airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.create_table",
352
- category=AirflowProviderDeprecationWarning,
353
- )
354
- @GoogleBaseHook.fallback_to_default_project_id
355
- def create_empty_table(
356
- self,
357
- project_id: str = PROVIDE_PROJECT_ID,
358
- dataset_id: str | None = None,
359
- table_id: str | None = None,
360
- table_resource: dict[str, Any] | None = None,
361
- schema_fields: list | None = None,
362
- time_partitioning: dict | None = None,
363
- cluster_fields: list[str] | None = None,
364
- labels: dict | None = None,
365
- view: dict | None = None,
366
- materialized_view: dict | None = None,
367
- encryption_configuration: dict | None = None,
368
- retry: Retry = DEFAULT_RETRY,
369
- location: str | None = None,
370
- exists_ok: bool = True,
371
- ) -> Table:
372
- """
373
- Create a new, empty table in the dataset.
374
-
375
- To create a view, which is defined by a SQL query, parse a dictionary to
376
- the *view* argument.
377
-
378
- :param project_id: The project to create the table into.
379
- :param dataset_id: The dataset to create the table into.
380
- :param table_id: The Name of the table to be created.
381
- :param table_resource: Table resource as described in documentation:
382
- https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#Table
383
- If provided all other parameters are ignored.
384
- :param schema_fields: If set, the schema field list as defined here:
385
- https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.load.schema
386
-
387
- .. code-block:: python
388
-
389
- schema_fields = [
390
- {"name": "emp_name", "type": "STRING", "mode": "REQUIRED"},
391
- {"name": "salary", "type": "INTEGER", "mode": "NULLABLE"},
392
- ]
393
-
394
- :param labels: a dictionary containing labels for the table, passed to BigQuery
395
- :param retry: Optional. How to retry the RPC.
396
- :param time_partitioning: configure optional time partitioning fields i.e.
397
- partition by field, type and expiration as per API specifications.
398
-
399
- .. seealso::
400
- https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#timePartitioning
401
- :param cluster_fields: [Optional] The fields used for clustering.
402
- BigQuery supports clustering for both partitioned and
403
- non-partitioned tables.
404
- https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#clustering.fields
405
- :param view: [Optional] A dictionary containing definition for the view.
406
- If set, it will create a view instead of a table:
407
- https://cloud.google.com/bigquery/docs/reference/rest/v2/tables#ViewDefinition
408
-
409
- .. code-block:: python
410
-
411
- view = {
412
- "query": "SELECT * FROM `test-project-id.test_dataset_id.test_table_prefix*` LIMIT 1000",
413
- "useLegacySql": False,
414
- }
415
-
416
- :param materialized_view: [Optional] The materialized view definition.
417
- :param encryption_configuration: [Optional] Custom encryption configuration (e.g., Cloud KMS keys).
418
-
419
- .. code-block:: python
420
-
421
- encryption_configuration = {
422
- "kmsKeyName": "projects/testp/locations/us/keyRings/test-kr/cryptoKeys/test-key",
423
- }
424
-
425
- :param num_retries: Maximum number of retries in case of connection problems.
426
- :param location: (Optional) The geographic location where the table should reside.
427
- :param exists_ok: If ``True``, ignore "already exists" errors when creating the table.
428
- :return: Created table
429
- """
430
- _table_resource: dict[str, Any] = {}
431
-
432
- if self.location:
433
- _table_resource["location"] = self.location
434
-
435
- if schema_fields:
436
- _table_resource["schema"] = {"fields": schema_fields}
437
-
438
- if time_partitioning:
439
- _table_resource["timePartitioning"] = time_partitioning
440
-
441
- if cluster_fields:
442
- _table_resource["clustering"] = {"fields": cluster_fields}
443
-
444
- if labels:
445
- _table_resource["labels"] = labels
446
-
447
- if view:
448
- _table_resource["view"] = view
449
-
450
- if materialized_view:
451
- _table_resource["materializedView"] = materialized_view
452
-
453
- if encryption_configuration:
454
- _table_resource["encryptionConfiguration"] = encryption_configuration
455
-
456
- table_resource = table_resource or _table_resource
457
- table_resource = self._resolve_table_reference(
458
- table_resource=table_resource,
459
- project_id=project_id,
460
- dataset_id=dataset_id,
461
- table_id=table_id,
462
- )
463
- table = Table.from_api_repr(table_resource)
464
- result = self.get_client(project_id=project_id, location=location).create_table(
465
- table=table, exists_ok=exists_ok, retry=retry
466
- )
467
- get_hook_lineage_collector().add_output_asset(
468
- context=self,
469
- scheme="bigquery",
470
- asset_kwargs={
471
- "project_id": result.project,
472
- "dataset_id": result.dataset_id,
473
- "table_id": result.table_id,
474
- },
475
- )
476
- return result
477
-
478
435
  @GoogleBaseHook.fallback_to_default_project_id
479
436
  def create_table(
480
437
  self,
@@ -861,7 +818,7 @@ class BigQueryHook(GoogleBaseHook, DbApiHook):
861
818
  if return_iterator:
862
819
  # The iterator returned by list_datasets() is a HTTPIterator but annotated
863
820
  # as Iterator
864
- return iterator # type: ignore
821
+ return iterator # type: ignore
865
822
 
866
823
  datasets_list = list(iterator)
867
824
  self.log.info("Datasets List: %s", len(datasets_list))
@@ -1349,7 +1306,16 @@ class BigQueryHook(GoogleBaseHook, DbApiHook):
1349
1306
  job_api_repr.result(timeout=timeout, retry=retry)
1350
1307
  return job_api_repr
1351
1308
 
1352
- def generate_job_id(self, job_id, dag_id, task_id, logical_date, configuration, force_rerun=False) -> str:
1309
+ def generate_job_id(
1310
+ self,
1311
+ job_id: str | None,
1312
+ dag_id: str,
1313
+ task_id: str,
1314
+ logical_date: datetime | None,
1315
+ configuration: dict,
1316
+ run_after: pendulum.DateTime | datetime | None = None,
1317
+ force_rerun: bool = False,
1318
+ ) -> str:
1353
1319
  if force_rerun:
1354
1320
  hash_base = str(uuid.uuid4())
1355
1321
  else:
@@ -1360,10 +1326,31 @@ class BigQueryHook(GoogleBaseHook, DbApiHook):
1360
1326
  if job_id:
1361
1327
  return f"{job_id}_{uniqueness_suffix}"
1362
1328
 
1363
- exec_date = logical_date.isoformat()
1364
- job_id = f"airflow_{dag_id}_{task_id}_{exec_date}_{uniqueness_suffix}"
1329
+ if logical_date is not None:
1330
+ if AIRFLOW_V_3_0_PLUS:
1331
+ warnings.warn(
1332
+ "The 'logical_date' parameter is deprecated. Please use 'run_after' instead.",
1333
+ AirflowProviderDeprecationWarning,
1334
+ stacklevel=1,
1335
+ )
1336
+ job_id_timestamp = logical_date
1337
+ elif run_after is not None:
1338
+ job_id_timestamp = run_after
1339
+ else:
1340
+ job_id_timestamp = pendulum.now("UTC")
1341
+
1342
+ job_id = f"airflow_{dag_id}_{task_id}_{job_id_timestamp.isoformat()}_{uniqueness_suffix}"
1365
1343
  return re.sub(r"[:\-+.]", "_", job_id)
1366
1344
 
1345
+ def get_run_after_or_logical_date(self, context: Context) -> pendulum.DateTime | datetime | None:
1346
+ dag_run = context.get("dag_run")
1347
+ if not dag_run:
1348
+ return pendulum.now("UTC")
1349
+
1350
+ if AIRFLOW_V_3_0_PLUS:
1351
+ return dag_run.start_date
1352
+ return dag_run.start_date if dag_run.run_type == DagRunType.SCHEDULED else context.get("logical_date")
1353
+
1367
1354
  def split_tablename(
1368
1355
  self, table_input: str, default_project_id: str, var_name: str | None = None
1369
1356
  ) -> tuple[str, str, str]:
@@ -1777,6 +1764,7 @@ class BigQueryCursor(BigQueryBaseCursor):
1777
1764
  schema_update_options: Iterable | None = None,
1778
1765
  priority: str | None = None,
1779
1766
  time_partitioning: dict | None = None,
1767
+ range_partitioning: dict | None = None,
1780
1768
  api_resource_configs: dict | None = None,
1781
1769
  cluster_fields: list[str] | None = None,
1782
1770
  encryption_configuration: dict | None = None,
@@ -1789,6 +1777,10 @@ class BigQueryCursor(BigQueryBaseCursor):
1789
1777
 
1790
1778
  if time_partitioning is None:
1791
1779
  time_partitioning = {}
1780
+ if range_partitioning is None:
1781
+ range_partitioning = {}
1782
+ if time_partitioning and range_partitioning:
1783
+ raise ValueError("Only one of time_partitioning or range_partitioning can be set.")
1792
1784
 
1793
1785
  if not api_resource_configs:
1794
1786
  api_resource_configs = self.hook.api_resource_configs
@@ -1818,14 +1810,6 @@ class BigQueryCursor(BigQueryBaseCursor):
1818
1810
  f" Please only use one or more of the following options: {allowed_schema_update_options}"
1819
1811
  )
1820
1812
 
1821
- if schema_update_options:
1822
- if write_disposition not in ["WRITE_APPEND", "WRITE_TRUNCATE"]:
1823
- raise ValueError(
1824
- "schema_update_options is only "
1825
- "allowed if write_disposition is "
1826
- "'WRITE_APPEND' or 'WRITE_TRUNCATE'."
1827
- )
1828
-
1829
1813
  if destination_dataset_table:
1830
1814
  destination_project, destination_dataset, destination_table = self.hook.split_tablename(
1831
1815
  table_input=destination_dataset_table, default_project_id=self.project_id
@@ -1849,16 +1833,21 @@ class BigQueryCursor(BigQueryBaseCursor):
1849
1833
  (maximum_billing_tier, "maximumBillingTier", None, int),
1850
1834
  (maximum_bytes_billed, "maximumBytesBilled", None, float),
1851
1835
  (time_partitioning, "timePartitioning", {}, dict),
1836
+ (range_partitioning, "rangePartitioning", {}, dict),
1852
1837
  (schema_update_options, "schemaUpdateOptions", None, list),
1853
1838
  (destination_dataset_table, "destinationTable", None, dict),
1854
1839
  (cluster_fields, "clustering", None, dict),
1855
1840
  ]
1856
1841
 
1857
- for param, param_name, param_default, param_type in query_param_list:
1858
- if param_name not in configuration["query"] and param in [None, {}, ()]:
1842
+ for param_raw, param_name, param_default, param_type in query_param_list:
1843
+ param: Any
1844
+ if param_name not in configuration["query"] and param_raw in [None, {}, ()]:
1859
1845
  if param_name == "timePartitioning":
1860
- param_default = _cleanse_time_partitioning(destination_dataset_table, time_partitioning)
1861
- param = param_default
1846
+ param = _cleanse_time_partitioning(destination_dataset_table, time_partitioning)
1847
+ else:
1848
+ param = param_default
1849
+ else:
1850
+ param = param_raw
1862
1851
 
1863
1852
  if param in [None, {}, ()]:
1864
1853
  continue
@@ -1885,15 +1874,14 @@ class BigQueryCursor(BigQueryBaseCursor):
1885
1874
  "must be a dict with {'projectId':'', "
1886
1875
  "'datasetId':'', 'tableId':''}"
1887
1876
  )
1888
- else:
1889
- configuration["query"].update(
1890
- {
1891
- "allowLargeResults": allow_large_results,
1892
- "flattenResults": flatten_results,
1893
- "writeDisposition": write_disposition,
1894
- "createDisposition": create_disposition,
1895
- }
1896
- )
1877
+ configuration["query"].update(
1878
+ {
1879
+ "allowLargeResults": allow_large_results,
1880
+ "flattenResults": flatten_results,
1881
+ "writeDisposition": write_disposition,
1882
+ "createDisposition": create_disposition,
1883
+ }
1884
+ )
1897
1885
 
1898
1886
  if (
1899
1887
  "useLegacySql" in configuration["query"]
@@ -1937,74 +1925,6 @@ def _escape(s: str) -> str:
1937
1925
  return e
1938
1926
 
1939
1927
 
1940
- @deprecated(
1941
- planned_removal_date="April 01, 2025",
1942
- use_instead="airflow.providers.google.cloud.hooks.bigquery.BigQueryHook.split_tablename",
1943
- category=AirflowProviderDeprecationWarning,
1944
- )
1945
- def split_tablename(
1946
- table_input: str, default_project_id: str, var_name: str | None = None
1947
- ) -> tuple[str, str, str]:
1948
- if "." not in table_input:
1949
- raise ValueError(f"Expected table name in the format of <dataset>.<table>. Got: {table_input}")
1950
-
1951
- if not default_project_id:
1952
- raise ValueError("INTERNAL: No default project is specified")
1953
-
1954
- def var_print(var_name):
1955
- if var_name is None:
1956
- return ""
1957
- return f"Format exception for {var_name}: "
1958
-
1959
- if table_input.count(".") + table_input.count(":") > 3:
1960
- raise ValueError(f"{var_print(var_name)}Use either : or . to specify project got {table_input}")
1961
- cmpt = table_input.rsplit(":", 1)
1962
- project_id = None
1963
- rest = table_input
1964
- if len(cmpt) == 1:
1965
- project_id = None
1966
- rest = cmpt[0]
1967
- elif len(cmpt) == 2 and cmpt[0].count(":") <= 1:
1968
- if cmpt[-1].count(".") != 2:
1969
- project_id = cmpt[0]
1970
- rest = cmpt[1]
1971
- else:
1972
- raise ValueError(
1973
- f"{var_print(var_name)}Expect format of (<project:)<dataset>.<table>, got {table_input}"
1974
- )
1975
-
1976
- cmpt = rest.split(".")
1977
- if len(cmpt) == 3:
1978
- if project_id:
1979
- raise ValueError(f"{var_print(var_name)}Use either : or . to specify project")
1980
- project_id = cmpt[0]
1981
- dataset_id = cmpt[1]
1982
- table_id = cmpt[2]
1983
-
1984
- elif len(cmpt) == 2:
1985
- dataset_id = cmpt[0]
1986
- table_id = cmpt[1]
1987
- else:
1988
- raise ValueError(
1989
- f"{var_print(var_name)}Expect format of (<project.|<project:)<dataset>.<table>, got {table_input}"
1990
- )
1991
-
1992
- # Exclude partition from the table name
1993
- table_id = table_id.split("$")[0]
1994
-
1995
- if project_id is None:
1996
- if var_name is not None:
1997
- log.info(
1998
- 'Project is not included in %s: %s; using project "%s"',
1999
- var_name,
2000
- table_input,
2001
- default_project_id,
2002
- )
2003
- project_id = default_project_id
2004
-
2005
- return project_id, dataset_id, table_id
2006
-
2007
-
2008
1928
  def _cleanse_time_partitioning(
2009
1929
  destination_dataset_table: str | None, time_partitioning_in: dict | None
2010
1930
  ) -> dict: # if it is a partitioned table ($ is in the table name) add partition load option
@@ -2120,46 +2040,11 @@ class BigQueryAsyncHook(GoogleBaseAsyncHook):
2120
2040
  async def _get_job(
2121
2041
  self, job_id: str | None, project_id: str = PROVIDE_PROJECT_ID, location: str | None = None
2122
2042
  ) -> BigQueryJob | UnknownJob:
2123
- """
2124
- Get BigQuery job by its ID, project ID and location.
2125
-
2126
- WARNING.
2127
- This is a temporary workaround for issues below, and it's not intended to be used elsewhere!
2128
- https://github.com/apache/airflow/issues/35833
2129
- https://github.com/talkiq/gcloud-aio/issues/584
2130
-
2131
- This method was developed, because neither the `google-cloud-bigquery` nor the `gcloud-aio-bigquery`
2132
- provides asynchronous access to a BigQuery jobs with location parameter. That's why this method wraps
2133
- synchronous client call with the event loop's run_in_executor() method.
2134
-
2135
- This workaround must be deleted along with the method _get_job_sync() and replaced by more robust and
2136
- cleaner solution in one of two cases:
2137
- 1. The `google-cloud-bigquery` library provides async client with get_job method, that supports
2138
- optional parameter `location`
2139
- 2. The `gcloud-aio-bigquery` library supports the `location` parameter in get_job() method.
2140
- """
2141
- loop = asyncio.get_event_loop()
2142
- job = await loop.run_in_executor(None, self._get_job_sync, job_id, project_id, location)
2043
+ """Get BigQuery job by its ID, project ID and location."""
2044
+ sync_hook = await self.get_sync_hook()
2045
+ job = sync_hook.get_job(job_id=job_id, project_id=project_id, location=location)
2143
2046
  return job
2144
2047
 
2145
- def _get_job_sync(self, job_id, project_id, location):
2146
- """
2147
- Get BigQuery job by its ID, project ID and location synchronously.
2148
-
2149
- WARNING
2150
- This is a temporary workaround for issues below, and it's not intended to be used elsewhere!
2151
- https://github.com/apache/airflow/issues/35833
2152
- https://github.com/talkiq/gcloud-aio/issues/584
2153
-
2154
- This workaround must be deleted along with the method _get_job() and replaced by more robust and
2155
- cleaner solution in one of two cases:
2156
- 1. The `google-cloud-bigquery` library provides async client with get_job method, that supports
2157
- optional parameter `location`
2158
- 2. The `gcloud-aio-bigquery` library supports the `location` parameter in get_job() method.
2159
- """
2160
- hook = BigQueryHook(**self._hook_kwargs)
2161
- return hook.get_job(job_id=job_id, project_id=project_id, location=location)
2162
-
2163
2048
  async def get_job_status(
2164
2049
  self, job_id: str | None, project_id: str = PROVIDE_PROJECT_ID, location: str | None = None
2165
2050
  ) -> dict[str, str]:
@@ -2262,7 +2147,7 @@ class BigQueryAsyncHook(GoogleBaseAsyncHook):
2262
2147
  self,
2263
2148
  sql: str,
2264
2149
  pass_value: Any,
2265
- records: list[Any],
2150
+ records: list[Any] | None = None,
2266
2151
  tolerance: float | None = None,
2267
2152
  ) -> None:
2268
2153
  """