[fix](array_apply) pick array apply fix (#39328)
## Proposed changes backport: https://github.com/apache/doris/pull/39105 Issue Number: close #xxx <!--Describe your changes.-->
This commit is contained in:
@ -173,48 +173,51 @@ private:
|
||||
}
|
||||
|
||||
// need exception safety
|
||||
#define APPLY_ALL_TYPES(src_column, src_offsets, OP, cmp, dst) \
|
||||
do { \
|
||||
WhichDataType which(remove_nullable(nested_type)); \
|
||||
if (which.is_uint8()) { \
|
||||
*dst = _apply_internal<UInt8, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_int8()) { \
|
||||
*dst = _apply_internal<Int8, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_int16()) { \
|
||||
*dst = _apply_internal<Int16, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_int32()) { \
|
||||
*dst = _apply_internal<Int32, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_int64()) { \
|
||||
*dst = _apply_internal<Int64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_int128()) { \
|
||||
*dst = _apply_internal<Int128, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_float32()) { \
|
||||
*dst = _apply_internal<Float32, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_float64()) { \
|
||||
*dst = _apply_internal<Float64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_date()) { \
|
||||
*dst = _apply_internal<Int64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_date_time()) { \
|
||||
*dst = _apply_internal<Int64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_date_v2()) { \
|
||||
*dst = _apply_internal<UInt32, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_date_time_v2()) { \
|
||||
*dst = _apply_internal<UInt64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_date_time_v2()) { \
|
||||
*dst = _apply_internal<UInt64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_decimal32()) { \
|
||||
*dst = _apply_internal<Decimal32, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_decimal64()) { \
|
||||
*dst = _apply_internal<Decimal64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_decimal128v2()) { \
|
||||
*dst = _apply_internal<Decimal128V2, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_decimal128v3()) { \
|
||||
*dst = _apply_internal<Decimal128V3, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_decimal256()) { \
|
||||
*dst = _apply_internal<Decimal256, OP>(src_column, src_offsets, cmp); \
|
||||
} else { \
|
||||
LOG(FATAL) << "unsupported type " << nested_type->get_name(); \
|
||||
} \
|
||||
#define APPLY_ALL_TYPES(src_column, src_offsets, OP, cmp, dst) \
|
||||
do { \
|
||||
WhichDataType which(remove_nullable(nested_type)); \
|
||||
if (which.is_uint8()) { \
|
||||
*dst = _apply_internal<UInt8, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_int8()) { \
|
||||
*dst = _apply_internal<Int8, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_int16()) { \
|
||||
*dst = _apply_internal<Int16, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_int32()) { \
|
||||
*dst = _apply_internal<Int32, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_int64()) { \
|
||||
*dst = _apply_internal<Int64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_int128()) { \
|
||||
*dst = _apply_internal<Int128, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_float32()) { \
|
||||
*dst = _apply_internal<Float32, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_float64()) { \
|
||||
*dst = _apply_internal<Float64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_date()) { \
|
||||
*dst = _apply_internal<Int64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_date_time()) { \
|
||||
*dst = _apply_internal<Int64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_date_v2()) { \
|
||||
*dst = _apply_internal<UInt32, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_date_time_v2()) { \
|
||||
*dst = _apply_internal<UInt64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_date_time_v2()) { \
|
||||
*dst = _apply_internal<UInt64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_decimal32()) { \
|
||||
*dst = _apply_internal<Decimal32, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_decimal64()) { \
|
||||
*dst = _apply_internal<Decimal64, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_decimal128v2()) { \
|
||||
*dst = _apply_internal<Decimal128V2, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_decimal128v3()) { \
|
||||
*dst = _apply_internal<Decimal128V3, OP>(src_column, src_offsets, cmp); \
|
||||
} else if (which.is_decimal256()) { \
|
||||
*dst = _apply_internal<Decimal256, OP>(src_column, src_offsets, cmp); \
|
||||
} else { \
|
||||
throw doris::Exception(ErrorCode::INVALID_ARGUMENT, \
|
||||
"array_apply only accept array with nested type which is " \
|
||||
"uint/int/decimal/float/date but got : " + \
|
||||
nested_type->get_name()); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// need exception safety
|
||||
|
||||
@ -26,6 +26,7 @@ import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral;
|
||||
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
|
||||
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
|
||||
import org.apache.doris.nereids.types.ArrayType;
|
||||
import org.apache.doris.nereids.types.DataType;
|
||||
import org.apache.doris.nereids.types.VarcharType;
|
||||
import org.apache.doris.nereids.types.coercion.AnyDataType;
|
||||
import org.apache.doris.nereids.types.coercion.FollowToAnyDataType;
|
||||
@ -67,6 +68,15 @@ public class ArrayApply extends ScalarFunction
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkLegalityBeforeTypeCoercion() {
|
||||
DataType argType = ((ArrayType) child(0).getDataType()).getItemType();
|
||||
if (!(argType.isIntegralType() || argType.isFloatLikeType() || argType.isDecimalLikeType()
|
||||
|| argType.isDateLikeType() || argType.isBooleanType())) {
|
||||
throw new AnalysisException("array_apply does not support type: " + toSql());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayApply withChildren(List<Expression> children) {
|
||||
Preconditions.checkArgument(children.size() == 3,
|
||||
|
||||
@ -14448,6 +14448,9 @@ true
|
||||
-- !array_empty_fe --
|
||||
[]
|
||||
|
||||
-- !array_empty_be --
|
||||
-- !array_empty_fe --
|
||||
[]
|
||||
|
||||
-- !sql_array_map --
|
||||
[1, 1, 1, 1]
|
||||
|
||||
|
||||
@ -977,3 +977,6 @@ _
|
||||
-- !sql --
|
||||
[11.9999, 34.0000]
|
||||
|
||||
-- !sql_array_map --
|
||||
[1, 1, 1, 1]
|
||||
|
||||
|
||||
@ -1308,4 +1308,17 @@ suite("nereids_scalar_fn_Array") {
|
||||
logger.info(exception.message)
|
||||
}
|
||||
}
|
||||
|
||||
// with array empty
|
||||
qt_array_empty_fe """select array()"""
|
||||
|
||||
// array_map with string is can be succeed
|
||||
qt_sql_array_map """select array_map(x->x!='', split_by_string('amory,is,better,committing', ','))"""
|
||||
|
||||
// array_apply with string should be failed
|
||||
test {
|
||||
sql """select array_apply(split_by_string("amory,is,better,committing", ","), '!=', '');"""
|
||||
exception("errCode = 2")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -410,4 +410,13 @@ suite("test_array_functions_by_literal") {
|
||||
} catch (Exception ex) {
|
||||
assert("${ex}".contains("errCode = 2, detailMessage = No matching function with signature: array_intersect"))
|
||||
}
|
||||
|
||||
// array_map with string is can be succeed
|
||||
qt_sql_array_map """ select array_map(x->x!='', split_by_string('amory,is,better,committing', ',')) """
|
||||
|
||||
// array_apply with string should be failed
|
||||
test {
|
||||
sql """select array_apply(split_by_string("amory,is,better,committing", ","), '!=', '');"""
|
||||
exception("No matching function")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user