morrySnow commented on code in PR #64335:
URL: https://github.com/apache/doris/pull/64335#discussion_r3385290435
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SimplifyAggGroupBy.java:
##########
@@ -81,7 +85,75 @@ protected static boolean
isBinaryArithmeticSlot(TreeNode<Expression> expr) {
if (!supportedFunctions.contains(expr.getClass())) {
return false;
}
- return ExpressionUtils.isSlotOrCastOnSlot(expr.child(0)).isPresent()
&& expr.child(1) instanceof Literal
- ||
ExpressionUtils.isSlotOrCastOnSlot(expr.child(1)).isPresent() && expr.child(0)
instanceof Literal;
+
+ // Multiply / Divide: both sides must not be float/double
+ if (expr instanceof Multiply || expr instanceof Divide) {
+ if (expr.child(0).getDataType().isFloatLikeType()
+ || expr.child(1).getDataType().isFloatLikeType()) {
+ return false;
+ }
+ }
+
+ Expression slotExpr;
+ Literal literal;
+ if (expr.child(0) instanceof Literal) {
+ literal = (Literal) expr.child(0);
+ slotExpr = expr.child(1);
+ } else if (expr.child(1) instanceof Literal) {
+ literal = (Literal) expr.child(1);
+ slotExpr = expr.child(0);
+ } else {
+ return false;
+ }
+
+ if (!canExtractSlot(slotExpr)) {
+ return false;
+ }
+
+ return checkLiteral(expr, literal);
+ }
+
+ @VisibleForTesting
+ protected static boolean checkLiteral(Expression expr, Literal literal) {
+ if (literal.isNullLiteral()) {
+ return false;
+ }
+ if (expr instanceof Multiply || expr instanceof Divide) {
+ if (literal.isZero()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @VisibleForTesting
+ protected static boolean canExtractSlot(Expression expr) {
+ while (expr instanceof Cast) {
+ Cast cast = (Cast) expr;
+ Expression inner = cast.child();
+ if (!isLosslessWidening(inner.getDataType(), cast.getDataType())) {
+ return false;
+ }
+ expr = inner;
+ }
+ return expr instanceof Slot;
+ }
+
+ @VisibleForTesting
+ protected static boolean isLosslessWidening(DataType src, DataType tgt) {
Review Comment:
in #64080, DataType add a new interface `isInjectiveCastTo`, i think we
could reuse it here
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]