You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Yogendra Sharma <sy...@live.com> on 2022/01/06 14:10:06 UTC

Parsing ALTER TABLE Statements

Wondering why does calcite DDL parser fail to parse ALTER TABLE stayements?

In the code I see that we support ALTER SESSION and ALTER SYSTEM but not ALTER Table.

-Yogi



Get Outlook for Android<https://aka.ms/ghei36>

Re: Parsing ALTER TABLE Statements

Posted by Stamatis Zampetakis <za...@gmail.com>.
The main idea is outlined below:

1. Obtain the Parser.jj file [1] from Calcite and put it somewhere in your
project; this file includes FreeMarker directives.
2. Create a file with the parser extensions (for javacc) (e.g.,
parserImpls.ftl [2]) specific to your project.
3. Create/Personalize a FMPP configuration file (e.g., config.fmpp [3])
pointing to the parser extensions.
4. Use a FreeMarker processor to generate the final Parser.jj file with all
FreeMarker templates filled in.
5. Use JavaCC to generate the Java files for the parser.

Usually these steps are done automatically during the build process relying
on Maven/Gradle plugins. For examples:
* with Gradle check server [4] or babel [5] modules in Calcite;
* with Maven check the Drill project [6].

Best,
Stamatis

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

[2]
https://github.com/apache/calcite/blob/ea4a5f36085553d427a339270a6e0b9b844f2364/server/src/main/codegen/includes/parserImpls.ftl
[3]
https://github.com/apache/calcite/blob/ea4a5f36085553d427a339270a6e0b9b844f2364/server/src/main/codegen/config.fmpp
[4]
https://github.com/apache/calcite/blob/ea4a5f36085553d427a339270a6e0b9b844f2364/server/build.gradle.kts
[5]
https://github.com/apache/calcite/blob/ea4a5f36085553d427a339270a6e0b9b844f2364/babel/build.gradle.kts
[6]
https://github.com/apache/drill/blob/31b1274b6beddd191bee9c1d0ab2c827296b0353/exec/java-exec/pom.xml#L831

On Fri, Jan 7, 2022 at 7:20 AM Yogendra Sharma <sy...@live.com> wrote:

> Thanks Stamatis. It makes sense now.
>
> Just a request - I am unable to understand how parser extensions work in
> Calcite. Can you please point me to any test-case or example or doc?
>
> ________________________________
> From: Stamatis Zampetakis <za...@gmail.com>
> Sent: Friday, January 7, 2022 3:12 AM
> To: dev@calcite.apache.org <de...@calcite.apache.org>
> Subject: Re: Parsing ALTER TABLE Statements
>
> Hi Yogendra,
>
> ALTER TABLE is not part of the standard and differs from one system to the
> other so it's difficult to come up with something that covers every
> use-case.
> Most often users choose to add the ALTER TABLE via the FreeMarker template
> extensions in their codebase.
> As mentioned previously [1], if somebody wants to contribute to the parser,
> probably the babel module is the best place for this.
>
> Best,
> Stamatis
>
> [1] https://lists.apache.org/thread/lo5v3t6rk2htptr7v62r91s7vstnngj2
>
> On Thu, Jan 6, 2022 at 7:32 PM Yogendra Sharma <sy...@live.com> wrote:
>
> > I did supply is DDL parser factory but it's able to parse other DDL
> > statements such as DELETE, UPDATE, INSERT but not ALTER.
> >
> > Sample code as below-
> >
> > SqlParser.Config config = SqlParser.config()
> >
> > .withParserFactory(SqlDdlParserImpl.FACTORY)
> >
> > .withConformance(SqlConformanceEnum.STRICT_2003);
> > SqlParser parser = SqlParser.create("alter table tab1 drop column col1",
> > config);
> > SqlNode node = parser.parse();
> >
> >
> > ________________________________
> > From: Jacques Nadeau <ja...@apache.org>
> > Sent: Thursday, January 6, 2022 11:19 PM
> > To: dev@calcite.apache.org <de...@calcite.apache.org>
> > Subject: Re: Parsing ALTER TABLE Statements
> >
> > I believe this is a feature that is off by default. Try creating your
> > parser with an alternative parser factory. I think it is something like
> > this:
> >
> > SqlParser.Config.DEFAULT.withParserFactory(SqlDdlParserImpl.FACTORY)
> >
> > On Thu, Jan 6, 2022 at 6:10 AM Yogendra Sharma <sy...@live.com> wrote:
> >
> > > Wondering why does calcite DDL parser fail to parse ALTER TABLE
> > stayements?
> > >
> > > In the code I see that we support ALTER SESSION and ALTER SYSTEM but
> not
> > > ALTER Table.
> > >
> > > -Yogi
> > >
> > >
> > >
> > > Get Outlook for Android<https://aka.ms/ghei36>
> > >
> >
>

