Skip to content

Commit d361df3

Browse files
authored
Provider Migration: Update mysql for Airflow 3.0 compatibility (#52500)
Follow-up of #52292. Part of #52378
1 parent 51ddece commit d361df3

File tree

6 files changed

+62
-17
lines changed

6 files changed

+62
-17
lines changed

providers/mysql/src/airflow/providers/mysql/transfers/presto_to_mysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
from collections.abc import Sequence
2121
from typing import TYPE_CHECKING
2222

23-
from airflow.models import BaseOperator
2423
from airflow.providers.mysql.hooks.mysql import MySqlHook
24+
from airflow.providers.mysql.version_compat import BaseOperator
2525
from airflow.providers.presto.hooks.presto import PrestoHook
2626

2727
if TYPE_CHECKING:

providers/mysql/src/airflow/providers/mysql/transfers/s3_to_mysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from collections.abc import Sequence
2121
from typing import TYPE_CHECKING
2222

23-
from airflow.models import BaseOperator
2423
from airflow.providers.amazon.aws.hooks.s3 import S3Hook
2524
from airflow.providers.mysql.hooks.mysql import MySqlHook
25+
from airflow.providers.mysql.version_compat import BaseOperator
2626

2727
if TYPE_CHECKING:
2828
try:

providers/mysql/src/airflow/providers/mysql/transfers/trino_to_mysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
from collections.abc import Sequence
2121
from typing import TYPE_CHECKING
2222

23-
from airflow.models import BaseOperator
2423
from airflow.providers.mysql.hooks.mysql import MySqlHook
24+
from airflow.providers.mysql.version_compat import BaseOperator
2525
from airflow.providers.trino.hooks.trino import TrinoHook
2626

2727
if TYPE_CHECKING:

providers/mysql/src/airflow/providers/mysql/transfers/vertica_to_mysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"installed in case you see compilation error during installation."
3434
)
3535

36-
from airflow.models import BaseOperator
3736
from airflow.providers.mysql.hooks.mysql import MySqlHook
37+
from airflow.providers.mysql.version_compat import BaseOperator
3838
from airflow.providers.vertica.hooks.vertica import VerticaHook
3939

4040
if TYPE_CHECKING:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from __future__ import annotations
19+
20+
21+
def get_base_airflow_version_tuple() -> tuple[int, int, int]:
22+
from packaging.version import Version
23+
24+
from airflow import __version__
25+
26+
airflow_version = Version(__version__)
27+
return airflow_version.major, airflow_version.minor, airflow_version.micro
28+
29+
30+
AIRFLOW_V_3_0_PLUS = get_base_airflow_version_tuple() >= (3, 0, 0)
31+
32+
if AIRFLOW_V_3_0_PLUS:
33+
from airflow.sdk import BaseOperator
34+
else:
35+
from airflow.models import BaseOperator
36+
37+
__all__ = [
38+
"AIRFLOW_V_3_0_PLUS",
39+
"BaseOperator",
40+
]

providers/mysql/tests/unit/mysql/transfers/test_trino_to_mysql.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,21 @@ def test_execute_with_mysql_preoperator(self, mock_trino_hook, mock_mysql_hook):
6565
@pytest.mark.skipif(
6666
"AIRFLOW_RUNALL_TESTS" not in os.environ, reason="Skipped because AIRFLOW_RUNALL_TESTS is not set"
6767
)
68-
def test_trino_to_mysql(self):
69-
op = TrinoToMySqlOperator(
70-
task_id="trino_to_mysql_check",
71-
sql="""
72-
SELECT name, count(*) as ccount
73-
FROM airflow.static_babynames
74-
GROUP BY name
75-
""",
76-
mysql_table="test_static_babynames",
77-
mysql_preoperator="TRUNCATE TABLE test_static_babynames;",
78-
dag=self.dag,
79-
)
80-
op.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, ignore_ti_state=True)
68+
def test_trino_to_mysql(self, dag_maker):
69+
with dag_maker(
70+
dag_id="test_trino_to_mysql_transfer",
71+
schedule=None,
72+
start_date=DEFAULT_DATE,
73+
):
74+
TrinoToMySqlOperator(
75+
task_id="trino_to_mysql_check",
76+
sql="""
77+
SELECT name, count(*) as ccount
78+
FROM airflow.static_babynames
79+
GROUP BY name
80+
""",
81+
mysql_table="test_static_babynames",
82+
mysql_preoperator="TRUNCATE TABLE test_static_babynames;",
83+
)
84+
dr = dag_maker.create_dagrun()
85+
dag_maker.run_ti("trino_to_mysql_check", dr)

0 commit comments

Comments
 (0)