[
https://issues.apache.org/jira/browse/IMPALA-11049?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17454655#comment-17454655
]
Sheng Wang commented on IMPALA-11049:
-------------------------------------
Hi [~stigahuang] and [~boroknagyz], this bug is quite simple to fix, just add
type check is ok like this:
{code:java}
// old
return castExpr.getType().matchesType(child.getType())? child : castExpr
// new
return castExpr.getType() != Type.INVALID && child.getType() != Type.INVALID &&
castExpr.getType().matchesType(child.getType())? child : castExpr;
{code}
This is due to 'orderByElements_' rewrite in SelectStmt.rewriteExprs():
{code:java}
if (orderByElements_ != null) {
for (OrderByElement orderByElem: orderByElements_) {
orderByElem.setExpr(rewriteCheckOrdinalResult(rewriter,
orderByElem.getExpr()));
}
}
{code}
When analyze SelectStmt by SelectAnalyzer.analyze(), Impala construct
'sortInfo_' in QueryStmt.createSortInfo(). But exprs in 'orderByElements_' is
not been analyzed, and this casued a wrong rewrite in 'SimplifyCastExprRule',
since 'd_date_sk' and 'cast(d_date_sk AS string)' are both invalid type.
I read the code, find that 'orderByElements_' not been used after construct
'sortInfo_' in QueryStmt.createSortInfo(). So maybe we should rewrite
'sortInfo_' instead of 'orderByElements_' in SelectStmt.rewriteExprs().
Besides, I think rewrite operation should execute on analyzed exprs, but
'orderByElements_' is not been analyzed, how do you think?
> Order by clause contains cast expr execute failed after
> 'SimplifyCastExprRule' rewrite
> --------------------------------------------------------------------------------------
>
> Key: IMPALA-11049
> URL: https://issues.apache.org/jira/browse/IMPALA-11049
> Project: IMPALA
> Issue Type: Bug
> Components: Frontend
> Affects Versions: Impala 4.1.0
> Reporter: Sheng Wang
> Assignee: Sheng Wang
> Priority: Major
>
> When add new rewrite rule 'SimplifyCastExprRule' in IMPALA-10836, this query
> will execute failed:
> {code:java}
> explain
> SELECT month(to_timestamp(cast(d_date_sk AS string),'yyyy-MM-dd')) aa
> FROM date_dim
> GROUP BY month(to_timestamp(cast(d_date_sk AS string),'yyyy-MM-dd'))
> ORDER BY month(to_timestamp(cast(d_date_sk AS string),'yyyy-MM-dd')) LIMIT 10;
> {code}
> The exception is:
> {code:java}
> ERROR: AnalysisException: No matching function with signature:
> to_timestamp(INT, STRING).
> {code}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]