apache-airflow-providers-common-sql 1.18.0rc1__tar.gz → 1.19.0rc1__tar.gz

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.

Potentially problematic release.


This version of apache-airflow-providers-common-sql might be problematic. Click here for more details.

Files changed (18) hide show
  1. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/PKG-INFO +6 -6
  2. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/README.rst +3 -3
  3. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/__init__.py +1 -1
  4. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/get_provider_info.py +2 -1
  5. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/hooks/sql.py +17 -3
  6. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/hooks/sql.pyi +6 -11
  7. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/operators/sql.py +14 -2
  8. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/operators/sql.pyi +3 -15
  9. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/sensors/sql.py +14 -9
  10. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/sensors/sql.pyi +1 -4
  11. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/pyproject.toml +3 -3
  12. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/LICENSE +0 -0
  13. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/README_API.md +0 -0
  14. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/doc/adr/0001-record-architecture-decisions.md +0 -0
  15. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/doc/adr/0002-return-common-data-structure-from-dbapihook-derived-hooks.md +0 -0
  16. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/hooks/__init__.py +0 -0
  17. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/operators/__init__.py +0 -0
  18. {apache_airflow_providers_common_sql-1.18.0rc1 → apache_airflow_providers_common_sql-1.19.0rc1}/airflow/providers/common/sql/sensors/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: apache-airflow-providers-common-sql
3
- Version: 1.18.0rc1
3
+ Version: 1.19.0rc1
4
4
  Summary: Provider package apache-airflow-providers-common-sql for Apache Airflow
5
5
  Keywords: airflow-provider,common.sql,airflow,integration
6
6
  Author-email: Apache Software Foundation <dev@airflow.apache.org>
@@ -27,8 +27,8 @@ Requires-Dist: apache-airflow-providers-openlineage ; extra == "openlineage"
27
27
  Requires-Dist: pandas>=2.1.2,<2.2 ; extra == "pandas" and (python_version>="3.9")
28
28
  Requires-Dist: pandas>=1.5.3,<2.2 ; extra == "pandas" and (python_version<"3.9")
29
29
  Project-URL: Bug Tracker, https://github.com/apache/airflow/issues
30
- Project-URL: Changelog, https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.18.0/changelog.html
31
- Project-URL: Documentation, https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.18.0
30
+ Project-URL: Changelog, https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.19.0/changelog.html
31
+ Project-URL: Documentation, https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.19.0
32
32
  Project-URL: Slack Chat, https://s.apache.org/airflow-slack
33
33
  Project-URL: Source Code, https://github.com/apache/airflow
34
34
  Project-URL: Twitter, https://twitter.com/ApacheAirflow
@@ -80,7 +80,7 @@ Provides-Extra: pandas
80
80
 
81
81
  Package ``apache-airflow-providers-common-sql``
82
82
 
83
- Release: ``1.18.0.rc1``
83
+ Release: ``1.19.0.rc1``
84
84
 
85
85
 
86
86
  `Common SQL Provider <https://en.wikipedia.org/wiki/SQL>`__
@@ -93,7 +93,7 @@ This is a provider package for ``common.sql`` provider. All classes for this pro
93
93
  are in ``airflow.providers.common.sql`` python package.
94
94
 
95
95
  You can find package information and changelog for the provider
96
- in the `documentation <https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.18.0/>`_.
96
+ in the `documentation <https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.19.0/>`_.
97
97
 
98
98
  Installation
99
99
  ------------
@@ -135,4 +135,4 @@ Dependent package
135
135
  ============================================================================================================== ===============
136
136
 
137
137
  The changelog for the provider package can be found in the
138
- `changelog <https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.18.0/changelog.html>`_.
138
+ `changelog <https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.19.0/changelog.html>`_.
@@ -42,7 +42,7 @@
42
42
 
43
43
  Package ``apache-airflow-providers-common-sql``
44
44
 
45
- Release: ``1.18.0.rc1``
45
+ Release: ``1.19.0.rc1``
46
46
 
47
47
 
48
48
  `Common SQL Provider <https://en.wikipedia.org/wiki/SQL>`__
