This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new 9bb6ff4ea2f branch-4.0: [chore](literal) remove some useless code
#57487 (#57542)
9bb6ff4ea2f is described below
commit 9bb6ff4ea2fbcb8384e39765a8cc9475323ccdb4
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Nov 3 12:07:15 2025 +0800
branch-4.0: [chore](literal) remove some useless code #57487 (#57542)
Cherry-picked from #57487
Co-authored-by: morrySnow <[email protected]>
---
.../org/apache/doris/analysis/ArithmeticExpr.java | 151 ---------------------
.../java/org/apache/doris/analysis/CastExpr.java | 5 -
.../org/apache/doris/analysis/DecimalLiteral.java | 27 ----
.../main/java/org/apache/doris/analysis/Expr.java | 40 ------
.../org/apache/doris/analysis/FloatLiteral.java | 7 -
.../java/org/apache/doris/analysis/IntLiteral.java | 7 -
.../org/apache/doris/analysis/LargeIntLiteral.java | 6 -
.../org/apache/doris/analysis/LiteralExpr.java | 44 ------
.../org/apache/doris/analysis/PlaceHolderExpr.java | 7 -
9 files changed, 294 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java
index 9a85409f151..d4213855f99 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java
@@ -24,12 +24,9 @@ import org.apache.doris.catalog.Function;
import org.apache.doris.catalog.Function.NullableMode;
import org.apache.doris.catalog.FunctionSet;
import org.apache.doris.catalog.ScalarFunction;
-import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.TableIf.TableType;
import org.apache.doris.catalog.Type;
-import org.apache.doris.common.AnalysisException;
-import org.apache.doris.common.Config;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
import org.apache.doris.thrift.TExprOpcode;
@@ -297,156 +294,8 @@ public class ArithmeticExpr extends Expr {
return ((ArithmeticExpr) obj).opcode == opcode;
}
- /**
- * Convert integer type to decimal type.
- */
- public static Type convertIntToDecimalV3Type(Type type) throws
AnalysisException {
- if (type.isLargeIntType()) {
- return
ScalarType.createDecimalV3Type(ScalarType.MAX_DECIMAL128_PRECISION, 0);
- } else if (type.isBigIntType()) {
- return
ScalarType.createDecimalV3Type(ScalarType.MAX_DECIMAL64_PRECISION, 0);
- } else if (type.isInteger32Type()) {
- return
ScalarType.createDecimalV3Type(ScalarType.MAX_DECIMAL32_PRECISION, 0);
- } else {
- Preconditions.checkState(false,
- "Implicit converting to decimal for arithmetic operations
only support integer");
- return Type.INVALID;
- }
- }
-
- public static Type convertDecimalV2ToDecimalV3Type(ScalarType type) {
- return ScalarType.createDecimalV3Type(type.decimalPrecision(),
type.decimalScale());
- }
-
- private void analyzeDecimalV3Op(Type t1, Type t2) throws AnalysisException
{
- Type t1TargetType = t1;
- Type t2TargetType = t2;
- switch (op) {
- case MULTIPLY:
- case ADD:
- case SUBTRACT:
- case MOD:
- case DIVIDE:
- if (t1.isFloatingPointType() || t2.isFloatingPointType()) {
- type = castBinaryOp(ScalarType.DOUBLE);
- break;
- }
- if (t1.isFixedPointType()) {
- t1TargetType = convertIntToDecimalV3Type(t1);
- castChild(t1TargetType, 0);
- }
- if (t2.isFixedPointType()) {
- t2TargetType = convertIntToDecimalV3Type(t2);
- castChild(t2TargetType, 1);
- }
- if (t1.isDecimalV2()) {
- t1TargetType =
convertDecimalV2ToDecimalV3Type((ScalarType) t1);
- castChild(t1TargetType, 0);
- }
- if (t2.isDecimalV2()) {
- t2TargetType =
convertDecimalV2ToDecimalV3Type((ScalarType) t2);
- castChild(t2TargetType, 1);
- }
- final int t1Precision = ((ScalarType)
t1TargetType).getScalarPrecision();
- final int t2Precision = ((ScalarType)
t2TargetType).getScalarPrecision();
- final int t1Scale = ((ScalarType)
t1TargetType).getScalarScale();
- final int t2Scale = ((ScalarType)
t2TargetType).getScalarScale();
- int precision = Math.max(t1Precision, t2Precision);
- int scale = Math.max(t1Scale, t2Scale);
-
- // operands: DECIMALV3(precision1, scale1) and
DECIMALV3(precision2, scale2)
- // we use widthOfIntPart to present width of integer part.
- int widthOfIntPart1 = t1Precision - t1Scale;
- int widthOfIntPart2 = t2Precision - t2Scale;
- if (op == Operator.MULTIPLY) {
- // target type: DECIMALV3(precision1 + precision2, scale1
+ scale2)
- scale = t1Scale + t2Scale;
- precision = t1Precision + t2Precision;
- } else if (op == Operator.DIVIDE) {
- precision = t1TargetType.getPrecision() + t2Scale +
Config.div_precision_increment;
- scale = t1Scale + Config.div_precision_increment;
- } else if (op == Operator.ADD || op == Operator.SUBTRACT) {
- // target type: DECIMALV3(max(widthOfIntPart1,
widthOfIntPart2) + max(scale1, scale2) + 1,
- // max(scale1, scale2))
- scale = Math.max(t1Scale, t2Scale);
- precision = Math.max(widthOfIntPart1, widthOfIntPart2) +
scale + 1;
- } else {
- scale = Math.max(t1Scale, t2Scale);
- precision = widthOfIntPart2 + scale;
- }
- if (precision > ScalarType.MAX_DECIMAL128_PRECISION) {
- // TODO(gabriel): if precision is bigger than 38?
- precision = ScalarType.MAX_DECIMAL128_PRECISION;
- }
- if (precision < scale) {
- type = castBinaryOp(Type.DOUBLE);
- break;
- }
- type = ScalarType.createDecimalV3Type(precision, scale);
- if (op == Operator.ADD || op == Operator.SUBTRACT) {
- if (((ScalarType) type).getScalarScale() != ((ScalarType)
children.get(0).type).getScalarScale()) {
- castChild(type, 0);
- }
- if (((ScalarType) type).getScalarScale() != ((ScalarType)
children.get(1).type).getScalarScale()) {
- castChild(type, 1);
- }
- } else if (op == Operator.DIVIDE &&
(t1TargetType.isDecimalV3())) {
- int leftPrecision = t1Precision + t2Scale +
Config.div_precision_increment;
- int leftScale = t1Scale + t2Scale +
Config.div_precision_increment;
- if (leftPrecision < leftScale || leftPrecision >
ScalarType.MAX_DECIMAL128_PRECISION) {
- type = castBinaryOp(Type.DOUBLE);
- break;
- }
- Expr child = getChild(0);
- if (child instanceof DecimalLiteral) {
- DecimalLiteral literalChild = (DecimalLiteral) child;
- Expr newChild = literalChild
-
.castToDecimalV3ByDivde(ScalarType.createDecimalV3Type(leftPrecision,
leftScale));
- setChild(0, newChild);
- } else {
-
castChild(ScalarType.createDecimalV3Type(leftPrecision, leftScale), 0);
- }
- } else if (op == Operator.MOD) {
- // TODO use max int part + max scale of two operands as
result type
- // because BE require the result and operands types are
the exact the same decimalv3 type
- precision = Math.max(widthOfIntPart1, widthOfIntPart2) +
scale;
- if (precision > ScalarType.MAX_DECIMAL128_PRECISION) {
- type = castBinaryOp(Type.DOUBLE);
- } else {
- type = ScalarType.createDecimalV3Type(precision,
scale);
- castChild(type, 0);
- castChild(type, 1);
- }
- }
- break;
- case INT_DIVIDE:
- case BITAND:
- case BITOR:
- case BITXOR:
- type = castBinaryOp(Type.BIGINT);
- break;
- case BITNOT:
- case FACTORIAL:
- break;
- default:
- Preconditions.checkState(false,
- "Unknown arithmetic operation " + op + " in: " +
this.toSql());
- break;
- }
- }
-
@Override
public int hashCode() {
return 31 * super.hashCode() + Objects.hashCode(op);
}
-
- @Override
- protected void compactForLiteral(Type type) throws AnalysisException {
- super.compactForLiteral(type);
- Type t1 = getChild(0).getType();
- Type t2 = getChild(1).getType();
- if (t1.isDecimalV3() || t2.isDecimalV3()) {
- analyzeDecimalV3Op(t1, t2);
- }
- }
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
index e25864a8795..90b552b1355 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
@@ -394,9 +394,4 @@ public class CastExpr extends Expr {
public void setNotFold(boolean notFold) {
this.notFold = notFold;
}
-
- @Override
- protected void compactForLiteral(Type type) {
- // do nothing
- }
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/DecimalLiteral.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/DecimalLiteral.java
index 6205f08d43a..dd5d65cf52e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DecimalLiteral.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DecimalLiteral.java
@@ -25,7 +25,6 @@ import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.FormatOptions;
-import org.apache.doris.common.NotImplementedException;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.thrift.TDecimalLiteral;
import org.apache.doris.thrift.TExprNode;
@@ -302,25 +301,6 @@ public class DecimalLiteral extends NumericLiteralExpr {
msg.decimal_literal = new TDecimalLiteral(value.toPlainString());
}
- @Override
- public void swapSign() throws NotImplementedException {
- // swapping sign does not change the type
- value = value.negate();
- }
-
- @Override
- protected void compactForLiteral(Type type) throws AnalysisException {
- if (type.isDecimalV3()) {
- int scale = Math.max(this.value.scale(), ((ScalarType)
type).decimalScale());
- int integerPart = Math.max(this.value.precision() -
this.value.scale(),
- type.getPrecision() - ((ScalarType) type).decimalScale());
- this.type = ScalarType.createDecimalV3Type(integerPart + scale,
scale);
- BigDecimal adjustedValue = value.scale() < 0 ? value
- : value.setScale(scale, RoundingMode.HALF_UP);
- this.value = Objects.requireNonNull(adjustedValue);
- }
- }
-
// To be compatible with OLAP, only need 9 digits.
// Note: the return value is negative if value is negative.
public int getFracValue() {
@@ -363,13 +343,6 @@ public class DecimalLiteral extends NumericLiteralExpr {
return super.uncheckedCastTo(targetType);
}
- public Expr castToDecimalV3ByDivde(Type targetType) {
- // onlye use in DecimalLiteral divide DecimalV3
- CastExpr expr = new CastExpr(targetType, this);
- expr.setNotFold(true);
- return expr;
- }
-
@Override
public int hashCode() {
return 31 * super.hashCode() + Objects.hashCode(value);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
index 9f6a2c706d1..1565779e689 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
@@ -858,12 +858,6 @@ public abstract class Expr extends TreeNode<Expr>
implements Cloneable, ExprStat
return true;
}
- protected void compactForLiteral(Type type) throws AnalysisException {
- for (Expr expr : children) {
- expr.compactForLiteral(type);
- }
- }
-
/**
* Checks validity of cast, and
* calls uncheckedCastTo() to
@@ -1008,40 +1002,6 @@ public abstract class Expr extends TreeNode<Expr>
implements Cloneable, ExprStat
}
}
- /**
- * Cast the operands of a binary operation as necessary,
- * give their compatible type.
- * String literals are converted first, to enable casting of the
- * the other non-string operand.
- *
- * @param compatibleType
- * @return The possibly changed compatibleType
- * (if a string literal forced casting the other operand)
- */
- public Type castBinaryOp(Type compatibleType) throws AnalysisException {
- Preconditions.checkState(this instanceof BinaryPredicate || this
instanceof ArithmeticExpr);
- Type t1 = getChild(0).getType();
- Type t2 = getChild(1).getType();
- // add operand casts
- Preconditions.checkState(compatibleType.isValid());
- if (t1.isDecimalV3() || t1.isDecimalV2()) {
- if (!t1.equals(compatibleType)) {
- castChild(compatibleType, 0);
- }
- } else if (t1.getPrimitiveType() != compatibleType.getPrimitiveType())
{
- castChild(compatibleType, 0);
- }
-
- if (t2.isDecimalV3() || t2.isDecimalV2()) {
- if (!t2.equals(compatibleType)) {
- castChild(compatibleType, 1);
- }
- } else if (t2.getPrimitiveType() != compatibleType.getPrimitiveType())
{
- castChild(compatibleType, 1);
- }
- return compatibleType;
- }
-
@Override
public String toString() {
return MoreObjects.toStringHelper(this.getClass()).add("id",
id).add("type", type).add("sel",
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java
index 23da538bcbd..91e7925de6c 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java
@@ -24,7 +24,6 @@ import org.apache.doris.catalog.TableIf.TableType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
-import org.apache.doris.common.NotImplementedException;
import
org.apache.doris.nereids.trees.expressions.literal.format.FractionalFormat;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
@@ -237,12 +236,6 @@ public class FloatLiteral extends NumericLiteralExpr {
return this;
}
- @Override
- public void swapSign() throws NotImplementedException {
- // swapping sign does not change the type
- value = -value;
- }
-
@Override
public int hashCode() {
return 31 * super.hashCode() + Double.hashCode(value);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/IntLiteral.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/IntLiteral.java
index 853825d8b38..6677934f937 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/IntLiteral.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/IntLiteral.java
@@ -22,7 +22,6 @@ import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.TableIf.TableType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
-import org.apache.doris.common.NotImplementedException;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
@@ -311,12 +310,6 @@ public class IntLiteral extends NumericLiteralExpr {
return super.uncheckedCastTo(targetType);
}
- @Override
- public void swapSign() throws NotImplementedException {
- // swapping sign does not change the type
- value = -value;
- }
-
@Override
public int hashCode() {
return 31 * super.hashCode() + Long.hashCode(value);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/LargeIntLiteral.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/LargeIntLiteral.java
index 562881708a7..3a2d7f153fe 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/LargeIntLiteral.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/LargeIntLiteral.java
@@ -235,12 +235,6 @@ public class LargeIntLiteral extends NumericLiteralExpr {
return super.uncheckedCastTo(targetType);
}
- @Override
- public void swapSign() {
- // swapping sign does not change the type
- value = value.negate();
- }
-
@Override
public int hashCode() {
return 31 * super.hashCode() + Objects.hashCode(value);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java
index 396d0235d41..8aa3e45bbe3 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java
@@ -26,7 +26,6 @@ import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
-import org.apache.doris.common.NotImplementedException;
import org.apache.doris.mysql.MysqlProto;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
@@ -111,43 +110,6 @@ public abstract class LiteralExpr extends Expr implements
Comparable<LiteralExpr
return literalExpr;
}
- /**
- * Init LiteralExpr's Type information
- * only use in rewrite alias function
- * @param expr
- * @return
- * @throws AnalysisException
- */
- public static LiteralExpr init(LiteralExpr expr) throws AnalysisException {
- Preconditions.checkArgument(expr.getType().equals(Type.INVALID));
- String value = expr.getStringValue();
- LiteralExpr literalExpr = null;
- if (expr instanceof NullLiteral) {
- literalExpr = new NullLiteral();
- } else if (expr instanceof BoolLiteral) {
- literalExpr = new BoolLiteral(value);
- } else if (expr instanceof IntLiteral) {
- literalExpr = new IntLiteral(Long.parseLong(value));
- } else if (expr instanceof LargeIntLiteral) {
- literalExpr = new LargeIntLiteral(value);
- } else if (expr instanceof FloatLiteral) {
- literalExpr = new FloatLiteral(value);
- } else if (expr instanceof DecimalLiteral) {
- literalExpr = new DecimalLiteral(value);
- } else if (expr instanceof StringLiteral) {
- literalExpr = new StringLiteral(value);
- } else if (expr instanceof JsonLiteral) {
- literalExpr = new JsonLiteral(value);
- } else if (expr instanceof DateLiteral) {
- literalExpr = new DateLiteral(value, expr.getType());
- } else {
- throw new AnalysisException("Type[" + expr.getType().toSql() + "]
not supported.");
- }
-
- Preconditions.checkNotNull(literalExpr);
- return literalExpr;
- }
-
public Expr convertTo(Type targetType) throws AnalysisException {
Preconditions.checkArgument(!targetType.equals(Type.INVALID));
if (this instanceof NullLiteral) {
@@ -259,12 +221,6 @@ public abstract class LiteralExpr extends Expr implements
Comparable<LiteralExpr
return " ? ";
}
- // Swaps the sign of numeric literals.
- // Throws for non-numeric literals.
- public void swapSign() throws NotImplementedException {
- throw new NotImplementedException("swapSign() only implemented for
numeric" + "literals");
- }
-
@Override
public boolean equals(Object obj) {
if (this == obj) {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/PlaceHolderExpr.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/PlaceHolderExpr.java
index a8de460fae9..f4a261816bb 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/PlaceHolderExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/PlaceHolderExpr.java
@@ -24,7 +24,6 @@ import org.apache.doris.catalog.TableIf.TableType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FormatOptions;
-import org.apache.doris.common.NotImplementedException;
import org.apache.doris.thrift.TExprNode;
import com.google.common.base.Preconditions;
@@ -130,12 +129,6 @@ public class PlaceHolderExpr extends LiteralExpr {
return "?";
}
- // Swaps the sign of numeric literals.
- // Throws for non-numeric literals.
- public void swapSign() throws NotImplementedException {
- Preconditions.checkState(false, "should not implement this in derived
class. " + this.type.toSql());
- }
-
@Override
public boolean supportSerializable() {
return false;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]