[feature-wip](array-type) add ArrayType support for FeFunctions (#10041)
FEFunctionSignature do not support ArrayType as args, then following SQL failed: `> select array_contains([1,2,3], 1);` ERROR 1105 (HY000): errCode = 2, detailMessage = Unexpected exception: org.apache.doris.catalog.ArrayType cannot be cast to org.apache.doris.catalog.ScalarType
This commit is contained in:
@ -93,12 +93,8 @@ public enum ExpressionFunctions {
|
||||
return constExpr;
|
||||
}
|
||||
|
||||
List<ScalarType> argTypes = new ArrayList<>();
|
||||
for (Type type : fn.getArgs()) {
|
||||
argTypes.add((ScalarType) type);
|
||||
}
|
||||
FEFunctionSignature signature = new FEFunctionSignature(fn.functionName(),
|
||||
argTypes.toArray(new ScalarType[argTypes.size()]), fn.getReturnType());
|
||||
fn.getArgs(), fn.getReturnType());
|
||||
FEFunctionInvoker invoker = getFunction(signature);
|
||||
if (invoker != null) {
|
||||
try {
|
||||
@ -124,8 +120,8 @@ public enum ExpressionFunctions {
|
||||
continue;
|
||||
}
|
||||
|
||||
ScalarType[] argTypes1 = invoker.getSignature().getArgTypes();
|
||||
ScalarType[] argTypes2 = signature.getArgTypes();
|
||||
Type[] argTypes1 = invoker.getSignature().getArgTypes();
|
||||
Type[] argTypes2 = signature.getArgTypes();
|
||||
|
||||
if (!Arrays.equals(argTypes1, argTypes2)) {
|
||||
continue;
|
||||
@ -161,12 +157,12 @@ public enum ExpressionFunctions {
|
||||
if (annotation != null) {
|
||||
String name = annotation.name();
|
||||
Type returnType = Type.fromPrimitiveType(PrimitiveType.valueOf(annotation.returnType()));
|
||||
List<ScalarType> argTypes = new ArrayList<>();
|
||||
List<Type> argTypes = new ArrayList<>();
|
||||
for (String type : annotation.argTypes()) {
|
||||
argTypes.add(ScalarType.createType(type));
|
||||
}
|
||||
FEFunctionSignature signature = new FEFunctionSignature(name,
|
||||
argTypes.toArray(new ScalarType[argTypes.size()]), returnType);
|
||||
argTypes.toArray(new Type[argTypes.size()]), returnType);
|
||||
mapBuilder.put(name, new FEFunctionInvoker(method, signature));
|
||||
}
|
||||
}
|
||||
@ -229,7 +225,7 @@ public enum ExpressionFunctions {
|
||||
throw new AnalysisException("Function's args doesn't match.");
|
||||
}
|
||||
|
||||
final ScalarType argType = signature.getArgTypes()[typeIndex];
|
||||
final Type argType = signature.getArgTypes()[typeIndex];
|
||||
LiteralExpr[] exprs;
|
||||
if (argType.isStringType()) {
|
||||
exprs = new StringLiteral[args.size()];
|
||||
@ -259,16 +255,16 @@ public enum ExpressionFunctions {
|
||||
|
||||
public static class FEFunctionSignature {
|
||||
private final String name;
|
||||
private final ScalarType[] argTypes;
|
||||
private final Type[] argTypes;
|
||||
private final Type returnType;
|
||||
|
||||
public FEFunctionSignature(String name, ScalarType[] argTypes, Type returnType) {
|
||||
public FEFunctionSignature(String name, Type[] argTypes, Type returnType) {
|
||||
this.name = name;
|
||||
this.argTypes = argTypes;
|
||||
this.returnType = returnType;
|
||||
}
|
||||
|
||||
public ScalarType[] getArgTypes() {
|
||||
public Type[] getArgTypes() {
|
||||
return argTypes;
|
||||
}
|
||||
|
||||
|
||||
@ -113,7 +113,7 @@ public class ArrayType extends Type {
|
||||
return false;
|
||||
}
|
||||
ArrayType otherArrayType = (ArrayType) other;
|
||||
return otherArrayType.itemType.equals(itemType) && otherArrayType.containsNull == containsNull;
|
||||
return otherArrayType.itemType.equals(itemType);
|
||||
}
|
||||
|
||||
public static boolean canCastTo(ArrayType type, ArrayType targetType) {
|
||||
|
||||
@ -562,8 +562,19 @@ public class FEFunctions {
|
||||
}
|
||||
|
||||
@FEFunctionList({
|
||||
@FEFunction(name = "array", argTypes = {"BOOLEAN"}, returnType = "ARRAY"),
|
||||
@FEFunction(name = "array", argTypes = {"TINYINT"}, returnType = "ARRAY"),
|
||||
@FEFunction(name = "array", argTypes = {"SMALLINT"}, returnType = "ARRAY"),
|
||||
@FEFunction(name = "array", argTypes = {"INT"}, returnType = "ARRAY"),
|
||||
@FEFunction(name = "array", argTypes = {"VARCHAR"}, returnType = "ARRAY")
|
||||
@FEFunction(name = "array", argTypes = {"BIGINT"}, returnType = "ARRAY"),
|
||||
@FEFunction(name = "array", argTypes = {"LARGEINT"}, returnType = "ARRAY"),
|
||||
@FEFunction(name = "array", argTypes = {"DATETIME"}, returnType = "ARRAY"),
|
||||
@FEFunction(name = "array", argTypes = {"DATE"}, returnType = "ARRAY"),
|
||||
@FEFunction(name = "array", argTypes = {"FLOAT"}, returnType = "ARRAY"),
|
||||
@FEFunction(name = "array", argTypes = {"DOUBLE"}, returnType = "ARRAY"),
|
||||
@FEFunction(name = "array", argTypes = {"DECIMALV2"}, returnType = "ARRAY"),
|
||||
@FEFunction(name = "array", argTypes = {"VARCHAR"}, returnType = "ARRAY"),
|
||||
@FEFunction(name = "array", argTypes = {"STRING"}, returnType = "ARRAY")
|
||||
})
|
||||
public static ArrayLiteral array(LiteralExpr... exprs) throws AnalysisException {
|
||||
return new ArrayLiteral(exprs);
|
||||
|
||||
Reference in New Issue
Block a user