You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Laksh Singla <la...@imply.io> on 2022/01/04 13:08:00 UTC

Help with extending the Calcite grammar

Hi,
I am relatively a newcomer to the Calcite project and was exploring ways to
extend Calcite's grammar. I have gone through the provided test cases and
some examples where the grammar is modified.

I was facing difficulty in adding custom clauses to the end of a
pre-existing grammar rule.
In particular, implementing the grammar with the following form:
SELECT * FROM TABLE *WITH CONTEXT1=FLAG1, CONTEXT2=FLAG2*.

In the FTL templates, I created a custom rule like
SelectCustom() -> Select() <WITH> <CONTEXT1>=flag1, <CONTEXT2>=flag2

The issue I am facing is that since JavaCC doesn't support backtracking,
any rule which begins with the "SELECT" keyword is getting evaluated as my
custom rule, and normal statements (like SELECT * FROM TABLE) are not
getting parsed, since they don't contain the optional clause.

Would it be correct to modify the rule as follows, such that the custom
rule encapsulates both the cases, but overshadows the original SqlSelect()
rule (in SqlStmt())?
SelectCustom() ->
    Select() [<WITH> <CONTEXT1>=flag1, <CONTEXT2>=flag2].

Can there be a better/cleaner way to achieve the task, or is there any
provision made in the Calcite framework or JavaCC, which is better suited
for doing the same?

Thanks & Regards
Laksh