@@ -55,7 +55,7 @@ This is a provider package for ``common.sql`` provider. All classes for this pro
55
55
  are in ``airflow.providers.common.sql`` python package.
56
56
 
57
57
  You can find package information and changelog for the provider
58
- in the `documentation <https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.18.0/>`_.
58
+ in the `documentation <https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.19.0/>`_.
59
59
 
60
60
  Installation
61
61
  ------------
@@ -97,4 +97,4 @@ Dependent package
97
97
  ============================================================================================================== ===============
98
98
 
99
99
  The changelog for the provider package can be found in the
100
- `changelog <https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.18.0/changelog.html>`_.
100
+ `changelog <https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.19.0/changelog.html>`_.
@@ -29,7 +29,7 @@ from airflow import __version__ as airflow_version
29
29
 
30
30
  __all__ = ["__version__"]
31
31
 
32
- __version__ = "1.18.0"
32
+ __version__ = "1.19.0"
33
33
 
34
34
  if packaging.version.parse(packaging.version.parse(airflow_version).base_version) < packaging.version.parse(
35
35
  "2.8.0"
@@ -28,8 +28,9 @@ def get_provider_info():
28
28
  "name": "Common SQL",
29
29
  "description": "`Common SQL Provider <https://en.wikipedia.org/wiki/SQL>`__\n",
30
30
  "state": "ready",
31
- "source-date-epoch": 1728485007,
31
+ "source-date-epoch": 1730012422,
32
32
  "versions": [
33
+ "1.19.0",
33
34
  "1.18.0",
34
35
  "1.17.1",
35
36
  "1.17.0",
@@ -190,7 +190,7 @@ class DbApiHook(BaseHook):
190
190
  return getattr(self, self.conn_name_attr)
191
191
 
192
192
  @cached_property
193
- def placeholder(self):
193
+ def placeholder(self) -> str:
194
194
  placeholder = self.connection_extra.get("placeholder")
195
195
  if placeholder:
196
196
  if placeholder in SQL_PLACEHOLDERS:
@@ -235,9 +235,11 @@ class DbApiHook(BaseHook):
235
235
  """
236
236
  return {k.lower(): v for k, v in self.connection_extra.items()}
237
237
 
238
- def get_conn(self):
238
+ def get_conn(self) -> Any:
239
239
  """Return a connection object."""
240
240
  db = self.connection
241
+ if self.connector is None:
242
+ raise RuntimeError(f"{type(self).__name__} didn't have `self.connector` set!")
241
243
  return self.connector.connect(host=db.host, port=db.port, username=db.login, schema=db.schema)
242
244
 
243
245
  def get_uri(self) -> str:
@@ -570,7 +572,7 @@ class DbApiHook(BaseHook):
570
572
  """
571
573
  return getattr(conn, "autocommit", False) and self.supports_autocommit
572
574
 
573
- def get_cursor(self):
575
+ def get_cursor(self) -> Any:
574
576
  """Return a cursor."""
575
577
  return self.get_conn().cursor()
576
578
 
@@ -618,6 +620,7 @@ class DbApiHook(BaseHook):
618
620
  replace=False,
619
621
  *,
620
622
  executemany=False,
623
+ fast_executemany=False,
621
624
  autocommit=False,
622
625
  **kwargs,
623
626
  ):
@@ -636,6 +639,8 @@ class DbApiHook(BaseHook):
636
639
  :param executemany: If True, all rows are inserted at once in
637
640
  chunks defined by the commit_every parameter. This only works if all rows
638
641
  have same number of column names, but leads to better performance.
642
+ :param fast_executemany: If True, the `fast_executemany` parameter will be set on the
643
+ cursor used by `executemany` which leads to better performance, if supported by driver.
639
644
  :param autocommit: What to set the connection's autocommit setting to
640
645
  before executing the query.
641
646
  """
@@ -644,6 +649,15 @@ class DbApiHook(BaseHook):
644
649
  conn.commit()
645
650
  with closing(conn.cursor()) as cur:
646
651
  if self.supports_executemany or executemany:
652
+ if fast_executemany:
653
+ with contextlib.suppress(AttributeError):
654
+ # Try to set the fast_executemany attribute
655
+ cur.fast_executemany = True
656
+ self.log.info(
657
+ "Fast_executemany is enabled for conn_id '%s'!",
658
+ self.get_conn_id(),
659
+ )
660
+
647
661
  for chunked_rows in chunked(rows, commit_every):
648
662
  values = list(
649
663
  map(
@@ -31,19 +31,14 @@
31
31
  Definition of the public interface for airflow.providers.common.sql.hooks.sql
32
32
  isort:skip_file
33
33
  """
34
- from _typeshed import Incomplete
35
- from airflow.exceptions import (
36
- AirflowException as AirflowException,
37
- AirflowOptionalProviderFeatureException as AirflowOptionalProviderFeatureException,
38
- AirflowProviderDeprecationWarning as AirflowProviderDeprecationWarning,
39
- )
34
+ from _typeshed import Incomplete as Incomplete
40
35
  from airflow.hooks.base import BaseHook as BaseHook
41
36
  from airflow.models import Connection as Connection
42
37
  from airflow.providers.openlineage.extractors import OperatorLineage as OperatorLineage
43
38
  from airflow.providers.openlineage.sqlparser import DatabaseInfo as DatabaseInfo
44
39
  from functools import cached_property as cached_property
45
40
  from pandas import DataFrame as DataFrame
46
- from sqlalchemy.engine import Inspector, URL as URL
41
+ from sqlalchemy.engine import Inspector as Inspector, URL as URL
47
42
  from typing import Any, Callable, Generator, Iterable, Mapping, Protocol, Sequence, TypeVar, overload
48
43
 
49
44
  T = TypeVar("T")
@@ -67,7 +62,7 @@ class DbApiHook(BaseHook):
67
62
  def __init__(self, *args, schema: str | None = None, log_sql: bool = True, **kwargs) -> None: ...
68
63
  def get_conn_id(self) -> str: ...
69
64
  @cached_property
70
- def placeholder(self): ...
65
+ def placeholder(self) -> str: ...
71
66
  @property
72
67
  def connection(self) -> Connection: ...
73
68
  @connection.setter
@@ -76,7 +71,7 @@ class DbApiHook(BaseHook):
76
71
  def connection_extra(self) -> dict: ...
77
72
  @cached_property
78
73
  def connection_extra_lower(self) -> dict: ...
79
- def get_conn(self): ...
74
+ def get_conn(self) -> Any: ...
80
75
  def get_uri(self) -> str: ...
81
76
  @property
82
77
  def sqlalchemy_url(self) -> URL: ...
@@ -123,7 +118,7 @@ class DbApiHook(BaseHook):
123
118
  ) -> tuple | list[tuple] | list[list[tuple] | tuple] | None: ...