Re: Parsing ALTER TABLE Statements

Posted by Yogendra Sharma <sy...@live.com>.
Thanks Stamatis. It makes sense now.

Just a request - I am unable to understand how parser extensions work in Calcite. Can you please point me to any test-case or example or doc?

________________________________
From: Stamatis Zampetakis <za...@gmail.com>
Sent: Friday, January 7, 2022 3:12 AM
To: dev@calcite.apache.org <de...@calcite.apache.org>
Subject: Re: Parsing ALTER TABLE Statements

Hi Yogendra,

ALTER TABLE is not part of the standard and differs from one system to the
other so it's difficult to come up with something that covers every
use-case.
Most often users choose to add the ALTER TABLE via the FreeMarker template
extensions in their codebase.
As mentioned previously [1], if somebody wants to contribute to the parser,
probably the babel module is the best place for this.

Best,
Stamatis

[1] https://lists.apache.org/thread/lo5v3t6rk2htptr7v62r91s7vstnngj2

On Thu, Jan 6, 2022 at 7:32 PM Yogendra Sharma <sy...@live.com> wrote:

> I did supply is DDL parser factory but it's able to parse other DDL
> statements such as DELETE, UPDATE, INSERT but not ALTER.
>
> Sample code as below-
>
> SqlParser.Config config = SqlParser.config()
>
> .withParserFactory(SqlDdlParserImpl.FACTORY)
>
> .withConformance(SqlConformanceEnum.STRICT_2003);
> SqlParser parser = SqlParser.create("alter table tab1 drop column col1",
> config);
> SqlNode node = parser.parse();
>
>
> ________________________________
> From: Jacques Nadeau <ja...@apache.org>
> Sent: Thursday, January 6, 2022 11:19 PM
> To: dev@calcite.apache.org <de...@calcite.apache.org>
> Subject: Re: Parsing ALTER TABLE Statements
>
> I believe this is a feature that is off by default. Try creating your
> parser with an alternative parser factory. I think it is something like
> this:
>
> SqlParser.Config.DEFAULT.withParserFactory(SqlDdlParserImpl.FACTORY)
>
> On Thu, Jan 6, 2022 at 6:10 AM Yogendra Sharma <sy...@live.com> wrote:
>
> > Wondering why does calcite DDL parser fail to parse ALTER TABLE
> stayements?
> >
> > In the code I see that we support ALTER SESSION and ALTER SYSTEM but not
> > ALTER Table.
> >
> > -Yogi
> >
> >
> >
> > Get Outlook for Android<https://aka.ms/ghei36>
> >
>

Re: Parsing ALTER TABLE Statements

Posted by Stamatis Zampetakis <za...@gmail.com>.
Hi Yogendra,

ALTER TABLE is not part of the standard and differs from one system to the
other so it's difficult to come up with something that covers every
use-case.
Most often users choose to add the ALTER TABLE via the FreeMarker template
extensions in their codebase.
As mentioned previously [1], if somebody wants to contribute to the parser,
probably the babel module is the best place for this.

