You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hive.apache.org by Ritesh Gautam <gr...@gmail.com> on 2014/11/05 14:01:50 UTC

Parsing Hive queries to get table names and column names

Hello,
        I am trying to parse hive queries so that I can get the table names
on which the query is dependent on.

I have tried the following :
1) downloaded the grammer and used ANTLR to generate the lexer and parser,
but there are some errors as such when I try to build it:
......
  symbol:   class RecognitionException
  location: class HiveLexer
HiveLexer.java:2432: error: cannot find symbol
public final void mKW_ESCAPED() throws RecognitionException {
                                       ^
  symbol:   class RecognitionException
  location: class HiveLexer
HiveLexer.java:2453: error: cannot find symbol
public final void mKW_COLLECTION() throws RecognitionException {
                                          ^
  symbol:   class RecognitionException
  location: class HiveLexer
100 errors

2) I have tried using org.apache.hadoop.hive.ql.parse but I am stuck at
this point:

        ANTLRStringStream input = new ANTLRStringStream("SELECT x FROM
abc");
        HiveLexer lexer = new HiveLexer(input);
        TokenStream tokens = new CommonTokenStream(lexer);
        HiveParser parser = new HiveParser(tokens);
        System.out.println(parser.statement());

*How should I proceed from here to extract the table names and column
names?*
*And, Is the way I am doing it correct?*

Is this the correct forum to ask such questions?

Thank You.
Regards,
Ritesh

Re: Parsing Hive queries to get table names and column names

Posted by Lefty Leverenz <le...@gmail.com>.
Ritesh, a better forum would be user@hive.apache.org -- see
http://hive.apache.org/mailing_lists.html.



-- Lefty

On Wed, Nov 5, 2014 at 5:01 AM, Ritesh Gautam <gr...@gmail.com> wrote:

> Hello,
>         I am trying to parse hive queries so that I can get the table names
> on which the query is dependent on.
>
> I have tried the following :
> 1) downloaded the grammer and used ANTLR to generate the lexer and parser,
> but there are some errors as such when I try to build it:
> ......
>   symbol:   class RecognitionException
>   location: class HiveLexer
> HiveLexer.java:2432: error: cannot find symbol
> public final void mKW_ESCAPED() throws RecognitionException {
>                                        ^
>   symbol:   class RecognitionException
>   location: class HiveLexer
> HiveLexer.java:2453: error: cannot find symbol
> public final void mKW_COLLECTION() throws RecognitionException {
>                                           ^
>   symbol:   class RecognitionException
>   location: class HiveLexer
> 100 errors
>
> 2) I have tried using org.apache.hadoop.hive.ql.parse but I am stuck at
> this point:
>
>         ANTLRStringStream input = new ANTLRStringStream("SELECT x FROM
> abc");
>         HiveLexer lexer = new HiveLexer(input);
>         TokenStream tokens = new CommonTokenStream(lexer);
>         HiveParser parser = new HiveParser(tokens);
>         System.out.println(parser.statement());
>
> *How should I proceed from here to extract the table names and column
> names?*
> *And, Is the way I am doing it correct?*
>
> Is this the correct forum to ask such questions?
>
> Thank You.
> Regards,
> Ritesh
>