This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-1.1-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit 065745b1d1ba56b6ab40858b4901fc6f8e8bb6d8 Author: Gabriel <gabrielleeb...@gmail.com> AuthorDate: Thu Sep 15 08:44:18 2022 +0800 [Bug](lead) fix wrong child expression of `lead` function (#12587) --- .../org/apache/doris/analysis/AnalyticExpr.java | 5 ++++- .../java/org/apache/doris/analysis/CastExpr.java | 5 +++-- .../main/java/org/apache/doris/catalog/Type.java | 23 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyticExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyticExpr.java index a8adc13940..3fd841fff2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyticExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyticExpr.java @@ -574,7 +574,10 @@ public class AnalyticExpr extends Expr { Type type = getFnCall().getChildren().get(2).getType(); try { - getFnCall().uncheckedCastChild(getFnCall().getChildren().get(0).getType(), 2); + if (!Type.matchExactType(getFnCall().getChildren().get(0).getType(), + getFnCall().getChildren().get(2).getType())) { + getFnCall().uncheckedCastChild(getFnCall().getChildren().get(0).getType(), 2); + } } catch (Exception e) { LOG.warn("" , e); throw new AnalysisException("Convert type error in offset fn(default value); old_type=" 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 261c1cf89a..58062f1d5f 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 @@ -239,8 +239,9 @@ public class CastExpr extends Expr { Type childType = getChild(0).getType(); // this cast may result in loss of precision, but the user requested it - if (childType.matchesType(type)) { - noOp = true; + noOp = Type.matchExactType(childType, type); + + if (noOp) { return; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java index 01245d3529..9e3d55f2e0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java @@ -1193,4 +1193,27 @@ public abstract class Type { return this.getPrimitiveType().getOlapColumnIndexSize(); } } + + // Whether `type1` matches the exact type of `type2`. + public static boolean matchExactType(Type type1, Type type2) { + if (type1.matchesType(type2)) { + if (PrimitiveType.typeWithPrecision.contains(type2.getPrimitiveType())) { + // For types which has precision and scale, we also need to check quality between precisions and scales + if ((((ScalarType) type2).decimalPrecision() + == ((ScalarType) type1).decimalPrecision()) && (((ScalarType) type2).decimalScale() + == ((ScalarType) type1).decimalScale())) { + return true; + } + } else if (type2.isArrayType()) { + // For types array, we also need to check contains null for case like + // cast(array<not_null(int)> as array<int>) + if (((ArrayType) type2).getContainsNull() == ((ArrayType) type1).getContainsNull()) { + return true; + } + } else { + return true; + } + } + return false; + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org