You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "kacpermuda (via GitHub)" <gi...@apache.org> on 2026/05/05 15:55:45 UTC

[PR] feat: Add uri sanitizers and asset factories for new schemes [airflow]

kacpermuda opened a new pull request, #66426:
URL: https://github.com/apache/airflow/pull/66426

    <!-- SPDX-License-Identifier: Apache-2.0
         https://www.apache.org/licenses/LICENSE-2.0 -->
   
   <!--
   Thank you for contributing!
   
   Please provide above a brief description of the changes made in this pull request.
   Write a good git commit message following this guide: http://chris.beams.io/posts/git-commit/
   
   Please make sure that your code changes are covered with tests.
   And in case of new features or big changes remember to adjust the documentation.
   
   Feel free to ping (in general) for the review if you do not see reaction for a few days
   (72 Hours is the minimum reaction time you can expect from volunteers) - we sometimes miss notifications.
   
   In case of an existing issue, reference it using one of the following:
   
   * closes: #ISSUE
   * related: #ISSUE
   -->
   
   Adding uri sanitizers, asset factories and openlineage asset converters for more schemes. This will improve the quality of Airflow Assets and the conversion rate of airflow assets to OL datasets.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, please
   change below checkbox to `[X]` followed by the name of the tool, uncomment the "Generated-by".
   -->
   
   - [X] Yes (please specify the tool below)
   
   
   Generated-by: Claude following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   
   ---
   
   * Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: `{pr_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments). You can add this file in a follow-up commit after the PR is created so you know the PR number.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: Add uri sanitizers and asset factories for new schemes [airflow]

Posted by "mobuchowski (via GitHub)" <gi...@apache.org>.
mobuchowski commented on code in PR #66426:
URL: https://github.com/apache/airflow/pull/66426#discussion_r3217751184


##########
providers/apache/hdfs/tests/unit/apache/hdfs/assets/test_hdfs.py:
##########
@@ -0,0 +1,92 @@
+# 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
+
+import urllib.parse
+
+import pytest
+
+from airflow.providers.apache.hdfs.assets.hdfs import (
+    convert_asset_to_openlineage,
+    create_asset,
+    sanitize_uri,
+)
+from airflow.providers.common.compat.assets import Asset
+
+
+@pytest.mark.parametrize(
+    ("original", "normalized"),
+    [
+        pytest.param(
+            "hdfs://namenode:8020/data/file.csv",
+            "hdfs://namenode:8020/data/file.csv",
+            id="normalized",
+        ),
+        pytest.param(
+            "hdfs://namenode/data/file.csv",
+            "hdfs://namenode/data/file.csv",
+            id="no-explicit-port",
+        ),
+    ],
+)
+def test_sanitize_uri_pass(original: str, normalized: str) -> None:
+    uri_i = urllib.parse.urlsplit(original)
+    uri_o = sanitize_uri(uri_i)
+    assert urllib.parse.urlunsplit(uri_o) == normalized
+
+
+@pytest.mark.parametrize(
+    "value",
+    [
+        pytest.param("hdfs://", id="blank"),
+        pytest.param("hdfs:///path/to/file", id="no-host"),
+    ],
+)
+def test_sanitize_uri_fail(value: str) -> None:
+    uri_i = urllib.parse.urlsplit(value)
+    with pytest.raises(ValueError, match="URI format hdfs:// must contain"):
+        sanitize_uri(uri_i)
+
+
+@pytest.mark.parametrize(
+    ("path", "expected_uri"),
+    [
+        pytest.param("/data/file.csv", "hdfs://namenode:8020//data/file.csv", id="root"),
+        pytest.param("data/file.csv", "hdfs://namenode:8020/data/file.csv", id="no-leading-slash"),

Review Comment:
   This looks wrong to me, why do we have double slash in the middle there?
   I don't get why would we want non-absolute paths for URLs.



##########
providers/mysql/provider.yaml:
##########
@@ -124,11 +124,15 @@ connection-types:
     connection-type: mysql
 
 asset-uris:
-  - schemes: [mysql, mariadb]
+  - schemes: [mysql]
     handler: airflow.providers.mysql.assets.mysql.sanitize_uri
+    factory: airflow.providers.mysql.assets.mysql.create_asset
+    to_openlineage_converter: airflow.providers.mysql.assets.mysql.convert_asset_to_openlineage
 
 # dataset has been renamed to asset in Airflow 3.0
 # This is kept for backward compatibility.
 dataset-uris:
-  - schemes: [mysql, mariadb]

Review Comment:
   why are we removing mariadb here? 



##########
providers/microsoft/mssql/pyproject.toml:
##########
@@ -72,12 +72,16 @@ dependencies = [
 "openlineage" = [
     "apache-airflow-providers-openlineage"
 ]
+"common.compat" = [
+    "apache-airflow-providers-common-compat"
+]

Review Comment:
   shouldn't common-compat be a required dependency? you're top level importing
   
   ```
   from airflow.providers.common.compat.assets import Asset
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: Add uri sanitizers and asset factories for new schemes [airflow]

