[Bug](lead) fix wrong child expression of lead function (#12587)
This commit is contained in:
@ -691,7 +691,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="
|
||||
|
||||
@ -20,7 +20,6 @@
|
||||
|
||||
package org.apache.doris.analysis;
|
||||
|
||||
import org.apache.doris.catalog.ArrayType;
|
||||
import org.apache.doris.catalog.Env;
|
||||
import org.apache.doris.catalog.Function;
|
||||
import org.apache.doris.catalog.FunctionSet;
|
||||
@ -269,24 +268,7 @@ 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)) {
|
||||
if (PrimitiveType.typeWithPrecision.contains(type.getPrimitiveType())) {
|
||||
// For types which has precision and scale, we also need to check quality between precisions and scales
|
||||
if ((((ScalarType) type).decimalPrecision()
|
||||
== ((ScalarType) childType).decimalPrecision()) && (((ScalarType) type).decimalScale()
|
||||
== ((ScalarType) childType).decimalScale())) {
|
||||
noOp = true;
|
||||
}
|
||||
} else if (type.isArrayType()) {
|
||||
// For types array, we also need to check contains null for case like
|
||||
// cast(array<not_null(int)> as array<int>)
|
||||
if (((ArrayType) type).getContainsNull() == ((ArrayType) childType).getContainsNull()) {
|
||||
noOp = true;
|
||||
}
|
||||
} else {
|
||||
noOp = true;
|
||||
}
|
||||
}
|
||||
noOp = Type.matchExactType(childType, type);
|
||||
|
||||
if (noOp) {
|
||||
return;
|
||||
|
||||
@ -1637,4 +1637,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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user