This is an automated email from the ASF dual-hosted git repository.

mobuchowski pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 2a39914cbd Don't use database as fallback when no schema parsed. 
(#32959)
2a39914cbd is described below

commit 2a39914cbd091fb7b19de80197afcaf82c8ec240
Author: Jakub Dardzinski <[email protected]>
AuthorDate: Tue Aug 1 20:24:38 2023 +0200

    Don't use database as fallback when no schema parsed. (#32959)
    
    Signed-off-by: Jakub Dardzinski <[email protected]>
---
 airflow/providers/openlineage/sqlparser.py          | 2 +-
 tests/providers/openlineage/utils/test_sqlparser.py | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/airflow/providers/openlineage/sqlparser.py 
b/airflow/providers/openlineage/sqlparser.py
index 2b18e28d7d..ff788afdf2 100644
--- a/airflow/providers/openlineage/sqlparser.py
+++ b/airflow/providers/openlineage/sqlparser.py
@@ -291,6 +291,6 @@ class SQLParser:
             else:
                 db = None
             schemas = hierarchy.setdefault(normalize_name(db) if db else db, 
{})
-            tables = schemas.setdefault(normalize_name(table.schema) if 
table.schema else db, [])
+            tables = schemas.setdefault(normalize_name(table.schema) if 
table.schema else None, [])
             tables.append(table.name)
         return hierarchy
diff --git a/tests/providers/openlineage/utils/test_sqlparser.py 
b/tests/providers/openlineage/utils/test_sqlparser.py
index 31611c7c11..bbb02ec122 100644
--- a/tests/providers/openlineage/utils/test_sqlparser.py
+++ b/tests/providers/openlineage/utils/test_sqlparser.py
@@ -89,6 +89,14 @@ class TestSQLParser:
             is_cross_db=True,
         ) == {"db": {"schema1": ["Table2"]}, "db2": {"schema1": ["Table1"]}}
 
+        # cross db, no db & schema parsed
+        assert SQLParser._get_tables_hierarchy(
+            [DbTableMeta("Table1"), DbTableMeta("Table2")],
+            normalize_name_lower,
+            database="Db",
+            is_cross_db=True,
+        ) == {"db": {None: ["Table1", "Table2"]}}
+
     def test_normalize_sql(self):
         assert SQLParser.normalize_sql("select * from asdf") == "select * from 
asdf"
 

Reply via email to