Skip to content

Commit

Permalink
Merge branch 'main' into feature/add-accuracy-metric
Browse files Browse the repository at this point in the history
* main:
  Fixes open-metadata#17085: Update Oracle count & unique count function to handle HexByteString/Blob types (open-metadata#17596)
  • Loading branch information
hurongliang committed Sep 6, 2024
2 parents f3e8b9c + b2f21fa commit e9f65ae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
9 changes: 9 additions & 0 deletions ingestion/src/metadata/profiler/orm/functions/count.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from metadata.profiler.metrics.core import CACHE
from metadata.profiler.orm.registry import Dialects
from metadata.profiler.orm.types.custom_hex_byte_string import HexByteString

# Keep SQA docs style defining custom constructs
# pylint: disable=consider-using-f-string,duplicate-code
Expand All @@ -36,6 +37,14 @@ def _(element, compiler, **kw):
return compiler.process(element.clauses, **kw)


@compiles(CountFn, Dialects.Oracle)
def _(element, compiler, **kw):
col_type = element.clauses.clauses[0].type
if isinstance(col_type, HexByteString):
return f"DBMS_LOB.GETLENGTH({compiler.process(element.clauses, **kw)})"
return compiler.process(element.clauses, **kw)


@compiles(CountFn, Dialects.MSSQL)
def _(element, compiler, **kw):
col_type = element.clauses.clauses[0].type
Expand Down
6 changes: 6 additions & 0 deletions ingestion/src/metadata/profiler/orm/functions/unique_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,11 @@ def _unique_count_query_mssql(col, session, sample):
)


def _unique_count_query_oracle(col, session, sample):
count_fn = CountFn(col)
return _unique_count_query(count_fn, session, sample)


_unique_count_query_mapper = defaultdict(lambda: _unique_count_query)
_unique_count_query_mapper[Dialects.MSSQL] = _unique_count_query_mssql
_unique_count_query_mapper[Dialects.Oracle] = _unique_count_query_oracle
26 changes: 13 additions & 13 deletions ingestion/tests/cli_e2e/test_cli_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

from typing import List

import pytest

from metadata.ingestion.api.status import Status

from .base.e2e_types import E2EType
Expand Down Expand Up @@ -48,14 +46,19 @@ class OracleCliTest(CliCommonDB.TestSuite, SQACommonMethods):

insert_data_queries: List[str] = [
"""
INSERT INTO admin.admin_emp (empno, ename, ssn, job, mgr, sal, comm, comments, status) WITH names AS (
SELECT 1, 'John Doe', 12356789, 'Manager', 121, 5200.0, 5000.0, 'Amazing', 'Active' FROM dual UNION ALL
SELECT 2, 'Jane Doe', 123467189, 'Clerk', 131, 503.0, 5000.0, 'Wow', 'Active' FROM dual UNION ALL
SELECT 3, 'Jon Doe', 123562789, 'Assistant', 141, 5000.0, 5000.0, 'Nice', 'Active' FROM dual UNION ALL
SELECT 4, 'Jon Doe', 13456789, 'Manager', 151, 5050.0, 5000.0, 'Excellent', 'Active' FROM dual
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
)
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
)
SELECT * from names
""",
]

drop_table_query: str = """
Expand Down Expand Up @@ -98,11 +101,11 @@ def view_column_lineage_count(self) -> int:

@staticmethod
def fqn_created_table() -> str:
return "e2e_oracle.default.admin.admin_emp"
return "e2e_oracle.default.admin.ADMIN_EMP"

@staticmethod
def _fqn_deleted_table() -> str:
return "e2e_oracle.default.admin.admin_emp"
return "e2e_oracle.default.admin.ADMIN_EMP"

@staticmethod
def get_includes_schemas() -> List[str]:
Expand Down Expand Up @@ -136,9 +139,6 @@ def expected_filtered_table_excludes() -> int:
def expected_filtered_mix() -> int:
return 43

@pytest.mark.xfail(
reason="Issue Raised: https://github.com/open-metadata/OpenMetadata/issues/17085"
)
def test_create_table_with_profiler(self) -> None:
# delete table in case it exists
self.delete_table_and_view()
Expand Down

0 comments on commit e9f65ae

Please sign in to comment.