[ 
https://issues.apache.org/jira/browse/CALCITE-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17534933#comment-17534933
 ] 

Jiajun Xie edited comment on CALCITE-5143 at 5/11/22 2:41 PM:
--------------------------------------------------------------

[~komamitsu]  Sorry, I have no idea. I think we need to change code in babel 
module.

FYI: I check all 
[abbreviations|https://docs.microsoft.com/en-us/sql/t-sql/functions/dateadd-transact-sql?view=sql-server-ver15#arguments]
 in SQL Server. I don't plan to add *dayofyear* and *weekday* because they 
don't belong to  calcite-avatica TimeUnit.
||_datepart_||Abbreviations||
|*year*|{*}yy{*}, *yyyy*|
|*quarter*|{*}qq{*}, *q*|
|*month*|{*}mm{*}, *m*|
|-*dayofyear*-|-{*}dy{*}, *y*-|
|*day*|{*}dd{*}, *d*|
|*week*|{*}wk{*}, *ww*|
|-*weekday*-|-{*}dw{*}, *w*-|
|*hour*|*hh*|
|*minute*|{*}mi{*}, *n*|
|*second*|{*}ss{*}, *s*|
|*millisecond*|*ms*|
|*microsecond*|*mcs*|
|*nanosecond*|*ns*|


was (Author: jiajunbernoulli):
[~komamitsu]  Sorry, I have no idea. I think we need to change code in babel 
module.

FYI: I check all abbreviations in SQL Server. I don't plan to add *dayofyear* 
and *weekday* because they don't belong to  calcite-avatica TimeUnit.
||_datepart_||Abbreviations||
|*year*|{*}yy{*}, *yyyy*|
|*quarter*|{*}qq{*}, *q*|
|*month*|{*}mm{*}, *m*|
|-*dayofyear*-|-{*}dy{*}, *y*-|
|*day*|{*}dd{*}, *d*|
|*week*|{*}wk{*}, *ww*|
|-*weekday*-|-{*}dw{*}, *w*-|
|*hour*|*hh*|
|*minute*|{*}mi{*}, *n*|
|*second*|{*}ss{*}, *s*|
|*millisecond*|*ms*|
|*microsecond*|*mcs*|
|*nanosecond*|*ns*|

> Planner#parse fails to parse a function when HOUR is passed as an argument
> --------------------------------------------------------------------------
>
>                 Key: CALCITE-5143
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5143
>             Project: Calcite
>          Issue Type: Bug
>          Components: babel
>    Affects Versions: 1.30.0
>            Reporter: Mitsunori Komatsu
>            Priority: Major
>
> I'm trying to parse and rewrite some SQL dialects including SQL Server which 
> supports some functions that receive HOUR as an argument using. But Calcite's 
> Planner#parse can't handle this kind of SQL.
> {code:java}
> FrameworkConfig config = Frameworks.newConfigBuilder().build();
> Planner planner = Frameworks.getPlanner(config);
> System.out.println(planner.parse("SELECT DATEDIFF(HOUR, NOW(), NOW())")); 
> {code}
> {code:java}
> Exception in thread "main" org.apache.calcite.sql.parser.SqlParseException: 
> Incorrect syntax near the keyword 'HOUR' at line 2, column 21.
> Was expecting one of:
>     "ALL" ...
>     "ARRAY" ...
>     "CASE" ...
>    :
>     "GROUPING" ...
>     "HOUR" ...
>     "HOUR" "(" ...
>     "*" ...
>     ")" ...
>     
>     at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.convertException(SqlParserImpl.java:389)
>     at 
> org.apache.calcite.sql.parser.impl.SqlParserImpl.normalizeException(SqlParserImpl.java:153)
>     at 
> org.apache.calcite.sql.parser.SqlParser.handleException(SqlParser.java:145)
>     at org.apache.calcite.sql.parser.SqlParser.parseQuery(SqlParser.java:160)
>     at org.apache.calcite.sql.parser.SqlParser.parseStmt(SqlParser.java:185)
>     at org.apache.calcite.prepare.PlannerImpl.parse(PlannerImpl.java:214)
>     at org.apache.calcite.tools.Planner.parse(Planner.java:50) {code}
> This issue happens with other date/time keyword-ish ones like YEAR.
> I guess it happens because HOUR and YEAR are reserved keywords.
> Is this an expected behavior? If so, is there any workaround?



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to