- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Create empty table if no data in source table
- Labels:
-
Apache Hive
Created ‎08-17-2017 08:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi i am doing some ETL with hiveQl I am creating new tables based on external hive tables, but then the external hive table is empty no empty table is created. How do i create a empty table if there is no records in the external table om selecting from. I am running the code from NIFI hiveql processor in nifi 2.x not supporting multiple hql statement. A oneliner would be beautiful Her is a example DROP TABLE IF EXISTS myname_t1; CREATE TABLE myname_t1 STORED AS ORC LOCATION '/archive/data/myname/T1'AS select*,INPUT__FILE__NAME ETL_FILENAME from myname;
Created ‎08-17-2017 01:43 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi I´m not sure if I understand this exactly but I´m going to try to answer it.
If you want to create an empty table from an empty external table the only thing you have to do is:
- Create external table
- create external table rangerhdfslog(j string) stored as textfile location '/ranger/audit/hdfs';
- Create table from external table
- create table rangerhdfslog2 as select * from rangerhdfslog;
So, that should work with any major issue.
Created ‎08-17-2017 01:43 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi I´m not sure if I understand this exactly but I´m going to try to answer it.
If you want to create an empty table from an empty external table the only thing you have to do is:
- Create external table
- create external table rangerhdfslog(j string) stored as textfile location '/ranger/audit/hdfs';
- Create table from external table
- create table rangerhdfslog2 as select * from rangerhdfslog;
So, that should work with any major issue.
Created ‎08-17-2017 02:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@palgaba You mean without major issue?
Created ‎08-17-2017 03:35 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
, yes sorry that is what I meant.
Created ‎08-17-2017 03:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Bala Vignesh N V is correct.
create table <new table> as
select * from <external_table>;
Will create a new empty table with the same as the external columns. The external table has to be created prior to executing the CTAS.
Created ‎08-18-2017 07:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Simon, I tried the same scenario in Spark-shell with Hive.. I am able to create orc table from another external table.. Attaching snap. createasselect.png
Can you pls provide logs or error displayed while "create as select" ?
Created ‎08-18-2017 08:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@nramanaiahHi, yes i found out the same,it seems to be happening when running hive through JDBC and ODBC. My problem is that i am running this in NIFI PutHiveQL processor
