Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.30.0
Description
Babel parser can't parse DATEADD(S, ...). The parser should allow custom time unit abbreviations in FLOOR, CEIL, EXTRACT, DATE_PART, DATEADD, DATEDIFF and similar functions.
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.
FrameworkConfig config = Frameworks.newConfigBuilder().build(); Planner planner = Frameworks.getPlanner(config); System.out.println(planner.parse("SELECT DATEDIFF(HOUR, NOW(), NOW())"));
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)
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?
Attachments
Issue Links
- is duplicated by
-
CALCITE-5222 Support more EXTRACT field values (or allow arbitrary in parse?)
- Closed
- is related to
-
CALCITE-2496 EXTRACT function: MILLI/MICRO/NANOSECOND parts of a DATE must be zero
- Closed
-
CALCITE-3218 Syntax error while parsing DATEADD function (which is valid on Redshift)
- Closed
-
CALCITE-5155 Custom time frames
- Closed
- links to