From 20ab64d1f1e782d6f21ae91f33198a21a8d70fba Mon Sep 17 00:00:00 2001 From: Ayush Shah Date: Tue, 18 Mar 2025 15:48:58 +0530 Subject: [PATCH] Fixes #17660: Oracle handle quotes for lowercase columns in workflow agents (#20309) --- .../src/metadata/profiler/orm/converter/base.py | 14 ++++++++------ ingestion/tests/cli_e2e/test_cli_oracle.py | 17 +++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/ingestion/src/metadata/profiler/orm/converter/base.py b/ingestion/src/metadata/profiler/orm/converter/base.py index b7225c358aa..6e254894d45 100644 --- a/ingestion/src/metadata/profiler/orm/converter/base.py +++ b/ingestion/src/metadata/profiler/orm/converter/base.py @@ -31,7 +31,7 @@ Base = declarative_base() SQA_RESERVED_ATTRIBUTES = ["metadata"] -def check_snowflake_case_sensitive(table_service_type, table_or_col) -> Optional[bool]: +def check_case_sensitive(table_service_type, table_or_col) -> Optional[bool]: """Check whether column or table name are not uppercase for snowflake table. If so, then force quoting, If not return None to let engine backend handle the logic. @@ -40,7 +40,10 @@ def check_snowflake_case_sensitive(table_service_type, table_or_col) -> Optional Return: None or True """ - if table_service_type == databaseService.DatabaseServiceType.Snowflake: + if table_service_type in { + databaseService.DatabaseServiceType.Snowflake, + databaseService.DatabaseServiceType.Oracle, + }: return True if not str(table_or_col).isupper() else None return None @@ -81,9 +84,10 @@ def build_orm_col( if _quote is not None: quote = _quote else: + quote = check_if_should_quote_column_name( table_service_type - ) or check_snowflake_case_sensitive(table_service_type, col.name.root) + ) or check_case_sensitive(table_service_type, col.name.root) return sqlalchemy.Column( name=str(col.name.root), @@ -150,9 +154,7 @@ def ometa_to_sqa_orm( "__table_args__": { "schema": orm_schema_name, "extend_existing": True, # Recreates the table ORM object if it already exists. Useful for testing - "quote": check_snowflake_case_sensitive( - table.serviceType, table.name.root - ) + "quote": check_case_sensitive(table.serviceType, table.name.root) or None, }, **cols, diff --git a/ingestion/tests/cli_e2e/test_cli_oracle.py b/ingestion/tests/cli_e2e/test_cli_oracle.py index 0e9d177b8c9..61eecda2154 100644 --- a/ingestion/tests/cli_e2e/test_cli_oracle.py +++ b/ingestion/tests/cli_e2e/test_cli_oracle.py @@ -38,7 +38,8 @@ class OracleCliTest(CliCommonDB.TestSuite, SQACommonMethods): hrly_rate NUMBER(7,2) GENERATED ALWAYS AS (sal/2080), comm NUMBER(7,2), comments VARCHAR2(3277), - status VARCHAR2(10)) + status VARCHAR2(10), + "col_with_quotes" VARCHAR2(10)), TABLESPACE USERS STORAGE ( INITIAL 50K) """ @@ -48,16 +49,16 @@ class OracleCliTest(CliCommonDB.TestSuite, SQACommonMethods): insert_data_queries: List[str] = [ """ - INSERT INTO admin.admin_emp (empno, ename, ssn, job, mgr, sal, comm, comments, status, photo) WITH names AS ( -SELECT 1, 'John Doe', 12356789, 'Manager', 121, 5200.0, 5000.0, 'Amazing', 'Active', EMPTY_BLOB() FROM dual UNION ALL -SELECT 2, 'Jane Doe', 123467189, 'Clerk', 131, 503.0, 5000.0, 'Wow', 'Active', EMPTY_BLOB() FROM dual UNION ALL -SELECT 3, 'Jon Doe', 123562789, 'Assistant', 141, 5000.0, 5000.0, 'Nice', 'Active', EMPTY_BLOB() FROM dual + INSERT INTO admin.admin_emp (empno, ename, ssn, job, mgr, sal, comm, comments, status, photo, "col_with_quotes") WITH names AS ( +SELECT 1, 'John Doe', 12356789, 'Manager', 121, 5200.0, 5000.0, 'Amazing', 'Active', EMPTY_BLOB(), 'test' FROM dual UNION ALL +SELECT 2, 'Jane Doe', 123467189, 'Clerk', 131, 503.0, 5000.0, 'Wow', 'Active', EMPTY_BLOB(), 'test' FROM dual UNION ALL +SELECT 3, 'Jon Doe', 123562789, 'Assistant', 141, 5000.0, 5000.0, 'Nice', 'Active', EMPTY_BLOB(), 'test' FROM dual ) SELECT * from names """, """ -INSERT INTO admin.admin_emp (empno, ename, ssn, job, mgr, sal, comm, comments, status, photo) WITH names AS ( -SELECT 4, 'Jon Doe', 13456789, 'Manager', 151, 5050.0, 5000.0, 'Excellent', 'Active', UTL_RAW.CAST_TO_RAW('your_binary_data') FROM dual +INSERT INTO admin.admin_emp (empno, ename, ssn, job, mgr, sal, comm, comments, status, photo, "col_with_quotes") WITH names AS ( +SELECT 4, 'Jon Doe', 13456789, 'Manager', 151, 5050.0, 5000.0, 'Excellent', 'Active', UTL_RAW.CAST_TO_RAW('your_binary_data'), 'test' FROM dual ) SELECT * from names """, @@ -103,7 +104,7 @@ SELECT * from names """view was created from `CREATE VIEW xyz AS (SELECT * FROM abc)` which does not propagate column lineage """ - return 12 + return 13 def expected_lineage_node(self) -> str: return "e2e_oracle.default.admin.admin_emp_view"