You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by 黄大仙 <ha...@qq.com> on 2017/05/09 04:01:46 UTC

How to implement custom sql dialect without modify calcite-core?

Hi everybody:


I want implement some custom features which shouldn't place in calcite-core ,for example, add a special TableOverOpt grammar. I must modify the following files:
  1. copy and modify core/src/main/codegen/templates/parser.jj
  2. add my own config.fmpp
  3. add SqlTableOverOpt.java/LogicalTableOverOpt.java to the calcite-core
  4. modify SqlToRelConverter.java SqlValidatorImpl in the calcite-core
  5. implement a PhysicalPlan like other adapters.


I found there is a way to implement CalcitePrepareImpl to avoid modify calcite-core in step 3,4. but it looks I should copy a lot of codes in org.apache.calcite.jdbc.* and org.apache.calcite.prepare.*


In the step 1,2 I can inject the parserFactory class in configs.
Is there any easy way to custom SqlToRelConverter SqlValidatorImpl and other calcite components?



Thanks in advance, hamsn

Re: How to implement custom sql dialect without modify calcite-core?

Posted by Julian Hyde <jh...@apache.org>.
See how Phoenix does it:
https://insight.io/github.com/apache/phoenix/blob/calcite/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java

It's definitely not as easy as we'd like it to be.
https://issues.apache.org/jira/browse/CALCITE-1525 would improve
things, I think.

By the way, your LogicalTableOverOpt relational operator is kind of
similar to our Chi operator. It converts a stream into a relation by
"integrating over time" and just like in calculus, you could have an
integral between -inf and +inf, or a definite integral between T1 and
T2, or a time-varying integral between now - 1 hour and now. So,
"relation OVER window" is just one form of that.

On Tue, May 9, 2017 at 7:52 PM, hamsn <ha...@qq.com> wrote:
> demo code:
> https://gist.github.com/drougon/af5dfa221511a07dc7d00454c4be796c
>
>
> Or maybe extend the code in core/src/test/java/org/apache/calcite/sql/parser/parserextensiontesting/ to include validator extensions as well?
>
> --
> Do you mean extend the generated code? parserextensiontesting directory contains  ExtensionSqlParserTest/SqlCreateTable/SqlUploadJarNode.
>
>
> ------------------ Original ------------------
> From:  "Julian Hyde";<jh...@apache.org>;
> Send time: Wednesday, May 10, 2017 5:56 AM
> To: "dev"<de...@calcite.apache.org>;
>
> Subject:  Re: How to implement custom sql dialect without modify calcite-core?
>
>
>
> I thought it was possible to create sub-classes or alternative implementations. You shouldn’t need to copy a lot of code.
>
> Can you share the code you’re trying to write?
>
> Or maybe extend the code in core/src/test/java/org/apache/calcite/sql/parser/parserextensiontesting/ to include validator extensions as well?
>
>> On May 8, 2017, at 9:01 PM, 黄大仙 <ha...@qq.com> wrote:
>>
>> Hi everybody:
>>
>>
>> I want implement some custom features which shouldn't place in calcite-core ,for example, add a special TableOverOpt grammar. I must modify the following files:
>>  1. copy and modify core/src/main/codegen/templates/parser.jj
>>  2. add my own config.fmpp
>>  3. add SqlTableOverOpt.java/LogicalTableOverOpt.java to the calcite-core
>>  4. modify SqlToRelConverter.java SqlValidatorImpl in the calcite-core
>>  5. implement a PhysicalPlan like other adapters.
>>
>>
>> I found there is a way to implement CalcitePrepareImpl to avoid modify calcite-core in step 3,4. but it looks I should copy a lot of codes in org.apache.calcite.jdbc.* and org.apache.calcite.prepare.*
>>
>>
>> In the step 1,2 I can inject the parserFactory class in configs.
>> Is there any easy way to custom SqlToRelConverter SqlValidatorImpl and other calcite components?
>>
>>
>>
>> Thanks in advance, hamsn

Re: How to implement custom sql dialect without modify calcite-core?

Posted by hamsn <ha...@qq.com>.
demo code:
https://gist.github.com/drougon/af5dfa221511a07dc7d00454c4be796c


Or maybe extend the code in core/src/test/java/org/apache/calcite/sql/parser/parserextensiontesting/ to include validator extensions as well?

--
Do you mean extend the generated code? parserextensiontesting directory contains  ExtensionSqlParserTest/SqlCreateTable/SqlUploadJarNode.


------------------ Original ------------------
From:  "Julian Hyde";<jh...@apache.org>;
Send time: Wednesday, May 10, 2017 5:56 AM
To: "dev"<de...@calcite.apache.org>; 

Subject:  Re: How to implement custom sql dialect without modify calcite-core?



I thought it was possible to create sub-classes or alternative implementations. You shouldn’t need to copy a lot of code.

Can you share the code you’re trying to write?

Or maybe extend the code in core/src/test/java/org/apache/calcite/sql/parser/parserextensiontesting/ to include validator extensions as well?

> On May 8, 2017, at 9:01 PM, 黄大仙 <ha...@qq.com> wrote:
> 
> Hi everybody:
> 
> 
> I want implement some custom features which shouldn't place in calcite-core ,for example, add a special TableOverOpt grammar. I must modify the following files:
>  1. copy and modify core/src/main/codegen/templates/parser.jj
>  2. add my own config.fmpp
>  3. add SqlTableOverOpt.java/LogicalTableOverOpt.java to the calcite-core
>  4. modify SqlToRelConverter.java SqlValidatorImpl in the calcite-core
>  5. implement a PhysicalPlan like other adapters.
> 
> 
> I found there is a way to implement CalcitePrepareImpl to avoid modify calcite-core in step 3,4. but it looks I should copy a lot of codes in org.apache.calcite.jdbc.* and org.apache.calcite.prepare.*
> 
> 
> In the step 1,2 I can inject the parserFactory class in configs.
> Is there any easy way to custom SqlToRelConverter SqlValidatorImpl and other calcite components?
> 
> 
> 
> Thanks in advance, hamsn

Re: How to implement custom sql dialect without modify calcite-core?

Posted by Julian Hyde <jh...@apache.org>.
I thought it was possible to create sub-classes or alternative implementations. You shouldn’t need to copy a lot of code.

Can you share the code you’re trying to write?

Or maybe extend the code in core/src/test/java/org/apache/calcite/sql/parser/parserextensiontesting/ to include validator extensions as well?

> On May 8, 2017, at 9:01 PM, 黄大仙 <ha...@qq.com> wrote:
> 
> Hi everybody:
> 
> 
> I want implement some custom features which shouldn't place in calcite-core ,for example, add a special TableOverOpt grammar. I must modify the following files:
>  1. copy and modify core/src/main/codegen/templates/parser.jj
>  2. add my own config.fmpp
>  3. add SqlTableOverOpt.java/LogicalTableOverOpt.java to the calcite-core
>  4. modify SqlToRelConverter.java SqlValidatorImpl in the calcite-core
>  5. implement a PhysicalPlan like other adapters.
> 
> 
> I found there is a way to implement CalcitePrepareImpl to avoid modify calcite-core in step 3,4. but it looks I should copy a lot of codes in org.apache.calcite.jdbc.* and org.apache.calcite.prepare.*
> 
> 
> In the step 1,2 I can inject the parserFactory class in configs.
> Is there any easy way to custom SqlToRelConverter SqlValidatorImpl and other calcite components?
> 
> 
> 
> Thanks in advance, hamsn