[
https://issues.apache.org/jira/browse/CALCITE-2282?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16825653#comment-16825653
]
Lai Zhou edited comment on CALCITE-2282 at 4/25/19 2:35 AM:
------------------------------------------------------------
[~danny0405], it's the way how I override the built-in operators:
In Parser.jj
{code:java}
| <LIKE> { op = SqlStdOperatorTable.LIKE; }
| <SIMILAR> <TO> { op = SqlStdOperatorTable.SIMILAR_TO; }
| <RLIKE> { op = HiveSqlOperatorTable.RLIKE; }
| <REGEXP> { op = HiveSqlOperatorTable.REGEXP; } )
{code}
{code:java}
| <PLUS> { return SqlStdOperatorTable.PLUS; }
| <MINUS> { return SqlStdOperatorTable.MINUS; }
| <STAR> { return HiveSqlOperatorTable.MULTIPLY; }
| <SLASH> { return HiveSqlOperatorTable.DIVIDE; }{code}
The default DIVIDE operator in SqlStdOperatorTable is not ok for real business.
Consider the follow sql:
select 2/5 , the result is 0. But we expect 0.4.
[~julianhyde], Now the only way to custom the DIVIDE operator is to rewrite the
Parser.jj.
I didn't find the way as [~zhztheplayer] said to custom static built-in
operators without changing the parser for this use case.
was (Author: hhlai1990):
[~danny0405], it's the way how I override the built-in operators:
In Parser.jj
{code:java}
| <LIKE> { op = SqlStdOperatorTable.LIKE; }
| <SIMILAR> <TO> { op = SqlStdOperatorTable.SIMILAR_TO; }
| <RLIKE> { op = HiveSqlOperatorTable.RLIKE; }
| <REGEXP> { op = HiveSqlOperatorTable.REGEXP; } )
{code}
{code:java}
| <PLUS> { return SqlStdOperatorTable.PLUS; }
| <MINUS> { return SqlStdOperatorTable.MINUS; }
| <STAR> { return HiveSqlOperatorTable.MULTIPLY; }
| <SLASH> { return HiveSqlOperatorTable.DIVIDE; }{code}
The default DIVIDE operator in SqlStdOperatorTable is not ok for real business.
Consider the follow sql:
select 2/5 , the result is 0. But we expect 0.4.
[~julianhyde], Now the only way to custom the DIVIDE operator is to rewrite the
Parser.jj.
I didn't find the way as [~zhztheplayer] said to to custom static built-in
operators without changing the parser for this use case.
> Allow OperatorTable to be pluggable in the parser
> -------------------------------------------------
>
> Key: CALCITE-2282
> URL: https://issues.apache.org/jira/browse/CALCITE-2282
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: Sudheesh Katkam
> Priority: Major
> Attachments: CALCITE-2282.patch.txt
>
>
> SqlAbstractParserImpl [hardcodes OperatorTable to
> SqlStdOperatorTable|https://github.com/apache/calcite/blob/8327e674e7f0a768d124fa37fd75cda4b8a35bb6/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java#L334|https://github.com/apache/calcite/blob/8327e674e7f0a768d124fa37fd75cda4b8a35bb6/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java#L334].
> Make this pluggable via a protected method.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)