Hive: Is it possible to rename an existing hive database?

activelearner picture activelearner · Apr 7, 2015 · Viewed 16.6k times · Source

There seems to be a similar requirement at: https://issues.apache.org/jira/browse/HIVE-4847

However, when I tried the proposed syntax from the issue's Description - 'ALTER DATABASE dbname RENAME TO newdbname', it gave me the following error:

ALTER DATABASE testdb RENAME TO testdb1;

NoViableAltException(26@[])
    at org.apache.hadoop.hive.ql.parse.HiveParser.alterDatabaseStatementSuffix(HiveParser.java:7881)
    at org.apache.hadoop.hive.ql.parse.HiveParser.alterStatement(HiveParser.java:6588)
    at org.apache.hadoop.hive.ql.parse.HiveParser.ddlStatement(HiveParser.java:2183)
    at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1392)
    at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1030)
    at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:199)
    at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
    at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:414)
    at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:332)
    at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:988)
    at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1053)
    at org.apache.hadoop.hive.ql.Driver.run(Driver.java:924)
    at org.apache.hadoop.hive.ql.Driver.run(Driver.java:914)
    at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:269)
    at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:221)
    at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:431)
    at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:367)
    at org.apache.hadoop.hive.cli.CliDriver.processReader(CliDriver.java:464)
    at org.apache.hadoop.hive.cli.CliDriver.processFile(CliDriver.java:474)
    at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:756)
    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:694)
    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:633)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
FAILED: ParseException line 3:15 cannot recognize input near 'testdb' 'RENAME' 'TO' in alter database statement

Answer

SachinJ picture SachinJ · Apr 7, 2015

Current Apache hive release doesn't support this feature. In this apache Hive Jira HIVE-4847, you can see this is a new feature and the patch is available but it is yet to be merged and tagged to a particular release. We can expect this feature in any of the later releases.