[
https://issues.apache.org/jira/browse/DRILL-4525?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15210396#comment-15210396
]
ASF GitHub Bot commented on DRILL-4525:
---------------------------------------
Github user jinfengni commented on the pull request:
https://github.com/apache/drill/pull/439#issuecomment-200883747
Looks like the root cause of the problem is Calcite does not allow the
comparison of Date and Timestamp.
{code}
select CAST('1990-01-01' AS DATE) < CAST('2001-01-01' AS TIMESTAMP) FROM
(VALUES(1, 2)) AS T(A,B);
Mar 24, 2016 8:15:53 AM
org.apache.calcite.sql.validate.SqlValidatorException <init>
SEVERE: org.apache.calcite.sql.validate.SqlValidatorException: Cannot apply
'<' to arguments of type '<DATE> < <TIMESTAMP(0)>'. Supported form(s):
'<COMPARABLE_TYPE> < <COMPARABLE_TYPE>'
{code}
Postgres, on the country, supports date vs timestamp compare, through
implicit cast.
{code}
select CAST('1990-01-01' AS DATE) < CAST('2001-01-01' AS TIMESTAMP) FROM
(VALUES(1, 2)) AS T(A,B);
?column?
----------
t
(1 row)
{code}
I looked through SQL standard, and could not find the rules for the
implicit cast, which means different system could choose it's own
interpretation. (In other words, it's hard to argue what Calcite is doing is
not right)
What Sean is trying to do with his proposal is to replace Calcite's between
operator with Drill's between operator, so that the checkOperand will use
Drill's rule.
> Query with BETWEEN clause on Date and Timestamp values fails with Validation
> Error
> ----------------------------------------------------------------------------------
>
> Key: DRILL-4525
> URL: https://issues.apache.org/jira/browse/DRILL-4525
> Project: Apache Drill
> Issue Type: Bug
> Components: Query Planning & Optimization
> Reporter: Abhishek Girish
> Assignee: Sean Hsuan-Yi Chu
> Priority: Critical
>
> Query: (simplified variant of TPC-DS Query37)
> {code}
> SELECT
> *
> FROM
> date_dim
> WHERE
> d_date BETWEEN Cast('1999-03-06' AS DATE) AND (
> Cast('1999-03-06' AS DATE) + INTERVAL '60' day)
> LIMIT 10;
> {code}
> Error:
> {code}
> Error: VALIDATION ERROR: From line 6, column 8 to line 7, column 64: Cannot
> apply 'BETWEEN ASYMMETRIC' to arguments of type '<ANY> BETWEEN ASYMMETRIC
> <DATE> AND <TIMESTAMP(0)>'. Supported form(s): '<COMPARABLE_TYPE> BETWEEN
> <COMPARABLE_TYPE> AND <COMPARABLE_TYPE>'
> SQL Query null
> [Error Id: 223fb37c-f561-4a37-9283-871dc6f4d6d0 on abhi2:31010]
> (state=,code=0)
> {code}
> This is a regression from 1.6.0.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)