0
votes

I am trying to insert a table from Oracle to HDFS using Nifi. The source table in Oracle has a timestamp(6) datatype field called sd_timestamp. Nifi is having the following processor:

  1. QueryDatabase: This queries the OracleDatabase.
  2. CovertAVROSchema: This one has input and output schemas. Both input and output schemas have sd_timestamp datatype as String.
  3. ConvertAvroToOrc
  4. PutHDFS: The table that is created in Hive also has the datatype as string for sd_timestamp. When the ingestion is done and I do a select * from the destination hive table, I am getting oracle.sql.timestamp@23aff4 as the value instead of the timestamp.

Please help.

2
Okay.. btw, do you want it to be saved as a String in the Hive external table as well or you're okay with it being a String? - Sivaprasanna Sethuraman

2 Answers

2
votes

Here are details of what I did to get it working. Did not require the ConvertAvroSchema step.

Oracle table

CREATE TABLE my_table
(
  entry_name varchar(10),
  sd_timestamp timestamp(6)
);

Populate some data

insert into my_table values('e-1',CURRENT_TIMESTAMP);
insert into my_table values('e-2',CURRENT_TIMESTAMP);
insert into my_table values('e-3',CURRENT_TIMESTAMP);

Verify data

SELECT * FROM my_table;
ENTRY_NAME   SD_TIMESTAMP
e-1          09-MAY-18 06.45.24.963327000 PM
e-2          09-MAY-18 06.45.39.291241000 PM
e-3          09-MAY-18 06.45.44.748736000 PM

NiFi Flow

Flow Design enter image description here

QueryDatabaseTable configuration enter image description here

ConvertAvroToOrc configuration enter image description here

PutHDFS configuration enter image description here

LogAttribute to see the hive.ddl attribute value enter image description here

Verify results on HDFS

$ hadoop fs -ls /oracle-ingest
/oracle-ingest/50201861895275.orc

Create Hive table to query data using the hive.ddl value and adding location to it

hive> CREATE EXTERNAL TABLE IF NOT EXISTS my_oracle_table 
(
    ENTRY_NAME STRING, 
    SD_TIMESTAMP STRING
) 
STORED AS ORC 
LOCATION '/oracle-ingest';

Query Hive table

hive> select * from my_oracle_table;
e-1 2018-05-09 18:45:24.963327
e-2 2018-05-09 18:45:39.291241
e-3 2018-05-09 18:45:44.748736
1
votes

I am able to resolve the error by adding the following java argument to the bootstrap.conf file present in Nifi/Conf directory

-Doracle.jdbc.J2EE13Compliant=true