Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete and update a record in Hive

I have installed Hadoop, Hive, Hive JDBC. which are running fine for me. But I still have a problem. How to delete or update a single record using Hive because delete or update command of MySQL is not working in Hive.

Thanks

hive> delete from student where id=1; Usage: delete [FILE|JAR|ARCHIVE] <value> [<value>]* Query returned non-zero code: 1, cause: null 
like image 245
Charnjeet Singh Avatar asked Jul 23 '13 12:07

Charnjeet Singh


People also ask

How do I update Hive data?

You use the UPDATE statement to modify data already stored in an Apache Hive table. You construct an UPDATE statement using the following syntax: UPDATE tablename SET column = value [, column = value ...]

How do I delete data from hive?

Use the following syntax to delete data from a Hive table. DELETE FROM tablename [WHERE expression]; Delete any rows of data from the students table if the gpa column has a value of 1 or 0.

Is it possible to delete and update in Hive table have you used in your project?

Your answerThere is no operation supported for deletion or update of a particular record or particular set of records, and to me, this is more a sign of a poor schema.

How do you overwrite data in Hive table?

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.


1 Answers

As of Hive version 0.14.0: INSERT...VALUES, UPDATE, and DELETE are now available with full ACID support.

INSERT ... VALUES Syntax:

INSERT INTO TABLE tablename [PARTITION (partcol1[=val1], partcol2[=val2] ...)] VALUES values_row [, values_row ...] 

Where values_row is: ( value [, value ...] ) where a value is either null or any valid SQL literal

UPDATE Syntax:

UPDATE tablename SET column = value [, column = value ...] [WHERE expression] 

DELETE Syntax:

DELETE FROM tablename [WHERE expression] 

Additionally, from the Hive Transactions doc:

If a table is to be used in ACID writes (insert, update, delete) then the table property "transactional" must be set on that table, starting with Hive 0.14.0. Without this value, inserts will be done in the old style; updates and deletes will be prohibited.

Hive DML reference:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML
Hive Transactions reference:
https://cwiki.apache.org/confluence/display/Hive/Hive+Transactions

like image 148
ashtonium Avatar answered Sep 26 '22 06:09

ashtonium