Skip to main content
Question

Oracle functions migration to Vertica

  • January 2, 2020
  • 6 replies
  • 22 views

farazrahman

We are working on a migration from Oracle to Vertica which involves converting Oracle functions. The customer uses Cognos for reporting where they have a query which calls the Oracle functions presently.

The approach we tried is re-writing the Oracle functions in Vertica using UDX (Python), the problem is that for each report (query) we will end up with multiple cursor calls which hits performance.

Example: For every row in the report we have to fire a select query within udx , so we might fire 1 report query which might have 100 records then we will end up running 1 report query + 100 queries which will be within the function.

Can you please suggest the recommended option for Oracle functions migration?

6 replies

Jim_Knicely
Forum|alt.badge.img+2
  • Participating Frequently
  • January 2, 2020

Hi,
Why does Cognos need to call the function for every report row? Can you just modiy the report query (i.e. SQL) to include the function's logic?

Example:

    dbadmin=> \d report_data
                                       List of Fields by Tables
     Schema |    Table    | Column | Type | Size | Default | Not Null | Primary Key | Foreign Key
    --------+-------------+--------+------+------+---------+----------+-------------+-------------
     public | report_data | c      | int  |    8 |         | f        | f           |
    (1 row)

    dbadmin=> \d lookup_data
                                           List of Fields by Tables
     Schema |    Table    |  Column   |    Type    | Size | Default | Not Null | Primary Key | Foreign Key
    --------+-------------+-----------+------------+------+---------+----------+-------------+-------------
     public | lookup_data | c         | int        |    8 |         | f        | f           |
     public | lookup_data | some_data | varchar(5) |    5 |         | f        | f           |
    (2 rows)

You can use a function (i.e. get_lookup_data) to get the values in the column LOOKUP_DATA.SOME_DATA for every row in the REPORT_DATA table:

SELECT c, get_lookup_data(c) AS lookup_data
  FROM report_data;

Unfortunatley you can't create a User Defined SQL Function in Vertica to do that...

dbadmin=> CREATE FUNCTION get_lookup_data(c_in INT) RETURN VARCHAR(5)
dbadmin-> AS
dbadmin-> BEGIN
dbadmin->   RETURN (SELECT some_data FROM lookup_data WHERE c = c_in);
dbadmin-> END;
ROLLBACK 2624:  Column "c_in" does not exist

Which is why you probably went to Python... But why do that when you can simply do it in the report SQL?

dbadmin=> SELECT a.c, b.some_data
dbadmin->   FROM report_data a
dbadmin->   JOIN lookup_data b
dbadmin->     ON b.c = a.c
dbadmin->  LIMIT 1;
 c | some_data
---+-----------
 5 | WTUKP
(1 row)

farazrahman
  • Author
  • New Participant
  • January 3, 2020

Thanks Jim!!
We were trying to avoid changes in the reporting side of things as the customer did not want their reports to be touched, they have 2000 reports and want to continue to use AS-IS post migration. But it seems from your suggestion it is unavoidable and rather recommended to go down that path. Thanks again.


Vertica_Curtis
Forum|alt.badge.img+1
  • Participating Frequently
  • January 3, 2020

What does the Oracle function do?


farazrahman
  • Author
  • New Participant
  • January 3, 2020

It executes a bunch of SQLs and has some business logic


Vertica_Curtis
Forum|alt.badge.img+1
  • Participating Frequently
  • January 3, 2020

So these are PL/SQL scripts?


farazrahman
  • Author
  • New Participant
  • January 3, 2020

Yes