0
votes

My Ambari version is HDP 2.5.2 and Hive version is Hive 1.2.1000.2.5.3.0-37.

I am trying to see the merge operation working in HIVE. I have tried below steps:

  1. Enabled ACID transaction on Ambari and restarted HIVE services

  2. Created target table which contains old salaries of employees.

    create table emp(id int,name string,sal int) clustered by (id) into 4 buckets stored as ORC TBLPROPERTIES('transactional'='true');

  3. Inserted 4 records on it.

    insert into emp values(1,'ABC',1000);
    insert into emp values(102,'XYZ',2000);
    insert into emp values(103,'MNO',3000);
    insert into emp values(104,'PQR',200);

  4. Created source table which has id and updated salaries. This is a normal table loaded with csv files.

    create table emp_updated(id int,sal_new int) row format delimited fields terminated by ',';

    load data inpath '/data/emp_updated.csv' into table emp_updated;

  5. Now, I want to update my emp table's sal column with sal values from emp_updated table wherever id matches. I am giving below query.

    merge into emp as e1 using emp_updated as e2 on e1.id=e2.id when matced then update set sal=e2.sal;

It is giving me below error:

NoViableAltException(26@[])
        at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1084)
        at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:202)
        at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:437)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:320)
        at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1219)
        at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1260)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1156)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1146)
        at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:217)
        at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:169)
        at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:380)
        at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:740)
        at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:685)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:625)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.hadoop.util.RunJar.run(RunJar.java:233)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:148)
FAILED: ParseException line 1:0 cannot recognize input near 'merge' 'into' 'emp'

Is merge not supported for this version? What is the problem in the steps followed?

1

1 Answers

0
votes

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML. version problem . I think Merge command available from hive 2.2