Steve Carlin has posted comments on this change. ( http://gerrit.cloudera.org:8080/24048 )
Change subject: IMPALA-14639: Calcite planner should not allow date cast to int ...................................................................... Patch Set 1: (1 comment) http://gerrit.cloudera.org:8080/#/c/24048/1//COMMIT_MSG Commit Message: http://gerrit.cloudera.org:8080/#/c/24048/1//COMMIT_MSG@12 PS1, Line 12: select cast(date '2000-12-21' as int); > AFAIK, according to the SQL standards casting a DATE to INT is not allowed, There are 2 types of CASTs that we have in our codebase: 1) There are implicit casts which are created when we need to coerce variables to fit into Impala functions. One example of this is the "INT =(INT, INT)" function used for let's say "where tinyint_col = smallint_col". In this situation, an implicit case is needed to use the INT "=" function. 2) There are explicit casts defined by the use, as in the above SQL in this comment: "select cast(date '2000-12-21" as int) For the original Impala planner, this is separated by a flag within CastExpr. For Calcite, however, these are separated by the type of operator. For implicit casts: These are sometimes generated by Calcite within rules and therefore we use the normal Calcite CAST operator. For explicit casts: These are known at parsing/validation time. So to keep these separate and known throughout the compilation process, an EXPLICIT_CAST operator has been created. I've provided all of this explanation as a setup to answer your question: Because this is an EXPLICIT_CAST, we are not relying on any Calcite mechanism for validation because it is not using the same operator. At validation time, it just plainly looks at the return type. But eventually, it does dip into the CastExpr.analyze() code and that's where it determines that this type of cast is illegal. -- To view, visit http://gerrit.cloudera.org:8080/24048 To unsubscribe, visit http://gerrit.cloudera.org:8080/settings Gerrit-Project: Impala-ASF Gerrit-Branch: master Gerrit-MessageType: comment Gerrit-Change-Id: Icad76e6c1db489ecdfa620109baa47232331a42d Gerrit-Change-Number: 24048 Gerrit-PatchSet: 1 Gerrit-Owner: Steve Carlin <[email protected]> Gerrit-Reviewer: Aman Sinha <[email protected]> Gerrit-Reviewer: Impala Public Jenkins <[email protected]> Gerrit-Reviewer: Joe McDonnell <[email protected]> Gerrit-Reviewer: Michael Smith <[email protected]> Gerrit-Reviewer: Steve Carlin <[email protected]> Gerrit-Comment-Date: Wed, 04 Mar 2026 17:37:50 +0000 Gerrit-HasComments: Yes
