You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Arina Yelchiyeva <ar...@gmail.com> on 2016/09/15 13:54:55 UTC

overwrite insert syntax

Hi all!

Calcite supports standard insert syntax. But I need to add partition by
clause in it.
I've been trying to overwrite it in parser using additional parser
statements calls but such calls go after insert in parsing hierarchy. So I
have been wondering is there a way to overwrite insert syntax?

Kind regards
Arina

Re: overwrite insert syntax

Posted by Julian Hyde <jh...@apache.org>.
JavaCC is a top-down parser. This means it needs to know which rule to
go into before it goes. It sees 'insert' and thinks 'hey, looks like
this could be a SqlInsert()', and never bothers going into
SqlInsertWithPartition.

Top-down parsers are, in general, a Good Thing, because they are
efficient. They don't have to maintain lots of state to be able to
back up and try alternative possibilities. But it puts the onus on you
to write a grammar that makes it clear where the parser should go
next.

I think you should get rid of SqlInsertWithPartition() and add a
template variable to SqlInsert(), just after

  [
      LOOKAHEAD(2)
      columnList = ParenthesizedSimpleIdentifierList()
  ]

and before

  source = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY)

Check that it works with and without a column list ("insert into x
(c1, c2) partition ..." and "insert into x partition ..."). You may
need to fiddle with that LOOKAHEAD(2), I don't know.

Julian



On Fri, Sep 16, 2016 at 4:26 AM, Arina Yelchiyeva
<ar...@gmail.com> wrote:
> I used extension to the parser through freemarker template.
> I have added parsing SqlInsertWithPartition() for new sql construct (insert
> into t2 (c1, c2) partition by (c1) select c1, c2 from t1)
> By I keep getting the following error:
> PARSE ERROR: Encountered "partition" at line 1, column 30.
> Though when I re-write my parsing to use other keyword then insert, for
> example, my_insert, everything works fine.
> My guess is that default insert parsing in Calcite [1] is done before
> custom.
>         stmt = SqlExplain()
>         |
>   *      stmt = SqlInsert()*
>         |
>         stmt = SqlDelete()
>         |
>         stmt = SqlUpdate()
>         |
>         stmt = SqlMerge()
>         |
>         stmt = SqlProcedureCall()
>
>         |
>        * stmt = SqlInsertWithPartition()*
>
> [1]
> https://github.com/apache/calcite/blob/master/core/src/main/codegen/templates/Parser.jj#L1259
>
> Am I doing something wrong?
>
> On Fri, Sep 16, 2016 at 3:33 AM Julian Hyde <jh...@apache.org> wrote:
>
>> Hopefully you know how to make extensions to the parser; see
>> https://issues.apache.org/jira/browse/PHOENIX-1706 for instance. You
>> can add an extension to INSERT syntax that is an empty string in
>> Calcite's version of the parser, something else in your version of the
>> parser. You might need to add a new template variable;
>> https://issues.apache.org/jira/browse/CALCITE-1241 is an example of a
>> change that did that.
>>
>> On Thu, Sep 15, 2016 at 6:54 AM, Arina Yelchiyeva
>> <ar...@gmail.com> wrote:
>> > Hi all!
>> >
>> > Calcite supports standard insert syntax. But I need to add partition by
>> > clause in it.
>> > I've been trying to overwrite it in parser using additional parser
>> > statements calls but such calls go after insert in parsing hierarchy. So
>> I
>> > have been wondering is there a way to overwrite insert syntax?
>> >
>> > Kind regards
>> > Arina
>>

Re: overwrite insert syntax

Posted by Arina Yelchiyeva <ar...@gmail.com>.
I used extension to the parser through freemarker template.
I have added parsing SqlInsertWithPartition() for new sql construct (insert
into t2 (c1, c2) partition by (c1) select c1, c2 from t1)
By I keep getting the following error:
PARSE ERROR: Encountered "partition" at line 1, column 30.
Though when I re-write my parsing to use other keyword then insert, for
example, my_insert, everything works fine.
My guess is that default insert parsing in Calcite [1] is done before
custom.
        stmt = SqlExplain()
        |
  *      stmt = SqlInsert()*
        |
        stmt = SqlDelete()
        |
        stmt = SqlUpdate()
        |
        stmt = SqlMerge()
        |
        stmt = SqlProcedureCall()

        |
       * stmt = SqlInsertWithPartition()*

[1]
https://github.com/apache/calcite/blob/master/core/src/main/codegen/templates/Parser.jj#L1259

Am I doing something wrong?

On Fri, Sep 16, 2016 at 3:33 AM Julian Hyde <jh...@apache.org> wrote:

> Hopefully you know how to make extensions to the parser; see
> https://issues.apache.org/jira/browse/PHOENIX-1706 for instance. You
> can add an extension to INSERT syntax that is an empty string in
> Calcite's version of the parser, something else in your version of the
> parser. You might need to add a new template variable;
> https://issues.apache.org/jira/browse/CALCITE-1241 is an example of a
> change that did that.
>
> On Thu, Sep 15, 2016 at 6:54 AM, Arina Yelchiyeva
> <ar...@gmail.com> wrote:
> > Hi all!
> >
> > Calcite supports standard insert syntax. But I need to add partition by
> > clause in it.
> > I've been trying to overwrite it in parser using additional parser
> > statements calls but such calls go after insert in parsing hierarchy. So
> I
> > have been wondering is there a way to overwrite insert syntax?
> >
> > Kind regards
> > Arina
>

Re: overwrite insert syntax

Posted by Julian Hyde <jh...@apache.org>.
Hopefully you know how to make extensions to the parser; see
https://issues.apache.org/jira/browse/PHOENIX-1706 for instance. You
can add an extension to INSERT syntax that is an empty string in
Calcite's version of the parser, something else in your version of the
parser. You might need to add a new template variable;
https://issues.apache.org/jira/browse/CALCITE-1241 is an example of a
change that did that.

On Thu, Sep 15, 2016 at 6:54 AM, Arina Yelchiyeva
<ar...@gmail.com> wrote:
> Hi all!
>
> Calcite supports standard insert syntax. But I need to add partition by
> clause in it.
> I've been trying to overwrite it in parser using additional parser
> statements calls but such calls go after insert in parsing hierarchy. So I
> have been wondering is there a way to overwrite insert syntax?
>
> Kind regards
> Arina