124
119
  def set_autocommit(self, conn, autocommit) -> None: ...
125
120
  def get_autocommit(self, conn) -> bool: ...
126
- def get_cursor(self): ...
121
+ def get_cursor(self) -> Any: ...
127
122
  def insert_rows(
128
123
  self,
129
124
  table,
@@ -138,7 +133,7 @@ class DbApiHook(BaseHook):
138
133
  ): ...
139
134
  def bulk_dump(self, table, tmp_file) -> None: ...
140
135
  def bulk_load(self, table, tmp_file) -> None: ...
141
- def test_connection(self): ...
136
+ def test_connection(self) -> None: ...
142
137
  def get_openlineage_database_info(self, connection) -> DatabaseInfo | None: ...
143
138
  def get_openlineage_database_dialect(self, connection) -> str: ...
144
139
  def get_openlineage_default_schema(self) -> str | None: ...
@@ -145,13 +145,25 @@ class BaseSQLOperator(BaseOperator):
145
145
  self.hook_params = hook_params or {}
146
146
  self.retry_on_failure = retry_on_failure
147
147
 
148
+ @classmethod
149
+ # TODO: can be removed once Airflow min version for this provider is 3.0.0 or higher
150
+ def get_hook(cls, conn_id: str, hook_params: dict | None = None) -> BaseHook:
151
+ """
152
+ Return default hook for this connection id.
153
+
154
+ :param conn_id: connection id
155
+ :param hook_params: hook parameters
156
+ :return: default hook for this connection
157
+ """
158
+ connection = BaseHook.get_connection(conn_id)
159
+ return connection.get_hook(hook_params=hook_params)
160
+
148
161
  @cached_property
