Skip to content

Commit 554ae58

Browse files
authored
Provider Migration: Update Apache Druid for Airflow 3.0 compatibility (#52498)
* Update BaseOperator imports for Airflow 3.0 compatibility merge updates from master * remove version_compat.py update as PR 52496
1 parent d3a33da commit 554ae58

3 files changed

Lines changed: 52 additions & 4 deletions

File tree

providers/apache/druid/src/airflow/providers/apache/druid/operators/druid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
from collections.abc import Sequence
2121
from typing import TYPE_CHECKING, Any
2222

23-
from airflow.models import BaseOperator
2423
from airflow.providers.apache.druid.hooks.druid import DruidHook, IngestionType
24+
from airflow.providers.apache.druid.version_compat import BaseOperator
2525

2626
if TYPE_CHECKING:
27-
from airflow.utils.context import Context
27+
from airflow.providers.apache.druid.version_compat import Context
2828

2929

3030
class DruidOperator(BaseOperator):

providers/apache/druid/src/airflow/providers/apache/druid/transfers/hive_to_druid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
from collections.abc import Sequence
2323
from typing import TYPE_CHECKING, Any
2424

25-
from airflow.models import BaseOperator
2625
from airflow.providers.apache.druid.hooks.druid import DruidHook
26+
from airflow.providers.apache.druid.version_compat import BaseOperator
2727
from airflow.providers.apache.hive.hooks.hive import HiveCliHook, HiveMetastoreHook
2828

2929
if TYPE_CHECKING:
30-
from airflow.utils.context import Context
30+
from airflow.providers.apache.druid.version_compat import Context
3131

3232
LOAD_CHECK_INTERVAL = 5
3333
DEFAULT_TARGET_PARTITION_SIZE = 5000000
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
# NOTE! THIS FILE IS COPIED MANUALLY IN OTHER PROVIDERS DELIBERATELY TO AVOID ADDING UNNECESSARY
19+
# DEPENDENCIES BETWEEN PROVIDERS. IF YOU WANT TO ADD CONDITIONAL CODE IN YOUR PROVIDER THAT DEPENDS
20+
# ON AIRFLOW VERSION, PLEASE COPY THIS FILE TO THE ROOT PACKAGE OF YOUR PROVIDER AND IMPORT
21+
# THOSE CONSTANTS FROM IT RATHER THAN IMPORTING THEM FROM ANOTHER PROVIDER OR TEST CODE
22+
#
23+
from __future__ import annotations
24+
25+
26+
def get_base_airflow_version_tuple() -> tuple[int, int, int]:
27+
from packaging.version import Version
28+
29+
from airflow import __version__
30+
31+
airflow_version = Version(__version__)
32+
return airflow_version.major, airflow_version.minor, airflow_version.micro
33+
34+
35+
AIRFLOW_V_3_0_PLUS = get_base_airflow_version_tuple() >= (3, 0, 0)
36+
37+
if AIRFLOW_V_3_0_PLUS:
38+
from airflow.sdk import BaseOperator
39+
from airflow.sdk.definitions.context import Context
40+
else:
41+
from airflow.models import BaseOperator
42+
from airflow.utils.context import Context
43+
44+
__all__ = [
45+
"AIRFLOW_V_3_0_PLUS",
46+
"BaseOperator",
47+
"Context",
48+
]

0 commit comments

Comments
 (0)