NoViableAltException(281@[]) exception while parsing hive query
<p>I had requirement in which I am parsing hive queries using following classes from hive-exex jar
        org.apache.hadoop.hive.ql.parse.ParseDriver,org.apache.hadoop.hive.ql.parse.ASTNode,org.apache.hadoop.hive.ql.parse.ParseUtils,org.apache.hadoop.hive.ql.parse.HiveParser.</p>

<pre><code>    for accessing these classes from hive-exec jar i am using following maven dependency in my project :

&lt;dependency&gt;
  &lt;groupId&gt;org.apache.hive&lt;/groupId&gt;
  &lt;artifactId&gt;hive-exec&lt;/artifactId&gt;
  &lt;version&gt;0.13.1-cdh5.3.0&lt;/version&gt;
&lt;/dependency&gt;
</code></pre>

<p>My hive query parsing utility works in almost all cases but surprisingly its failing in case of following query :</p>

<p>INSERT INTO db_lineage.many_one_hv SELECT * FROM (SELECT * FROM db_lineage.one_many1_hv UNION ALL SELECT * FROM db_lineage.one_many2_hv) FINAL;</p>

<p>This query is getting executed successfully on hive cluster with version 0.14 and 1.2 but in my local system its failing on my local system.Exception that I am getting is as follows:
NoViableAltException(281@[])
    at org.apache.hadoop.hive.ql.parse.HiveParser.queryStatementExpressionBody(HiveParser.java:36959)
    at org.apache.hadoop.hive.ql.parse.HiveParser.queryStatementExpression(HiveParser.java:36865)
    at org.apache.hadoop.hive.ql.parse.HiveParser_FromClauseParser.subQuerySource(HiveParser_FromClauseParser.java:5463)
    at org.apache.hadoop.hive.ql.parse.HiveParser_FromClauseParser.fromSource(HiveParser_FromClauseParser.java:3931)
    at org.apache.hadoop.hive.ql.parse.HiveParser_FromClauseParser.joinSource(HiveParser_FromClauseParser.java:1798)
    at org.apache.hadoop.hive.ql.parse.HiveParser_FromClauseParser.fromClause(HiveParser_FromClauseParser.java:1456)
    at org.apache.hadoop.hive.ql.parse.HiveParser.fromClause(HiveParser.java:40272)
    at org.apache.hadoop.hive.ql.parse.HiveParser.singleSelectStatement(HiveParser.java:38160)
    at org.apache.hadoop.hive.ql.parse.HiveParser.selectStatement(HiveParser.java:37845)
    at org.apache.hadoop.hive.ql.parse.HiveParser.regularBody(HiveParser.java:37745)
    at org.apache.hadoop.hive.ql.parse.HiveParser.queryStatementExpressionBody(HiveParser.java:36989)
    at org.apache.hadoop.hive.ql.parse.HiveParser.queryStatementExpression(HiveParser.java:36865)
    at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1332)
    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.parse.ParseDriver.parse(ParseDriver.java:161)
    at com.abc.bigsuite.parser.ECatHiveParser.parse(ECatHiveParser.java:39)
    at com.abc.bigsuite.parser.HiveParserTest.testIssue1(HiveParserTest.java:494)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)</p>

<p>[ERROR] com.datametica.bigsuite.parser.ECatHiveParser - Exception in parsing above query
org.apache.hadoop.hive.ql.parse.ParseException: line 1:12 missing TABLE at 'db_lineage' near '(' in subquery source
line 1:50 cannot recognize input near '(' 'SELECT' '*' in subquery source
    at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:202) ~[hive-exec-0.13.1-cdh5.3.0.jar:0.13.1-cdh5.3.0]
    at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166) ~[hive-exec-0.13.1-cdh5.3.0.jar:0.13.1-cdh5.3.0]
    at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:161) ~[hive-exec-0.13.1-cdh5.3.0.jar:0.13.1-cdh5.3.0]
    at com.abc.bigsuite.parser.ECatHiveParser.parse(ECatHiveParser.java:39) ~[classes/:na]
    at com.abc.bigsuite.parser.HiveParserTest.testIssue1(HiveParserTest.java:494) [test-classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_80]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_80]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_80]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_80]
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) [junit-4.12.jar:4.12]
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) [junit-4.12.jar:4.12]</p>

<p>I never connect to hive cluster or any database,my utility is standalone parsing of hive query and retrieve source node and destination node from it only by using hive-exec dependencies.please let me know if you can provide any inputs on this.</p>

<p>Thanks and Regards,
Mahendra Tonape.</p>