149
162
  def _hook(self):
150
163
  """Get DB Hook based on connection type."""
151
164
  conn_id = getattr(self, self.conn_id_field)
152
165
  self.log.debug("Get connection for %s", conn_id)
153
- conn = BaseHook.get_connection(conn_id)
154
- hook = conn.get_hook(hook_params=self.hook_params)
166
+ hook = self.get_hook(conn_id=conn_id, hook_params=self.hook_params)
155
167
  if not isinstance(hook, DbApiHook):
156
168
  raise AirflowException(
157
169
  f"You are trying to use `common-sql` with {hook.__class__.__name__},"
@@ -31,25 +31,13 @@
31
31
  Definition of the public interface for airflow.providers.common.sql.operators.sql
32
32
  isort:skip_file
33
33
  """
34
- from _typeshed import Incomplete
35
- from airflow.exceptions import (
36
- AirflowException as AirflowException,
37
- AirflowFailException as AirflowFailException,
38
- )
39
- from airflow.hooks.base import BaseHook as BaseHook
34
+ from _typeshed import Incomplete as Incomplete
40
35
  from airflow.models import BaseOperator as BaseOperator, SkipMixin as SkipMixin
41
- from airflow.providers.common.sql.hooks.sql import (
42
- DbApiHook as DbApiHook,
43
- fetch_all_handler as fetch_all_handler,
44
- return_single_query_results as return_single_query_results,
45
- )
36
+ from airflow.providers.common.sql.hooks.sql import DbApiHook as DbApiHook
46
37
  from airflow.providers.openlineage.extractors import OperatorLineage as OperatorLineage
47
38
  from airflow.utils.context import Context as Context
48
- from airflow.utils.helpers import merge_dicts as merge_dicts
49
- from functools import cached_property as cached_property
50
39
  from typing import Any, Callable, Iterable, Mapping, Sequence, SupportsAbs
51
40
 
52
- def _parse_boolean(val: str) -> str | bool: ...
53
41
  def parse_boolean(val: str) -> str | bool: ...
54
42
 
55
43
  class BaseSQLOperator(BaseOperator):
@@ -97,7 +85,7 @@ class SQLExecuteQueryOperator(BaseSQLOperator):
97
85
  show_return_value_in_logs: bool = False,
98
86
  **kwargs,
99
87
  ) -> None: ...
100
- def execute(self, context): ...
88
+ def execute(self, context) -> None: ...
101
89
  def prepare_template(self) -> None: ...
102
90
  def get_openlineage_facets_on_start(self) -> OperatorLineage | None: ...
103
91
  def get_openlineage_facets_on_complete(self, task_instance) -> OperatorLineage | None: ...
@@ -16,6 +16,7 @@
16
16
  # under the License.
17
17
  from __future__ import annotations
18
18
 
19
+ from operator import itemgetter
19
20
  from typing import TYPE_CHECKING, Any, Callable, Mapping, Sequence
20
21
 
21
22
  from airflow.exceptions import AirflowException
@@ -46,10 +47,12 @@ class SqlSensor(BaseSensorOperator):
46
47
  :param sql: The SQL to run. To pass, it needs to return at least one cell
47
48
  that contains a non-zero / empty string value.
48
49
  :param parameters: The parameters to render the SQL query with (optional).
49
- :param success: Success criteria for the sensor is a Callable that takes the first_cell's value
50
- as the only argument, and returns a boolean (optional).
51
- :param failure: Failure criteria for the sensor is a Callable that takes the first_cell's value
52
- as the only argument and returns a boolean (optional).
50
+ :param success: Success criteria for the sensor is a Callable that takes the output
51
+ of selector as the only argument, and returns a boolean (optional).
52
+ :param failure: Failure criteria for the sensor is a Callable that takes the output
53
+ of selector as the only argument and returns a boolean (optional).
54
+ :param selector: Function which takes the resulting row and transforms it before
55
+ it is passed to success or failure (optional). Takes the first cell by default.
53
56
  :param fail_on_empty: Explicitly fail on no rows returned.
54
57
  :param hook_params: Extra config params to be passed to the underlying hook.
55
58
  Should match the desired hook constructor params.
@@ -67,6 +70,7 @@ class SqlSensor(BaseSensorOperator):
67
70
  parameters: Mapping[str, Any] | None = None,
68
71
  success: Callable[[Any], bool] | None = None,
69
72
  failure: Callable[[Any], bool] | None = None,
73
+ selector: Callable[[tuple[Any]], Any] = itemgetter(0),
70
74
  fail_on_empty: bool = False,
71
75
  hook_params: Mapping[str, Any] | None = None,
72
76
  **kwargs,
@@ -76,6 +80,7 @@ class SqlSensor(BaseSensorOperator):
76
80
  self.parameters = parameters
77
81
  self.success = success
78
82
  self.failure = failure
83
+ self.selector = selector
79
84
  self.fail_on_empty = fail_on_empty
80
85
  self.hook_params = hook_params
81
86
  super().__init__(**kwargs)
@@ -102,11 +107,11 @@ class SqlSensor(BaseSensorOperator):
102
107
  else:
103
108
  return False
104
109
 
105
- first_cell = records[0][0]
110
+ condition = self.selector(records[0])
106
111
  if self.failure is not None:
107
112
  if callable(self.failure):
108
- if self.failure(first_cell):
109
- message = f"Failure criteria met. self.failure({first_cell}) returned True"
113
+ if self.failure(condition):
114
+ message = f"Failure criteria met. self.failure({condition}) returned True"
110
115
  raise AirflowException(message)
111
116
  else:
112
117
  message = f"self.failure is present, but not callable -> {self.failure}"
@@ -114,8 +119,8 @@ class SqlSensor(BaseSensorOperator):
114
119
 
115
120
  if self.success is not None:
116
121
  if callable(self.success):
117
- return self.success(first_cell)
122
+ return self.success(condition)
118
123
  else:
119
124
  message = f"self.success is present, but not callable -> {self.success}"
120
125
  raise AirflowException(message)
121
- return bool(first_cell)
126
+ return bool(condition)
@@ -31,10 +31,7 @@
31
31
  Definition of the public interface for airflow.providers.common.sql.sensors.sql
32
32
  isort:skip_file
33
33
  """
34
- from _typeshed import Incomplete
35
- from airflow.exceptions import AirflowException as AirflowException
36
- from airflow.hooks.base import BaseHook as BaseHook
37
- from airflow.providers.common.sql.hooks.sql import DbApiHook as DbApiHook
34
+ from _typeshed import Incomplete as Incomplete
38
35
  from airflow.sensors.base import BaseSensorOperator as BaseSensorOperator
39
36
  from airflow.utils.context import Context as Context
40
37
  from typing import Any, Callable, Mapping, Sequence
@@ -28,7 +28,7 @@ build-backend = "flit_core.buildapi"
28
28
 
29
29
  [project]
30
30
  name = "apache-airflow-providers-common-sql"
31
- version = "1.18.0.rc1"
31
+ version = "1.19.0.rc1"
32
32
  description = "Provider package apache-airflow-providers-common-sql for Apache Airflow"
33
33
  readme = "README.rst"
34
34
  authors = [
@@ -61,8 +61,8 @@ dependencies = [
61
61
  ]
62
62
 
63
63
  [project.urls]
64
- "Documentation" = "https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.18.0"
65
- "Changelog" = "https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.18.0/changelog.html"
64
+ "Documentation" = "https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.19.0"
65
+ "Changelog" = "https://airflow.apache.org/docs/apache-airflow-providers-common-sql/1.19.0/changelog.html"
66
66
  "Bug Tracker" = "https://github.com/apache/airflow/issues"
67
67
  "Source Code" = "https://github.com/apache/airflow"
68
68
  "Slack Chat" = "https://s.apache.org/airflow-slack"