Search code examples
sqloracle-databaseapache-nifivertica

Nifi extract content from ExecuteSQL output


I am trying to fetch the DDL from Oracle, and then convert the DDL into syntax appropriate for Vertica database. My ExecuteSQL processor SQL query is:

select dbms_metadata.get_ddl('TABLE','${table_name}','${owner}') as t_ddl from dual

I am getting the following output in AVRO format:

Objavro.schemaú{"type":"record","name":"NiFi_ExecuteSQL_Record","namespace":"any.data","fields":[{"name":"T_DDL","type":["null","string"]}]}avro.codecnull­¶½``¼�÷KGÙ‡LÞoCäÞ
  CREATE TABLE "VDBA"."CUSTOMERS" 
   (    "CUSTOMER_ID" NUMBER(10,0) NOT NULL ENABLE, 
    "CUSTOMER_NAME" VARCHAR2(50) NOT NULL ENABLE, 
    "CITY" VARCHAR2(50), 
    "ITEMS_CNT" NUMBER(5,0), 
    "TSTAMP" TIMESTAMP (6) DEFAULT CURRENT_TIMESTAMP NOT NULL ENABLE
   ) SEGMENT CREATION IMMEDIATE 
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 
 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" ­¶½``¼�÷KGÙ‡LÞoC

From this output, I only need the following text:

CREATE TABLE VDBA.CUSTOMERS 
   (CUSTOMER_ID NUMBER(10,0) NOT NULL, 
    CUSTOMER_NAME VARCHAR2(50) NOT NULL, 
    CITY VARCHAR2(50), 
    ITEMS_CNT NUMBER(5,0), 
    TSTAMP TIMESTAMP (6) DEFAULT CURRENT_TIMESTAMP NOT NULL
   )

I am unable to understand how to proceed next. Will ReplaceText processor work here? Please give me some pointers to move ahead.

Thanks & Regards, Bishal


Solution

  • Try using a ConvertAvroToJSON processor and then manipulating or extracting the JSON from there.