Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hive Insert Overwrite Table

Tags:

I'm new to Hive and I wanted to know if insert overwrite will overwrite an existing table I have created. I want to filter an already created table, let's call it TableA, to only select the rows where age is greater than 18. Can I achieve this using insert overwrite table?

I'm thinking of writing something like:

INSERT OVERWRITE TABLE TableA SELECT a.Age FROM TableA WHERE a.Age > = 18

there are NA entries in the table I created, but I assume that after I filter this table there will be no NAs in the Age column, right?

like image 958
Anna Mai Avatar asked Oct 02 '14 19:10

Anna Mai


People also ask

What is insert overwrite table in Hive?

Description. The INSERT OVERWRITE DIRECTORY with Hive format overwrites the existing data in the directory with the new values using Hive SerDe . Hive support must be enabled to use this command. The inserted rows can be specified by value expressions or result from a query.

What is insert overwrite table?

The INSERT OVERWRITE statement overwrites the existing data in the table using the new values. The inserted rows can be specified by value expressions or result from a query.

Can we do insert overwrite in Hive external table?

Conclusion. In summary the difference between Hive INSERT INTO vs INSERT OVERWRITE, INSERT INTO is used to append the data into Hive tables and partitioned tables and INSERT OVERWRITE is used to remove the existing data from the table and insert the new data.


1 Answers

Self filtering and insertion is not support , yet in hive.

I would suggest the following steps in your case :

1.Create a similar table , say tabB , with same structure.

create table tabB like tableA;

2.Then you could apply your filter and insert into this new table.

INSERT OVERWRITE TABLE tabB SELECT a.Age FROM TableA WHERE a.Age > = 18

Hope this helps.

like image 145
K S Nidhin Avatar answered Sep 21 '22 21:09

K S Nidhin