morrySnow commented on code in PR #32225: URL: https://github.com/apache/doris/pull/32225#discussion_r1524339901
########## fe/fe-core/src/main/java/org/apache/doris/nereids/CascadesContext.java: ########## @@ -127,6 +128,11 @@ public class CascadesContext implements ScheduleContext { private boolean isLeadingDisableJoinReorder = false; + // keep track of which element_at function's level + // e.g. element_at(element_at(v, 'repo'), 'name') level 1 + // element_at(v, 'repo') level 2 + private int currentElementAtLevel = 0; Review Comment: how to support more than one element at in plan? ########## fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java: ########## @@ -492,17 +492,27 @@ private Type getCmpType() throws AnalysisException { } } - if ((t1.isDecimalV3Type() && !t2.isStringType() && !t2.isFloatingPointType()) - || (t2.isDecimalV3Type() && !t1.isStringType() && !t1.isFloatingPointType())) { + if ((t1.isDecimalV3Type() && !t2.isStringType() && !t2.isFloatingPointType() && !t2.isVariantType()) + || (t2.isDecimalV3Type() && !t1.isStringType() && !t1.isFloatingPointType() && !t1.isVariantType())) { return Type.getAssignmentCompatibleType(getChild(0).getType(), getChild(1).getType(), false, SessionVariable.getEnableDecimal256()); } // Variant can be implicit cast to numeric type and string type at present if (t1.isVariantType() && (t2.isNumericType() || t2.isStringType())) { + if (t2.isDecimalV2Type() || t2.isDecimalV3Type()) { + // TODO support decimal + throw new org.apache.doris.nereids.exceptions.AnalysisException("Not support cast to decimal type" + + " at present, maybe explicitly cast variant to double"); + } return Type.fromPrimitiveType(t2); } if (t2.isVariantType() && (t1.isNumericType() || t1.isStringType())) { + if (t1.isDecimalV2Type() || t1.isDecimalV3Type()) { + // TODO support decimal + throw new org.apache.doris.nereids.exceptions.AnalysisException("Not support cast to decimal type" + + " at present, maybe explicitly cast variant to double"); + } Review Comment: implicit cast to double is better? ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FunctionBinder.java: ########## @@ -188,6 +191,15 @@ public Expression visitUnboundFunction(UnboundFunction unboundFunction, Expressi // so wrap COUNT with Nvl to ensure it's result is 0 instead of null to get the correct result boundFunction = new Nvl(boundFunction, new BigIntLiteral(0)); } + if (context.cascadesContext.currentElementAtLevel() == 1 Review Comment: it is hard to understand, please add enough comment to explain the if condition ########## fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java: ########## @@ -492,17 +492,27 @@ private Type getCmpType() throws AnalysisException { } } - if ((t1.isDecimalV3Type() && !t2.isStringType() && !t2.isFloatingPointType()) - || (t2.isDecimalV3Type() && !t1.isStringType() && !t1.isFloatingPointType())) { + if ((t1.isDecimalV3Type() && !t2.isStringType() && !t2.isFloatingPointType() && !t2.isVariantType()) + || (t2.isDecimalV3Type() && !t1.isStringType() && !t1.isFloatingPointType() && !t1.isVariantType())) { return Type.getAssignmentCompatibleType(getChild(0).getType(), getChild(1).getType(), false, SessionVariable.getEnableDecimal256()); } // Variant can be implicit cast to numeric type and string type at present if (t1.isVariantType() && (t2.isNumericType() || t2.isStringType())) { + if (t2.isDecimalV2Type() || t2.isDecimalV3Type()) { + // TODO support decimal + throw new org.apache.doris.nereids.exceptions.AnalysisException("Not support cast to decimal type" Review Comment: use `org.apache.doris.common.AnalysisException` here ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FunctionBinder.java: ########## @@ -141,6 +141,9 @@ private UnboundFunction bindHighOrderFunction(UnboundFunction unboundFunction, E @Override public Expression visitUnboundFunction(UnboundFunction unboundFunction, ExpressionRewriteContext context) { + if (unboundFunction.getName().equalsIgnoreCase("element_at")) { Review Comment: it could not work correctly when user craate a UDF named element_at under database. ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FunctionBinder.java: ########## @@ -188,6 +191,15 @@ public Expression visitUnboundFunction(UnboundFunction unboundFunction, Expressi // so wrap COUNT with Nvl to ensure it's result is 0 instead of null to get the correct result boundFunction = new Nvl(boundFunction, new BigIntLiteral(0)); } + if (context.cascadesContext.currentElementAtLevel() == 1 + && PushDownToProjectionFunction.validToPushDown(boundFunction)) { + // Only rewrite the top level of PushDownToProjectionFunction, otherwise invalid slot will be generated + context.cascadesContext.resetCurrentElementAtLevel(); Review Comment: does it could work well for expression such as `element_at(v1, cast(element_at(v2, 'a') as int) + cast(element_at(v3, 'b') as bigint))`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org