Monday, 8 June 2015

Hadoop-Hive - Dual Table in Hive

Hive Does Not Having DUAL table how oracle is having. Oracle users use this DUAL table for multiple purposes. All Oracle users are looking this DUAL table in Hive for selecting Sysdate, calculation, etc..
Hive does not having Built in DUAL table But We can achieve the same thing in Hive by creating the Same DUAL table in Hive.

Step 1)  Login to Hive and create the table like below
             CREATE TABLE dual (dummy STRING);

Step 2) Insert single record into this table. Otherwise it will not work like how Dual works in Oracle.
            Insert Record into Dual Table can be via File and Run the file
            LOAD DATA LOCAL INPATH '/tmp/dual.txt' OVERWRITE INTO TABLE dual;
      or Insert records from other table also fine.
      INSERT INTO TABLE DUAL SELECT 'text' FROM TEMP_OTHER_TABLE LIMIT 1;

Not DUAL Table is ready for use. You can use it for getting the Sysdate, etc...

Eg. Hive > select unix_timestamp() from dual;

No comments:

Post a Comment