-
Notifications
You must be signed in to change notification settings - Fork 16.7k
AIP-99: Add AnalyticsOperator #62232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
9938fb1
Add analytics operator
gopidesupavan 24012b9
Add analytics operator
gopidesupavan 6b37769
Fix tests
gopidesupavan d1db351
Add docs
gopidesupavan 8472844
update params
gopidesupavan 5303379
update datafusion version
gopidesupavan 8c4a18d
Fix selective checks
gopidesupavan b5095a8
Fix tests
gopidesupavan 36d088e
Fix mypy checks
gopidesupavan 88abbfa
move examples to example_dag folder
gopidesupavan 9c84af1
Update docs
gopidesupavan 53fbdea
Update docs
gopidesupavan 1dde6d7
Update datasource config to support options parameter
gopidesupavan ce1b52b
Update docstring
gopidesupavan bc9dd21
Resolve comments
gopidesupavan 0644756
Resolve comments
gopidesupavan 259a34f
Resolve comments
gopidesupavan c7bc7c6
fixup tests
gopidesupavan 12ab800
Move analytics operator to common-sql
gopidesupavan 56d171d
Fixup tests
gopidesupavan 5ed8d92
Updated changes imports
gopidesupavan 316057a
Updated changes test paths
gopidesupavan b141a12
Resolve comments
gopidesupavan 428b8d0
Update endpoint in extras
gopidesupavan 2f12141
Merge branch 'main' into analytics-operator
gopidesupavan de2931c
Update dependency
gopidesupavan 0351be1
Update dependency
gopidesupavan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
providers/common/sql/src/airflow/providers/common/sql/config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass, field | ||
| from enum import Enum | ||
| from typing import Any | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class ConnectionConfig: | ||
| """Configuration for datafusion object store connections.""" | ||
|
|
||
| conn_id: str | ||
| credentials: dict[str, Any] = field(default_factory=dict) | ||
| extra_config: dict[str, Any] = field(default_factory=dict) | ||
|
|
||
|
|
||
| class FormatType(str, Enum): | ||
| """Supported data formats.""" | ||
|
|
||
| PARQUET = "parquet" | ||
| CSV = "csv" | ||
| AVRO = "avro" | ||
|
|
||
|
|
||
| class StorageType(str, Enum): | ||
| """Storage types for Data Fusion.""" | ||
|
|
||
| S3 = "s3" | ||
| LOCAL = "local" | ||
|
|
||
|
|
||
| @dataclass | ||
gopidesupavan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| class DataSourceConfig: | ||
| """ | ||
| Configuration for an input data source. | ||
|
|
||
| :param conn_id: The connection ID to use for accessing the data source. | ||
| :param uri: The URI of the data source (e.g., file path, S3 bucket, etc.). | ||
| :param format: The format of the data (e.g., 'parquet', 'csv'). | ||
| :param table_name: The name of the table if applicable. | ||
| :param schema: A dictionary mapping column names to their types. | ||
| :param db_name: The database name if applicable. | ||
| :param storage_type: The type of storage (automatically inferred from URI). | ||
| :param options: Additional options for the data source. eg: you can set partition columns to any datasource | ||
| that will be set in while registering the data | ||
| """ | ||
|
|
||
| conn_id: str | ||
| uri: str | ||
| format: str | None = None | ||
| table_name: str | None = None | ||
| storage_type: StorageType | None = None | ||
| options: dict[str, Any] = field(default_factory=dict) | ||
|
|
||
| def __post_init__(self): | ||
|
|
||
| if self.storage_type is None: | ||
| self.storage_type = self._extract_storage_type | ||
|
|
||
| if self.storage_type is not None and self.table_name is None: | ||
| raise ValueError("Table name must be provided for storage type") | ||
|
|
||
| @property | ||
| def _extract_storage_type(self) -> StorageType | None: | ||
| """Extract storage type.""" | ||
| if self.uri.startswith("s3://"): | ||
| return StorageType.S3 | ||
| if self.uri.startswith("file://"): | ||
| return StorageType.LOCAL | ||
| raise ValueError(f"Unsupported storage type for URI: {self.uri}") | ||
16 changes: 16 additions & 0 deletions
16
providers/common/sql/src/airflow/providers/common/sql/datafusion/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. |
67 changes: 67 additions & 0 deletions
67
providers/common/sql/src/airflow/providers/common/sql/datafusion/base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| from __future__ import annotations | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from airflow.utils.log.logging_mixin import LoggingMixin | ||
|
|
||
| if TYPE_CHECKING: | ||
| from datafusion import SessionContext | ||
|
|
||
| from airflow.providers.common.sql.config import ConnectionConfig, FormatType, StorageType | ||
|
|
||
|
|
||
| class ObjectStorageProvider(LoggingMixin, ABC): | ||
| """Abstract base class for object storage providers.""" | ||
|
|
||
| @property | ||
| def get_storage_type(self) -> StorageType: | ||
| """Return storage type handled by this provider (e.g., 's3', 'gcs', 'local').""" | ||
| raise NotImplementedError | ||
|
|
||
| @abstractmethod | ||
| def create_object_store(self, path: str, connection_config: ConnectionConfig | None = None) -> Any: | ||
| """Create and return a DataFusion object store instance.""" | ||
| raise NotImplementedError | ||
|
|
||
| @abstractmethod | ||
| def get_scheme(self) -> str: | ||
| """Return URL scheme for this storage type (e.g., 's3://', 'gs://').""" | ||
| raise NotImplementedError | ||
|
|
||
| def get_bucket(self, path: str) -> str | None: | ||
| """Extract the bucket name from the given path.""" | ||
| if path and path.startswith(self.get_scheme()): | ||
| path_parts = path[len(self.get_scheme()) :].split("/", 1) | ||
| return path_parts[0] | ||
| return None | ||
|
|
||
|
|
||
| class FormatHandler(LoggingMixin, ABC): | ||
| """Abstract base class for format handlers.""" | ||
|
|
||
| @property | ||
| def get_format(self) -> FormatType: | ||
| """Return file format type.""" | ||
| raise NotImplementedError | ||
|
|
||
| @abstractmethod | ||
| def register_data_source_format(self, ctx: SessionContext, table_name: str, path: str) -> None: | ||
| """Register data source format.""" | ||
| raise NotImplementedError |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.