Best,
Stamatis

[1] https://lists.apache.org/thread/lo5v3t6rk2htptr7v62r91s7vstnngj2

On Thu, Jan 6, 2022 at 7:32 PM Yogendra Sharma <sy...@live.com> wrote:

> I did supply is DDL parser factory but it's able to parse other DDL
> statements such as DELETE, UPDATE, INSERT but not ALTER.
>
> Sample code as below-
>
> SqlParser.Config config = SqlParser.config()
>
> .withParserFactory(SqlDdlParserImpl.FACTORY)
>
> .withConformance(SqlConformanceEnum.STRICT_2003);
> SqlParser parser = SqlParser.create("alter table tab1 drop column col1",
> config);
> SqlNode node = parser.parse();
>
>
> ________________________________
> From: Jacques Nadeau <ja...@apache.org>
> Sent: Thursday, January 6, 2022 11:19 PM
> To: dev@calcite.apache.org <de...@calcite.apache.org>
> Subject: Re: Parsing ALTER TABLE Statements
>
> I believe this is a feature that is off by default. Try creating your
> parser with an alternative parser factory. I think it is something like
> this:
>
> SqlParser.Config.DEFAULT.withParserFactory(SqlDdlParserImpl.FACTORY)
>
> On Thu, Jan 6, 2022 at 6:10 AM Yogendra Sharma <sy...@live.com> wrote:
>
> > Wondering why does calcite DDL parser fail to parse ALTER TABLE
> stayements?
> >
> > In the code I see that we support ALTER SESSION and ALTER SYSTEM but not
> > ALTER Table.
> >
> > -Yogi
> >
> >
> >
> > Get Outlook for Android<https://aka.ms/ghei36>
> >
>

Re: Parsing ALTER TABLE Statements

Posted by Yogendra Sharma <sy...@live.com>.
I did supply is DDL parser factory but it's able to parse other DDL statements such as DELETE, UPDATE, INSERT but not ALTER.

Sample code as below-

SqlParser.Config config = SqlParser.config()
                                                            .withParserFactory(SqlDdlParserImpl.FACTORY)
                                                            .withConformance(SqlConformanceEnum.STRICT_2003);
SqlParser parser = SqlParser.create("alter table tab1 drop column col1", config);
SqlNode node = parser.parse();


________________________________
From: Jacques Nadeau <ja...@apache.org>
Sent: Thursday, January 6, 2022 11:19 PM
To: dev@calcite.apache.org <de...@calcite.apache.org>
Subject: Re: Parsing ALTER TABLE Statements

I believe this is a feature that is off by default. Try creating your
parser with an alternative parser factory. I think it is something like
this:

SqlParser.Config.DEFAULT.withParserFactory(SqlDdlParserImpl.FACTORY)

On Thu, Jan 6, 2022 at 6:10 AM Yogendra Sharma <sy...@live.com> wrote:

> Wondering why does calcite DDL parser fail to parse ALTER TABLE stayements?
>
> In the code I see that we support ALTER SESSION and ALTER SYSTEM but not
> ALTER Table.
>
> -Yogi
>
>
>
> Get Outlook for Android<https://aka.ms/ghei36>
>

Re: Parsing ALTER TABLE Statements

Posted by Jacques Nadeau <ja...@apache.org>.
I believe this is a feature that is off by default. Try creating your
parser with an alternative parser factory. I think it is something like
this:

SqlParser.Config.DEFAULT.withParserFactory(SqlDdlParserImpl.FACTORY)

On Thu, Jan 6, 2022 at 6:10 AM Yogendra Sharma <sy...@live.com> wrote:

> Wondering why does calcite DDL parser fail to parse ALTER TABLE stayements?
>
> In the code I see that we support ALTER SESSION and ALTER SYSTEM but not
> ALTER Table.
>
> -Yogi
>
>
>
> Get Outlook for Android<https://aka.ms/ghei36>
>