use of org.apache.phoenix.parse.CastParseNode in project phoenix by apache.
the class ExpressionCompiler method visitLeave.
@Override
public Expression visitLeave(CastParseNode node, List<Expression> children) throws SQLException {
ParseNode childNode = node.getChildren().get(0);
PDataType targetDataType = node.getDataType();
Expression childExpr = children.get(0);
PDataType fromDataType = childExpr.getDataType();
if (childNode instanceof BindParseNode) {
context.getBindManager().addParamMetaData((BindParseNode) childNode, childExpr);
}
Expression expr = childExpr;
if (fromDataType != null) {
/*
* IndexStatementRewriter creates a CAST parse node when rewriting the query to use
* indexed columns. Without this check present we wrongly and unnecessarily
* end up creating a RoundExpression.
*/
if (context.getCurrentTable().getTable().getType() != PTableType.INDEX) {
expr = convertToRoundExpressionIfNeeded(fromDataType, targetDataType, children);
}
}
boolean rowKeyOrderOptimizable = context.getCurrentTable().getTable().rowKeyOrderOptimizable();
return wrapGroupByExpression(CoerceExpression.create(expr, targetDataType, SortOrder.getDefault(), expr.getMaxLength(), rowKeyOrderOptimizable));
}
Aggregations