Posted by "mobuchowski (via GitHub)" <gi...@apache.org>.
mobuchowski commented on code in PR #66426:
URL: https://github.com/apache/airflow/pull/66426#discussion_r3218231533


##########
providers/apache/hdfs/tests/unit/apache/hdfs/assets/test_hdfs.py:
##########
@@ -0,0 +1,92 @@
+# 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
+
+import urllib.parse
+
+import pytest
+
+from airflow.providers.apache.hdfs.assets.hdfs import (
+    convert_asset_to_openlineage,
+    create_asset,
+    sanitize_uri,
+)
+from airflow.providers.common.compat.assets import Asset
+
+
+@pytest.mark.parametrize(
+    ("original", "normalized"),
+    [
+        pytest.param(
+            "hdfs://namenode:8020/data/file.csv",
+            "hdfs://namenode:8020/data/file.csv",
+            id="normalized",
+        ),
+        pytest.param(
+            "hdfs://namenode/data/file.csv",
+            "hdfs://namenode/data/file.csv",
+            id="no-explicit-port",
+        ),
+    ],
+)
+def test_sanitize_uri_pass(original: str, normalized: str) -> None:
+    uri_i = urllib.parse.urlsplit(original)
+    uri_o = sanitize_uri(uri_i)
+    assert urllib.parse.urlunsplit(uri_o) == normalized
+
+
+@pytest.mark.parametrize(
+    "value",
+    [
+        pytest.param("hdfs://", id="blank"),
+        pytest.param("hdfs:///path/to/file", id="no-host"),
+    ],
+)
+def test_sanitize_uri_fail(value: str) -> None:
+    uri_i = urllib.parse.urlsplit(value)
+    with pytest.raises(ValueError, match="URI format hdfs:// must contain"):
+        sanitize_uri(uri_i)
+
+
+@pytest.mark.parametrize(
+    ("path", "expected_uri"),
+    [
+        pytest.param("/data/file.csv", "hdfs://namenode:8020//data/file.csv", id="root"),
+        pytest.param("data/file.csv", "hdfs://namenode:8020/data/file.csv", id="no-leading-slash"),

Review Comment:
   Relative paths are super hard to deal with in this context :( 
   
   Not sure if there's better way to deal with that unfortunately.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: Add uri sanitizers and asset factories for new schemes [airflow]

Posted by "kacpermuda (via GitHub)" <gi...@apache.org>.
kacpermuda commented on code in PR #66426:
URL: https://github.com/apache/airflow/pull/66426#discussion_r3218196369


##########
providers/apache/hdfs/tests/unit/apache/hdfs/assets/test_hdfs.py:
##########
@@ -0,0 +1,92 @@
+# 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
+
+import urllib.parse
+
+import pytest
+
+from airflow.providers.apache.hdfs.assets.hdfs import (
+    convert_asset_to_openlineage,
+    create_asset,
+    sanitize_uri,
+)
+from airflow.providers.common.compat.assets import Asset
+
+
+@pytest.mark.parametrize(
+    ("original", "normalized"),
+    [
+        pytest.param(
+            "hdfs://namenode:8020/data/file.csv",
+            "hdfs://namenode:8020/data/file.csv",
+            id="normalized",
+        ),
+        pytest.param(
+            "hdfs://namenode/data/file.csv",
+            "hdfs://namenode/data/file.csv",
+            id="no-explicit-port",
+        ),
+    ],
+)
+def test_sanitize_uri_pass(original: str, normalized: str) -> None:
+    uri_i = urllib.parse.urlsplit(original)
+    uri_o = sanitize_uri(uri_i)
+    assert urllib.parse.urlunsplit(uri_o) == normalized
+
+
+@pytest.mark.parametrize(
+    "value",
+    [
+        pytest.param("hdfs://", id="blank"),
+        pytest.param("hdfs:///path/to/file", id="no-host"),
+    ],
+)
+def test_sanitize_uri_fail(value: str) -> None:
+    uri_i = urllib.parse.urlsplit(value)
+    with pytest.raises(ValueError, match="URI format hdfs:// must contain"):
+        sanitize_uri(uri_i)
+
+
+@pytest.mark.parametrize(
+    ("path", "expected_uri"),
+    [
+        pytest.param("/data/file.csv", "hdfs://namenode:8020//data/file.csv", id="root"),
+        pytest.param("data/file.csv", "hdfs://namenode:8020/data/file.csv", id="no-leading-slash"),

Review Comment:
   I applied this logic to hdfs, ftp and sftp. I wanted to preserve distinction between absolute path and relative path, hence double slash if path passed is absolute, from root. My assumption was that a path from root is different than relative - relative should probably use user home directory as reference, so they are two completely different paths in this scenario.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: Add uri sanitizers and asset factories for new schemes [airflow]

Posted by "mobuchowski (via GitHub)" <gi...@apache.org>.
mobuchowski merged PR #66426:
URL: https://github.com/apache/airflow/pull/66426


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: Add uri sanitizers and asset factories for new schemes [airflow]

Posted by "kacpermuda (via GitHub)" <gi...@apache.org>.
kacpermuda commented on code in PR #66426:
URL: https://github.com/apache/airflow/pull/66426#discussion_r3218144201


##########
providers/microsoft/mssql/pyproject.toml:
##########
@@ -72,12 +72,16 @@ dependencies = [
 "openlineage" = [
     "apache-airflow-providers-openlineage"
 ]
+"common.compat" = [
+    "apache-airflow-providers-common-compat"
+]

Review Comment:
   Yes, missed it. Moved to dependencies.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: Add uri sanitizers and asset factories for new schemes [airflow]

Posted by "kacpermuda (via GitHub)" <gi...@apache.org>.
kacpermuda commented on PR #66426:
URL: https://github.com/apache/airflow/pull/66426#issuecomment-4406865116

   Compat pinecone failures are unrelated, fix in #66594 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: Add uri sanitizers and asset factories for new schemes [airflow]

Posted by "kacpermuda (via GitHub)" <gi...@apache.org>.
kacpermuda commented on code in PR #66426:
URL: https://github.com/apache/airflow/pull/66426#discussion_r3218126963


##########
providers/mysql/provider.yaml:
##########
@@ -124,11 +124,15 @@ connection-types:
     connection-type: mysql
 
 asset-uris:
-  - schemes: [mysql, mariadb]
+  - schemes: [mysql]
     handler: airflow.providers.mysql.assets.mysql.sanitize_uri
+    factory: airflow.providers.mysql.assets.mysql.create_asset
+    to_openlineage_converter: airflow.providers.mysql.assets.mysql.convert_asset_to_openlineage
 
 # dataset has been renamed to asset in Airflow 3.0
 # This is kept for backward compatibility.
 dataset-uris:
-  - schemes: [mysql, mariadb]

Review Comment:
   My mistake, reverted !



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org