OpenMetadata icon indicating copy to clipboard operation
OpenMetadata copied to clipboard

Oracle Package ingestion error. Parsed code is incorrect.

Open AlexeySumin opened this issue 1 year ago • 11 comments

Reopening to validate based on latest comment

ref: https://github.com/open-metadata/OpenMetadata/issues/21086#issuecomment-3888984385


Fixed in #25045 Affected module Ingestion and probably lineage

Describe the bug When i try to open some package (in OMD) and to view code on its Code tab, i always see some kind of mess: Image

It seems to be, that there is some error with sorting lines of code. Some lines, that should be in the beginning could be found in the end of package.

To Reproduce Run metadata ingestion on version 170. There is a new feature, that allows to ingest packages. Run this on big package 1k+ lines.

Expected behavior DDL in OMD should look like DDL in datagrip or other ide tools.

Version:

  • OpenMetadata version: 1.7.0-release

Additional context This might affect lineages with oracle packages.

AlexeySumin avatar May 06 '25 12:05 AlexeySumin

Looks like there is a problem with sorting and sorting

ORDER BY
    OWNER,
    NAME,
    LINE

should be added here

AlexeySumin avatar May 07 '25 10:05 AlexeySumin

@ulixius9 Hey! Maybe it would be helpful. I think this query is ok for ORACLE_GET_STORED_PACKAGES:

SELECT
    OWNER,
    NAME,
    LINE,
    TEXT,
    'StoredPackage' as procedure_type
FROM
    DBA_SOURCE
WHERE TYPE IN ('PACKAGE', 'PACKAGE BODY') AND owner = '{schema}'
ORDER BY
    OWNER,
    NAME,
    CASE type
        WHEN 'PACKAGE' THEN 1
        WHEN 'PACKAGE BODY' THEN 2
        ELSE 3
    END,
    LINE
;

AlexeySumin avatar Aug 12 '25 07:08 AlexeySumin

@AlexeySumin I tried to reproduce this, this is the dummy package that I created for testing and the same code I see on the OMD UI, can you share your package ddl to reproduce the same issue as you?

also what you recommended I cannot do that because I want procedures and functions to be part of the ingestion as well can you tell me what is the exact type which you want to ignore to fine tune it?

CREATE OR REPLACE PACKAGE BODY employee_pkg AS
  
  PROCEDURE add_employee (
    p_emp_id   NUMBER,
    p_name     VARCHAR2,
    p_salary   NUMBER
  ) IS
  BEGIN
    INSERT INTO employees (emp_id, emp_name, salary)
    VALUES (p_emp_id, p_name, p_salary);
    COMMIT;
  END add_employee;

  FUNCTION get_employee_salary (
    p_emp_id NUMBER
  ) RETURN NUMBER IS
    v_salary NUMBER;
  BEGIN
    SELECT salary INTO v_salary
    FROM employees
    WHERE emp_id = p_emp_id;
    RETURN v_salary;
  EXCEPTION
    WHEN NO_DATA_FOUND THEN
      RETURN NULL;
  END get_employee_salary;

END employee_pkg;
/

Image

ulixius9 avatar Aug 12 '25 10:08 ulixius9

@ulixius9 Hey!

  1. I cant copy and paste it from my production, but i think, this is the package from my screenshot above: https://github.com/chameleon82/oracle-scripts/blob/master/mail_pkg.pck
  2. Look on the screenshot below. I dont want to ignore something, i suppose, that the problem is in missing "order by" section. Image

I suppose, there should be added this order by

ORDER BY
    OWNER,
    NAME,
    CASE type
        WHEN 'PACKAGE' THEN 1
        WHEN 'PACKAGE BODY' THEN 2
        ELSE 3
    END,
    LINE
;

AlexeySumin avatar Aug 12 '25 16:08 AlexeySumin

@ulixius9 hey! any news? maybe you need some more info or test cases?

AlexeySumin avatar Aug 25 '25 11:08 AlexeySumin

fixed by https://github.com/open-metadata/OpenMetadata/pull/25045

ulixius9 avatar Jan 06 '26 14:01 ulixius9

@ulixius9 @ayush-shah @keshavmohta09 The bug is still not fixed. Ive posted a link on package for testing in comment https://github.com/open-metadata/OpenMetadata/issues/21086#issuecomment-3180101890

You ve missed this in orded by:

    CASE type
        WHEN 'PACKAGE' THEN 1
        WHEN 'PACKAGE BODY' THEN 2
        ELSE 3
    END,

Look on line numbers and code textlines, when this section is commented. Order is inciorrect. Image

And when i uncomment this, the code becomes correct.

Image

AlexeySumin avatar Feb 12 '26 06:02 AlexeySumin

We will reopen this for validation, we will share here if we can reproduce.

ayush-shah avatar Feb 12 '26 06:02 ayush-shah

@AlexeySumin can you share which version are you on?

ayush-shah avatar Feb 12 '26 06:02 ayush-shah

Hi @AlexeySumin, thank you for pointing out this issue. We have now fixed it in this PR: https://github.com/open-metadata/OpenMetadata/pull/25855.

keshavmohta09 avatar Feb 12 '26 18:02 keshavmohta09

@ayush-shah Im on 1.10.12 now. On every update i go and fix this sorting by hand before service is up)

AlexeySumin avatar Feb 13 '26 14:02 AlexeySumin