From b670dd0db7b2bc9d9e8aff67265c994158b52f94 Mon Sep 17 00:00:00 2001 From: morrySnow <101034200+morrySnow@users.noreply.github.com> Date: Tue, 22 Aug 2023 09:47:55 +0800 Subject: [PATCH] [feature](Nereids) support array type (#22851) FEATURE: 1. enable array type in Nereids 2. support generice on function signature 3. support array and map type in type coercion and type check 4. add element_at and element_slice syntax in Nereids parser REFACTOR: 1. remove AbstractDataType BUG FIX: 1. remove FROM from nonReserved keyword list TODO: 1. support lambda expression 2. use Nereids' way do function type coercion 3. use castIfnotSame when do implict cast on BoundFunction 4. let AnyDataType type coercion do same thing as function type coercion 5. add below array function - array_apply - array_concat - array_filter - array_sortby - array_exists - array_first_index - array_last_index - array_count - array_shuffle shuffle - array_pushfront - array_pushback - array_repeat - array_zip - reverse - concat_ws - split_by_string - explode - bitmap_from_array - bitmap_to_array - multi_search_all_positions - multi_match_any - tokenize --- .../org/apache/doris/catalog/ScalarType.java | 4 +- .../org/apache/doris/nereids/DorisLexer.g4 | 2 +- .../org/apache/doris/nereids/DorisParser.g4 | 33 +- .../apache/doris/analysis/ArrayLiteral.java | 7 + .../org/apache/doris/analysis/CastExpr.java | 2 +- .../doris/catalog/BuiltinScalarFunctions.java | 23 +- .../doris/catalog/FunctionSignature.java | 47 +- .../glue/translator/ExpressionTranslator.java | 6 +- .../doris/nereids/jobs/executor/Rewriter.java | 3 +- .../nereids/parser/LogicalPlanBuilder.java | 61 ++- .../doris/nereids/parser/NereidsParser.java | 3 +- .../analysis/AvgDistinctToSumDivCount.java | 2 +- .../nereids/rules/analysis/BindSink.java | 80 +-- .../rules/expression/check/CheckCast.java | 27 +- .../expression/rules/FunctionBinder.java | 37 +- .../SimplifyArithmeticComparisonRule.java | 3 +- .../nereids/rules/rewrite/CheckDataTypes.java | 17 +- .../SelectMaterializedIndexWithAggregate.java | 1 - .../trees/expressions/BinaryArithmetic.java | 9 +- .../trees/expressions/BinaryOperator.java | 6 +- .../nereids/trees/expressions/BitNot.java | 3 +- .../nereids/trees/expressions/CaseWhen.java | 12 +- .../expressions/ComparisonPredicate.java | 20 +- .../trees/expressions/CompoundPredicate.java | 3 +- .../nereids/trees/expressions/EqualTo.java | 5 - .../nereids/trees/expressions/Expression.java | 87 ++-- .../trees/expressions/InPredicate.java | 13 + .../nereids/trees/expressions/Match.java | 7 +- .../doris/nereids/trees/expressions/Not.java | 5 +- .../expressions/TimestampArithmetic.java | 13 + .../trees/expressions/UnaryOperator.java | 6 +- .../nereids/trees/expressions/WhenClause.java | 7 +- .../ComputePrecisionForArrayItemAgg.java | 43 ++ .../functions/ComputeSignature.java | 35 +- .../functions/ComputeSignatureHelper.java | 200 ++++++- .../ExplicitlyCastableSignature.java | 20 +- .../functions/IdenticalSignature.java | 6 +- .../ImplicitlyCastableSignature.java | 31 +- .../functions/NullOrIdenticalSignature.java | 6 +- .../functions/SearchSignature.java | 28 +- .../expressions/functions/agg/AnyValue.java | 2 +- .../functions/agg/CollectList.java | 56 +- .../expressions/functions/agg/CollectSet.java | 56 +- .../expressions/functions/agg/Count.java | 2 +- .../functions/agg/GroupConcat.java | 4 +- .../expressions/functions/agg/MaxBy.java | 2 +- .../expressions/functions/agg/MinBy.java | 2 +- .../functions/agg/MultiDistinctCount.java | 2 +- .../agg/MultiDistinctGroupConcat.java | 12 +- .../trees/expressions/functions/agg/Ndv.java | 2 +- .../expressions/functions/agg/TopNArray.java | 71 +-- .../expressions/functions/scalar/Array.java | 85 +-- .../functions/scalar/ArrayAvg.java | 41 +- .../functions/scalar/ArrayCompact.java | 36 +- .../functions/scalar/ArrayContains.java | 40 +- .../{ArrayPopback.java => ArrayCumSum.java} | 41 +- .../functions/scalar/ArrayDistinct.java | 43 +- .../functions/scalar/ArrayEnumerate.java | 34 +- .../functions/scalar/ArrayExcept.java | 57 +- .../functions/scalar/ArrayIntersect.java | 57 +- .../functions/scalar/ArrayJoin.java | 84 +-- .../functions/scalar/ArrayMax.java | 36 +- .../functions/scalar/ArrayMin.java | 36 +- .../{ArraySize.java => ArrayPopBack.java} | 18 +- .../scalar/{Size.java => ArrayPopFront.java} | 18 +- .../functions/scalar/ArrayPosition.java | 37 +- .../functions/scalar/ArrayProduct.java | 12 +- .../functions/scalar/ArrayRemove.java | 52 +- .../functions/scalar/ArrayReverseSort.java | 69 +++ .../functions/scalar/ArraySlice.java | 74 +-- .../functions/scalar/ArraySort.java | 38 +- .../functions/scalar/ArraySum.java | 11 +- .../functions/scalar/ArrayUnion.java | 57 +- .../functions/scalar/ArrayWithConstant.java | 32 +- .../functions/scalar/ArraysOverlap.java | 54 +- .../functions/scalar/Cardinality.java | 3 +- .../scalar/CompatibleTypeArrayFunction.java | 65 --- .../functions/scalar/CountEqual.java | 37 +- .../functions/scalar/ElementAt.java | 42 +- .../functions/scalar/ElementExtract.java | 103 ---- .../functions/scalar/ElementSlice.java | 148 ------ .../expressions/functions/scalar/If.java | 65 +-- .../expressions/functions/scalar/Reverse.java | 31 +- .../functions/scalar/TimeDiff.java | 4 +- .../expressions/functions/table/Hdfs.java | 2 +- .../trees/expressions/functions/table/S3.java | 2 +- .../expressions/functions/udf/JavaUdaf.java | 7 +- .../expressions/functions/udf/JavaUdf.java | 3 +- .../functions/udf/JavaUdfBuilder.java | 3 +- .../expressions/literal/ArrayLiteral.java | 19 +- .../typecoercion/ExpectsInputTypes.java | 4 +- .../visitor/ScalarFunctionVisitor.java | 41 +- .../doris/nereids/types/AggStateType.java | 3 +- .../apache/doris/nereids/types/ArrayType.java | 7 +- .../doris/nereids/types/BigIntType.java | 3 +- .../doris/nereids/types/BitmapType.java | 3 +- .../apache/doris/nereids/types/CharType.java | 3 +- .../apache/doris/nereids/types/DataType.java | 121 ++--- .../doris/nereids/types/DateTimeType.java | 9 + .../doris/nereids/types/DateTimeV2Type.java | 5 +- .../apache/doris/nereids/types/DateType.java | 9 + .../doris/nereids/types/DecimalV2Type.java | 12 +- .../doris/nereids/types/DecimalV3Type.java | 4 +- .../doris/nereids/types/DoubleType.java | 3 +- .../apache/doris/nereids/types/FloatType.java | 3 +- .../apache/doris/nereids/types/HllType.java | 3 +- .../doris/nereids/types/IntegerType.java | 3 +- .../apache/doris/nereids/types/JsonType.java | 3 +- .../doris/nereids/types/LargeIntType.java | 3 +- .../apache/doris/nereids/types/MapType.java | 55 +- .../nereids/types/QuantileStateType.java | 3 +- .../doris/nereids/types/SmallIntType.java | 3 +- .../doris/nereids/types/StringType.java | 3 +- .../doris/nereids/types/StructType.java | 26 +- .../doris/nereids/types/TinyIntType.java | 3 +- .../doris/nereids/types/VarcharType.java | 3 +- .../types/coercion/AbstractDataType.java | 65 --- .../nereids/types/coercion/AnyDataType.java | 36 +- .../nereids/types/coercion/CharacterType.java | 2 +- .../types/coercion/FollowToAnyDataType.java | 69 +++ .../types/coercion/FollowToArgumentType.java | 18 +- .../types/coercion/FractionalType.java | 2 +- .../nereids/types/coercion/IntegralType.java | 2 +- .../nereids/types/coercion/NumericType.java | 2 +- .../doris/nereids/util/TypeCoercionUtils.java | 221 ++++++-- .../org/apache/doris/qe/StmtExecutor.java | 19 +- .../doris/nereids/UnsupportedTypeTest.java | 12 +- .../rules/analysis/GenerateFunction.java | 2 +- .../nereids/types/AbstractDataTypeTest.java | 492 ------------------ .../doris/nereids/types/DataTypeTest.java | 468 +++++++++++++++++ .../array_functions/test_array_functions.out | 2 +- .../test_array_functions_by_literal.out | 2 +- .../suites/nereids_arith_p0/bitmap.groovy | 4 +- .../except/test_analyzer_exception.groovy | 2 +- .../except/test_bound_exception.groovy | 12 +- .../insert_into_table/aggregate.groovy | 28 +- .../ddl/{arr_t.sql => map_t.sql} | 4 +- .../insert_into_table/duplicate.groovy | 28 +- .../nereids_p0/insert_into_table/load.groovy | 5 +- .../insert_into_table/no_partition.groovy | 82 +-- .../insert_into_table/unique.groovy | 56 +- .../insert_into_table/unsupport_type.groovy | 10 +- .../test_duplicate_name_in_view.groovy | 2 +- .../nereids_syntax_p0/advance_mv.groovy | 4 +- .../nereids_syntax_p0/bind_priority.groovy | 4 +- .../forbid_unexpected_type.groovy | 6 +- .../nereids_syntax_p0/grouping_sets.groovy | 4 +- .../sub_query_diff_old_optimize.groovy | 12 +- .../nereids_syntax_p0/system_var.groovy | 2 +- .../test_timestamp_arithmetic.groovy | 4 +- .../suites/point_query_p0/load.groovy | 3 + .../point_query_p0/test_point_query.groovy | 18 +- .../join/test_bitmap_filter_nereids.groovy | 2 +- .../test_aggregate_collect.groovy | 4 +- .../test_array_functions_by_literal.groovy | 9 +- 155 files changed, 2126 insertions(+), 2661 deletions(-) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputePrecisionForArrayItemAgg.java rename fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/{ArrayPopback.java => ArrayCumSum.java} (60%) rename fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/{ArraySize.java => ArrayPopBack.java} (78%) rename fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/{Size.java => ArrayPopFront.java} (78%) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayReverseSort.java delete mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CompatibleTypeArrayFunction.java delete mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementExtract.java delete mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementSlice.java delete mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/AbstractDataType.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/FollowToAnyDataType.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/nereids/types/AbstractDataTypeTest.java rename regression-test/suites/nereids_p0/insert_into_table/ddl/{arr_t.sql => map_t.sql} (68%) diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java index 17c8eca69c..a6d02219cb 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java +++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java @@ -272,9 +272,9 @@ public class ScalarType extends Type { return TIME; case "DECIMAL": case "DECIMALV2": - return (ScalarType) createDecimalType(); + return createDecimalType(); case "DECIMALV3": - return (ScalarType) createDecimalV3Type(); + return createDecimalV3Type(); case "LARGEINT": return LARGEINT; default: diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 index 2f23376d0a..9eb05c1230 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4 @@ -433,7 +433,7 @@ HINT_END: '*/'; ATSIGN: '@'; DOUBLEATSIGN: '@@'; -STRING +STRING_LITERAL : '\'' ( ~('\''|'\\') | ('\\' .) )* '\'' | '"' ( ~('"'|'\\') | ('\\' .) )* '"' | 'R\'' (~'\'')* '\'' diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 index e63d5d9f88..1348bb80e6 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 @@ -59,7 +59,7 @@ statement identifierOrText : errorCapturingIdentifier - | STRING + | STRING_LITERAL ; userIdentify @@ -366,10 +366,13 @@ primaryExpression | qualifiedName DOT ASTERISK #star | functionIdentifier LEFT_PAREN ((DISTINCT|ALL)? arguments+=expression (COMMA arguments+=expression)* (ORDER BY sortItem (COMMA sortItem)*)?)? RIGHT_PAREN - (OVER windowSpec)? #functionCall + (OVER windowSpec)? #functionCall + | value=primaryExpression LEFT_BRACKET index=valueExpression RIGHT_BRACKET #elementAt + | value=primaryExpression LEFT_BRACKET begin=valueExpression + COLON (end=valueExpression)? RIGHT_BRACKET #arraySlice | LEFT_PAREN query RIGHT_PAREN #subqueryExpression - | ATSIGN identifierOrText #userVariable - | DOUBLEATSIGN (kind=(GLOBAL | SESSION) DOT)? identifier #systemVariable + | ATSIGN identifierOrText #userVariable + | DOUBLEATSIGN (kind=(GLOBAL | SESSION) DOT)? identifier #systemVariable | identifier #columnReference | base=primaryExpression DOT fieldName=identifier #dereference | LEFT_PAREN expression RIGHT_PAREN #parenthesizedExpression @@ -425,10 +428,10 @@ specifiedPartition constant : NULL #nullLiteral | interval #intervalLiteral - | type=(DATE | DATEV2 | TIMESTAMP) STRING #typeConstructor + | type=(DATE | DATEV2 | TIMESTAMP) STRING_LITERAL #typeConstructor | number #numericLiteral | booleanValue #booleanLiteral - | STRING #stringLiteral + | STRING_LITERAL #stringLiteral ; comparisonOperator @@ -452,7 +455,23 @@ unitIdentifier ; dataType - : identifier (LEFT_PAREN (ASTERISK | INTEGER_VALUE (COMMA INTEGER_VALUE)*) RIGHT_PAREN)? #primitiveDataType + : complex=ARRAY LT dataType GT #complexDataType + | complex=MAP LT dataType COMMA dataType GT #complexDataType + | complex=STRUCT LT complexColTypeList GT #complexDataType + | identifier (LEFT_PAREN INTEGER_VALUE + (COMMA INTEGER_VALUE)* RIGHT_PAREN)? #primitiveDataType + ; + +complexColTypeList + : complexColType (COMMA complexColType)* + ; + +complexColType + : identifier COLON dataType commentSpec? + ; + +commentSpec + : COMMENT STRING_LITERAL ; // this rule is used for explicitly capturing wrong identifiers such as test-table, which should actually be `test-table` diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java index ffd8f8f0ba..b7d95af1dd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArrayLiteral.java @@ -30,6 +30,7 @@ import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class ArrayLiteral extends LiteralExpr { @@ -39,6 +40,12 @@ public class ArrayLiteral extends LiteralExpr { children = new ArrayList<>(); } + public ArrayLiteral(Type type, LiteralExpr... exprs) throws AnalysisException { + this.type = type; + children = new ArrayList<>(Arrays.asList(exprs)); + analysisDone(); + } + public ArrayLiteral(LiteralExpr... exprs) throws AnalysisException { Type itemType = Type.NULL; boolean containsNull = true; 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 cb78d78539..a7bf0d5bd9 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 @@ -275,7 +275,7 @@ public class CastExpr extends Expr { if (type.isArrayType()) { fn = ScalarFunction.createBuiltin(getFnName(Type.ARRAY), type, Function.NullableMode.ALWAYS_NULLABLE, - Lists.newArrayList(Type.VARCHAR), false, + Lists.newArrayList(getActualArgTypes(collectChildReturnTypes())[0]), false, "doris::CastFunctions::cast_to_array_val", null, null, true); } else if (type.isMapType()) { fn = ScalarFunction.createBuiltin(getFnName(Type.MAP), diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java index 9e2733f08f..c4a2e1faeb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java @@ -28,6 +28,7 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.Array; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayAvg; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayCompact; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayContains; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayCumSum; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayDifference; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayDistinct; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayEnumerate; @@ -36,12 +37,13 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayIntersec import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayJoin; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayMax; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayMin; -import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayPopback; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayPopBack; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayPopFront; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayPosition; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayProduct; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRange; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRemove; -import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySize; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayReverseSort; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySlice; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySort; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySum; @@ -123,8 +125,6 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.Dround; import org.apache.doris.nereids.trees.expressions.functions.scalar.Dsqrt; import org.apache.doris.nereids.trees.expressions.functions.scalar.E; import org.apache.doris.nereids.trees.expressions.functions.scalar.ElementAt; -import org.apache.doris.nereids.trees.expressions.functions.scalar.ElementExtract; -import org.apache.doris.nereids.trees.expressions.functions.scalar.ElementSlice; import org.apache.doris.nereids.trees.expressions.functions.scalar.Elt; import org.apache.doris.nereids.trees.expressions.functions.scalar.EndsWith; import org.apache.doris.nereids.trees.expressions.functions.scalar.EsQuery; @@ -259,7 +259,6 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.SecondsDiff; import org.apache.doris.nereids.trees.expressions.functions.scalar.SecondsSub; import org.apache.doris.nereids.trees.expressions.functions.scalar.Sign; import org.apache.doris.nereids.trees.expressions.functions.scalar.Sin; -import org.apache.doris.nereids.trees.expressions.functions.scalar.Size; import org.apache.doris.nereids.trees.expressions.functions.scalar.Sleep; import org.apache.doris.nereids.trees.expressions.functions.scalar.Sm3; import org.apache.doris.nereids.trees.expressions.functions.scalar.Sm3sum; @@ -365,6 +364,7 @@ public class BuiltinScalarFunctions implements FunctionHelper { scalar(ArrayAvg.class, "array_avg"), scalar(ArrayCompact.class, "array_compact"), scalar(ArrayContains.class, "array_contains"), + scalar(ArrayCumSum.class, "array_cum_sum"), scalar(ArrayDifference.class, "array_difference"), scalar(ArrayDistinct.class, "array_distinct"), scalar(ArrayEnumerate.class, "array_enumerate"), @@ -373,12 +373,13 @@ public class BuiltinScalarFunctions implements FunctionHelper { scalar(ArrayJoin.class, "array_join"), scalar(ArrayMax.class, "array_max"), scalar(ArrayMin.class, "array_min"), - scalar(ArrayPopback.class, "array_popback"), + scalar(ArrayPopBack.class, "array_popback"), + scalar(ArrayPopFront.class, "array_popfront"), scalar(ArrayPosition.class, "array_position"), scalar(ArrayProduct.class, "array_product"), scalar(ArrayRange.class, "array_range"), scalar(ArrayRemove.class, "array_remove"), - scalar(ArraySize.class, "array_size"), + scalar(ArrayReverseSort.class, "array_reverse_sort"), scalar(ArraySlice.class, "array_slice"), scalar(ArraySort.class, "array_sort"), scalar(ArraySum.class, "array_sum"), @@ -414,7 +415,7 @@ public class BuiltinScalarFunctions implements FunctionHelper { scalar(BitmapToString.class, "bitmap_to_string"), scalar(BitmapXor.class, "bitmap_xor"), scalar(BitmapXorCount.class, "bitmap_xor_count"), - scalar(Cardinality.class, "cardinality"), + scalar(Cardinality.class, "array_size", "cardinality", "size"), scalar(Cbrt.class, "cbrt"), scalar(Ceil.class, "ceil", "ceiling"), scalar(CharacterLength.class, "char_length", "character_length"), @@ -460,8 +461,6 @@ public class BuiltinScalarFunctions implements FunctionHelper { scalar(Dsqrt.class, "dsqrt"), scalar(E.class, "e"), scalar(ElementAt.class, "element_at"), - scalar(ElementExtract.class, "%element_extract%"), - scalar(ElementSlice.class, "%element_slice%"), scalar(Elt.class, "elt"), scalar(EndsWith.class, "ends_with"), scalar(EsQuery.class, "esquery"), @@ -596,11 +595,9 @@ public class BuiltinScalarFunctions implements FunctionHelper { scalar(SecToTime.class, "sec_to_time"), scalar(Sign.class, "sign"), scalar(Sin.class, "sin"), - scalar(Size.class, "size"), scalar(Sleep.class, "sleep"), scalar(Sm3.class, "sm3"), - scalar(Sm3sum.class, - "sm3sum"), + scalar(Sm3sum.class, "sm3sum"), scalar(Sm4Decrypt.class, "sm4_decrypt"), scalar(Sm4DecryptV2.class, "sm4_decrypt_v2"), scalar(Sm4Encrypt.class, "sm4_encrypt"), diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSignature.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSignature.java index 338a8b71ee..1cb1573233 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSignature.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSignature.java @@ -19,7 +19,6 @@ package org.apache.doris.catalog; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.FollowToArgumentType; import com.google.common.base.MoreObjects; @@ -33,13 +32,13 @@ import java.util.Optional; import java.util.function.BiFunction; public class FunctionSignature { - public final AbstractDataType returnType; + public final DataType returnType; public final boolean hasVarArgs; - public final List argumentsTypes; + public final List argumentsTypes; public final int arity; - private FunctionSignature(AbstractDataType returnType, boolean hasVarArgs, - List argumentsTypes) { + private FunctionSignature(DataType returnType, boolean hasVarArgs, + List argumentsTypes) { this.returnType = Objects.requireNonNull(returnType, "returnType is not null"); this.argumentsTypes = ImmutableList.copyOf( Objects.requireNonNull(argumentsTypes, "argumentsTypes is not null")); @@ -47,11 +46,11 @@ public class FunctionSignature { this.arity = argumentsTypes.size(); } - public Optional getVarArgType() { + public Optional getVarArgType() { return hasVarArgs ? Optional.of(argumentsTypes.get(arity - 1)) : Optional.empty(); } - public AbstractDataType getArgType(int index) { + public DataType getArgType(int index) { if (hasVarArgs && index >= arity) { return argumentsTypes.get(arity - 1); } @@ -62,8 +61,8 @@ public class FunctionSignature { return new FunctionSignature(returnType, hasVarArgs, argumentsTypes); } - public FunctionSignature withArgumentType(int index, AbstractDataType argumentType) { - ImmutableList.Builder builder = ImmutableList.builder(); + public FunctionSignature withArgumentType(int index, DataType argumentType) { + ImmutableList.Builder builder = ImmutableList.builder(); for (int i = 0; i < argumentsTypes.size(); i++) { if (i == index) { builder.add(argumentType); @@ -74,7 +73,7 @@ public class FunctionSignature { return new FunctionSignature(returnType, hasVarArgs, builder.build()); } - public FunctionSignature withArgumentTypes(boolean hasVarArgs, List argumentsTypes) { + public FunctionSignature withArgumentTypes(boolean hasVarArgs, List argumentsTypes) { return new FunctionSignature(returnType, hasVarArgs, argumentsTypes); } @@ -85,8 +84,8 @@ public class FunctionSignature { * @return */ public FunctionSignature withArgumentTypes(List arguments, - BiFunction transform) { - List newTypes = Lists.newArrayList(); + BiFunction transform) { + List newTypes = Lists.newArrayList(); for (int i = 0; i < arguments.size(); i++) { newTypes.add(transform.apply(getArgType(i), arguments.get(i))); } @@ -101,29 +100,29 @@ public class FunctionSignature { * @return */ public FunctionSignature withArgumentTypes(List arguments, - TripleFunction transform) { - List newTypes = Lists.newArrayList(); + TripleFunction transform) { + List newTypes = Lists.newArrayList(); for (int i = 0; i < argumentsTypes.size(); i++) { newTypes.add(transform.apply(i, argumentsTypes.get(i), arguments.get(i))); } return withArgumentTypes(hasVarArgs, newTypes); } - public static FunctionSignature of(AbstractDataType returnType, List argumentsTypes) { + public static FunctionSignature of(DataType returnType, List argumentsTypes) { return of(returnType, false, argumentsTypes); } - public static FunctionSignature of(AbstractDataType returnType, boolean hasVarArgs, - List argumentsTypes) { + public static FunctionSignature of(DataType returnType, boolean hasVarArgs, + List argumentsTypes) { return new FunctionSignature(returnType, hasVarArgs, argumentsTypes); } - public static FunctionSignature of(AbstractDataType returnType, AbstractDataType... argumentsTypes) { + public static FunctionSignature of(DataType returnType, DataType... argumentsTypes) { return of(returnType, false, argumentsTypes); } - public static FunctionSignature of(AbstractDataType returnType, - boolean hasVarArgs, AbstractDataType... argumentsTypes) { + public static FunctionSignature of(DataType returnType, + boolean hasVarArgs, DataType... argumentsTypes) { return new FunctionSignature(returnType, hasVarArgs, Arrays.asList(argumentsTypes)); } @@ -146,17 +145,17 @@ public class FunctionSignature { } public static class FuncSigBuilder { - public final AbstractDataType returnType; + public final DataType returnType; - public FuncSigBuilder(AbstractDataType returnType) { + public FuncSigBuilder(DataType returnType) { this.returnType = returnType; } - public FunctionSignature args(AbstractDataType...argTypes) { + public FunctionSignature args(DataType...argTypes) { return FunctionSignature.of(returnType, false, argTypes); } - public FunctionSignature varArgs(AbstractDataType...argTypes) { + public FunctionSignature varArgs(DataType...argTypes) { return FunctionSignature.of(returnType, true, argTypes); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java index bb2a044e55..a67513d0f0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java @@ -89,7 +89,7 @@ import org.apache.doris.nereids.trees.expressions.functions.window.WindowFunctio import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.literal.NullLiteral; import org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionVisitor; -import org.apache.doris.nereids.types.coercion.AbstractDataType; +import org.apache.doris.nereids.types.DataType; import org.apache.doris.thrift.TFunctionBinaryType; import com.google.common.base.Preconditions; @@ -372,7 +372,7 @@ public class ExpressionTranslator extends DefaultExpressionVisitor argTypes = function.getArguments().stream() .map(Expression::getDataType) - .map(AbstractDataType::toCatalogDataType) + .map(DataType::toCatalogDataType) .collect(Collectors.toList()); NullableMode nullableMode = function.nullable() @@ -412,7 +412,7 @@ public class ExpressionTranslator extends DefaultExpressionVisitor arg.accept(this, context)) .collect(Collectors.toList()); List argTypes = function.expectedInputTypes().stream() - .map(AbstractDataType::toCatalogDataType) + .map(DataType::toCatalogDataType) .collect(Collectors.toList()); NullableMode nullableMode = function.nullable() diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java index 626c6094be..e134f9822d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java @@ -236,8 +236,6 @@ public class Rewriter extends AbstractBatchJobExecutor { topDown(new ExpressionNormalization()) ), - custom(RuleType.CHECK_DATA_TYPES, CheckDataTypes::new), - // this rule should invoke after ColumnPruning custom(RuleType.ELIMINATE_UNNECESSARY_PROJECT, EliminateUnnecessaryProject::new), @@ -294,6 +292,7 @@ public class Rewriter extends AbstractBatchJobExecutor { ), // this rule batch must keep at the end of rewrite to do some plan check topic("Final rewrite and check", + custom(RuleType.CHECK_DATA_TYPES, CheckDataTypes::new), custom(RuleType.ENSURE_PROJECT_ON_TOP_JOIN, EnsureProjectOnTopJoin::new), topDown( new PushdownFilterThroughProject(), diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index c73ca04a2f..876ca00a32 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -29,6 +29,7 @@ import org.apache.doris.nereids.DorisParser.AliasQueryContext; import org.apache.doris.nereids.DorisParser.AliasedQueryContext; import org.apache.doris.nereids.DorisParser.ArithmeticBinaryContext; import org.apache.doris.nereids.DorisParser.ArithmeticUnaryContext; +import org.apache.doris.nereids.DorisParser.ArraySliceContext; import org.apache.doris.nereids.DorisParser.BitOperationContext; import org.apache.doris.nereids.DorisParser.BooleanExpressionContext; import org.apache.doris.nereids.DorisParser.BooleanLiteralContext; @@ -38,6 +39,7 @@ import org.apache.doris.nereids.DorisParser.ColumnReferenceContext; import org.apache.doris.nereids.DorisParser.CommentJoinHintContext; import org.apache.doris.nereids.DorisParser.CommentRelationHintContext; import org.apache.doris.nereids.DorisParser.ComparisonContext; +import org.apache.doris.nereids.DorisParser.ComplexDataTypeContext; import org.apache.doris.nereids.DorisParser.ConstantContext; import org.apache.doris.nereids.DorisParser.CreateRowPolicyContext; import org.apache.doris.nereids.DorisParser.CteContext; @@ -46,6 +48,7 @@ import org.apache.doris.nereids.DorisParser.Date_subContext; import org.apache.doris.nereids.DorisParser.DecimalLiteralContext; import org.apache.doris.nereids.DorisParser.DeleteContext; import org.apache.doris.nereids.DorisParser.DereferenceContext; +import org.apache.doris.nereids.DorisParser.ElementAtContext; import org.apache.doris.nereids.DorisParser.ExistContext; import org.apache.doris.nereids.DorisParser.ExplainContext; import org.apache.doris.nereids.DorisParser.FromClauseContext; @@ -125,6 +128,7 @@ import org.apache.doris.nereids.analyzer.UnboundResultSink; import org.apache.doris.nereids.analyzer.UnboundSlot; import org.apache.doris.nereids.analyzer.UnboundStar; import org.apache.doris.nereids.analyzer.UnboundTVFRelation; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.exceptions.ParseException; import org.apache.doris.nereids.properties.OrderKey; import org.apache.doris.nereids.properties.SelectHint; @@ -173,9 +177,11 @@ import org.apache.doris.nereids.trees.expressions.WindowFrame; import org.apache.doris.nereids.trees.expressions.functions.Function; import org.apache.doris.nereids.trees.expressions.functions.agg.Count; import org.apache.doris.nereids.trees.expressions.functions.agg.GroupConcat; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySlice; import org.apache.doris.nereids.trees.expressions.functions.scalar.DaysAdd; import org.apache.doris.nereids.trees.expressions.functions.scalar.DaysDiff; import org.apache.doris.nereids.trees.expressions.functions.scalar.DaysSub; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ElementAt; import org.apache.doris.nereids.trees.expressions.functions.scalar.HoursAdd; import org.apache.doris.nereids.trees.expressions.functions.scalar.HoursDiff; import org.apache.doris.nereids.trees.expressions.functions.scalar.HoursSub; @@ -244,7 +250,9 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalSort; import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias; import org.apache.doris.nereids.trees.plans.logical.LogicalUnion; import org.apache.doris.nereids.trees.plans.logical.UsingJoin; +import org.apache.doris.nereids.types.ArrayType; import org.apache.doris.nereids.types.DataType; +import org.apache.doris.nereids.types.MapType; import org.apache.doris.nereids.types.coercion.CharacterType; import org.apache.doris.nereids.util.ExpressionUtils; import org.apache.doris.policy.FilterType; @@ -452,8 +460,8 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor { @Override public String visitIdentifierOrText(IdentifierOrTextContext ctx) { - if (ctx.STRING() != null) { - return ctx.STRING().getText().substring(1, ctx.STRING().getText().length() - 1); + if (ctx.STRING_LITERAL() != null) { + return ctx.STRING_LITERAL().getText().substring(1, ctx.STRING_LITERAL().getText().length() - 1); } else { return ctx.errorCapturingIdentifier().getText(); } @@ -1076,8 +1084,7 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor { @Override public Expression visitCast(DorisParser.CastContext ctx) { - List types = typedVisit(ctx.dataType()); - DataType dataType = DataType.convertPrimitiveFromStrings(types, true); + DataType dataType = ((DataType) typedVisit(ctx.dataType())).conversion(); Expression cast = ParserUtils.withOrigin(ctx, () -> new Cast(getExpression(ctx.expression()), dataType)); if (dataType.isStringLikeType() && ((CharacterType) dataType).getLen() >= 0) { @@ -1238,7 +1245,7 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor { @Override public Expression visitTypeConstructor(TypeConstructorContext ctx) { - String value = ctx.STRING().getText(); + String value = ctx.STRING_LITERAL().getText(); value = value.substring(1, value.length() - 1); String type = ctx.type.getText().toUpperCase(); switch (type) { @@ -1269,6 +1276,20 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor { }); } + @Override + public Expression visitElementAt(ElementAtContext ctx) { + return new ElementAt(typedVisit(ctx.value), typedVisit(ctx.index)); + } + + @Override + public Expression visitArraySlice(ArraySliceContext ctx) { + if (ctx.end != null) { + return new ArraySlice(typedVisit(ctx.value), typedVisit(ctx.begin), typedVisit(ctx.end)); + } else { + return new ArraySlice(typedVisit(ctx.value), typedVisit(ctx.begin)); + } + } + @Override public UnboundSlot visitColumnReference(ColumnReferenceContext ctx) { // todo: handle quoted and unquoted @@ -1308,7 +1329,7 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor { @Override public Literal visitStringLiteral(StringLiteralContext ctx) { // TODO: add unescapeSQLString. - String txt = ctx.STRING().getText(); + String txt = ctx.STRING_LITERAL().getText(); String s = escapeBackSlash(txt.substring(1, txt.length() - 1)); return new VarcharLiteral(s); } @@ -1959,11 +1980,29 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor { } @Override - public List visitPrimitiveDataType(PrimitiveDataTypeContext ctx) { - String dataType = ctx.identifier().getText().toLowerCase(Locale.ROOT); - List l = Lists.newArrayList(dataType); - ctx.INTEGER_VALUE().stream().map(ParseTree::getText).forEach(l::add); - return l; + public DataType visitPrimitiveDataType(PrimitiveDataTypeContext ctx) { + return ParserUtils.withOrigin(ctx, () -> { + String dataType = ctx.identifier().getText().toLowerCase(Locale.ROOT); + List l = Lists.newArrayList(dataType); + ctx.INTEGER_VALUE().stream().map(ParseTree::getText).forEach(l::add); + return DataType.convertPrimitiveFromStrings(l); + }); + } + + @Override + public DataType visitComplexDataType(ComplexDataTypeContext ctx) { + return ParserUtils.withOrigin(ctx, () -> { + switch (ctx.complex.getType()) { + case DorisParser.ARRAY: + return ArrayType.of(typedVisit(ctx.dataType(0)), true); + case DorisParser.MAP: + return MapType.of(typedVisit(ctx.dataType(0)), typedVisit(ctx.dataType(1))); + case DorisParser.STRUCT: + throw new AnalysisException("do not support STRUCT type for Nereids"); + default: + throw new AnalysisException("do not support " + ctx.complex.getText() + " type for Nereids"); + } + }); } private Expression parseFunctionWithOrderKeys(String functionName, boolean isDistinct, diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/NereidsParser.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/NereidsParser.java index 70065c7eda..895f057a69 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/NereidsParser.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/NereidsParser.java @@ -25,6 +25,7 @@ import org.apache.doris.nereids.StatementContext; import org.apache.doris.nereids.glue.LogicalPlanAdapter; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.plans.logical.LogicalPlan; +import org.apache.doris.nereids.types.DataType; import com.google.common.collect.Lists; import org.antlr.v4.runtime.CharStreams; @@ -74,7 +75,7 @@ public class NereidsParser { return parse(expression, DorisParser::expression); } - public List parseDataType(String dataType) { + public DataType parseDataType(String dataType) { return parse(dataType, DorisParser::dataType); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/AvgDistinctToSumDivCount.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/AvgDistinctToSumDivCount.java index 9f1e97b5aa..3745ec51c2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/AvgDistinctToSumDivCount.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/AvgDistinctToSumDivCount.java @@ -55,7 +55,7 @@ public class AvgDistinctToSumDivCount extends OneRewriteRuleFactory { new Sum(true, ((Avg) function).isAlwaysNullable(), ((Avg) function).child())); Count count = (Count) TypeCoercionUtils.processBoundFunction( new Count(true, ((Avg) function).child())); - return TypeCoercionUtils.processDivide(new Divide(sum, count), sum, count); + return TypeCoercionUtils.processDivide(new Divide(sum, count)); })); if (!avgToSumDivCount.isEmpty()) { List newOutput = agg.getOutputExpressions().stream() diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java index 69896e44ee..71ecb55034 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java @@ -45,6 +45,7 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalProject; import org.apache.doris.nereids.types.DataType; import org.apache.doris.nereids.util.RelationUtil; import org.apache.doris.nereids.util.TypeCoercionUtils; +import org.apache.doris.qe.ConnectContext; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -100,45 +101,58 @@ public class BindSink implements AnalysisRuleFactory { Map columnToOutput = Maps.newLinkedHashMap(); NereidsParser expressionParser = new NereidsParser(); + // this is a trick way to avoid legacy planner's slotRef toSql output include label. + // see more in org.apache.doris.analysis.SlotRef.toSqlImpl + if (ConnectContext.get() != null) { + ConnectContext.get().getState().setIsQuery(true); + } // generate slots not mentioned in sql, mv slots and shaded slots. - for (Column column : boundSink.getTargetTable().getFullSchema()) { - if (column.isMaterializedViewColumn()) { - List refs = column.getRefColumns(); - // now we have to replace the column to slots. - Preconditions.checkArgument(refs != null, - "mv column's ref column cannot be null"); - Expression parsedExpression = expressionParser.parseExpression( - column.getDefineExpr().toSql()); - Expression boundExpression = SlotReplacer.INSTANCE - .replace(parsedExpression, columnToOutput); + try { + for (Column column : boundSink.getTargetTable().getFullSchema()) { + if (column.isMaterializedViewColumn()) { + List refs = column.getRefColumns(); + // now we have to replace the column to slots. + Preconditions.checkArgument(refs != null, + "mv column's ref column cannot be null"); + Expression parsedExpression = expressionParser.parseExpression( + column.getDefineExpr().toSql()); + Expression boundExpression = SlotReplacer.INSTANCE + .replace(parsedExpression, columnToOutput); - NamedExpression slot = boundExpression instanceof NamedExpression - ? ((NamedExpression) boundExpression) - : new Alias(boundExpression, boundExpression.toSql()); + NamedExpression slot = boundExpression instanceof NamedExpression + ? ((NamedExpression) boundExpression) + : new Alias(boundExpression, boundExpression.toSql()); - columnToOutput.put(column.getName(), slot); - } else if (columnToChildOutput.containsKey(column)) { - columnToOutput.put(column.getName(), columnToChildOutput.get(column)); - } else { - if (table.hasSequenceCol() - && column.getName().equals(Column.SEQUENCE_COL) - && table.getSequenceMapCol() != null) { - Column seqCol = table.getFullSchema().stream() - .filter(col -> col.getName().equals(table.getSequenceMapCol())) - .findFirst().get(); - columnToOutput.put(column.getName(), columnToOutput.get(seqCol.getName())); - } else if (column.getDefaultValue() == null) { - columnToOutput.put(column.getName(), new Alias( - new NullLiteral(DataType.fromCatalogType(column.getType())), - column.getName() - )); + columnToOutput.put(column.getName(), slot); + } else if (columnToChildOutput.containsKey(column)) { + columnToOutput.put(column.getName(), columnToChildOutput.get(column)); } else { - columnToOutput.put(column.getName(), - new Alias(Literal.of(column.getDefaultValue()) - .checkedCastTo(DataType.fromCatalogType(column.getType())), - column.getName())); + if (table.hasSequenceCol() + && column.getName().equals(Column.SEQUENCE_COL) + && table.getSequenceMapCol() != null) { + Column seqCol = table.getFullSchema().stream() + .filter(col -> col.getName().equals(table.getSequenceMapCol())) + .findFirst().get(); + columnToOutput.put(column.getName(), columnToOutput.get(seqCol.getName())); + } else if (column.getDefaultValue() == null) { + columnToOutput.put(column.getName(), new Alias( + new NullLiteral(DataType.fromCatalogType(column.getType())), + column.getName() + )); + } else { + columnToOutput.put(column.getName(), + new Alias(Literal.of(column.getDefaultValue()) + .checkedCastTo(DataType.fromCatalogType(column.getType())), + column.getName())); + } } } + } finally { + if (ConnectContext.get() != null) { + // this is a trick way to avoid legacy planner's slotRef toSql output include label + // set back to original value. + ConnectContext.get().getState().setIsQuery(false); + } } List fullOutputExprs = ImmutableList.copyOf(columnToOutput.values()); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/check/CheckCast.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/check/CheckCast.java index c377a0e9e9..2a5b83a06f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/check/CheckCast.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/check/CheckCast.java @@ -24,6 +24,10 @@ import org.apache.doris.nereids.trees.expressions.Cast; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.types.ArrayType; import org.apache.doris.nereids.types.DataType; +import org.apache.doris.nereids.types.MapType; +import org.apache.doris.nereids.types.StructType; + +import java.util.Map; /** * check cast valid @@ -44,14 +48,23 @@ public class CheckCast extends AbstractExpressionRewriteRule { } private boolean check(DataType originalType, DataType targetType) { - if (originalType.isArrayType() && targetType.isArrayType()) { + if (originalType instanceof ArrayType && targetType instanceof ArrayType) { return check(((ArrayType) originalType).getItemType(), ((ArrayType) targetType).getItemType()); - } else if (originalType.isMapType()) { - // TODO support map cast check when we support map - return false; - } else if (originalType.isStructType()) { - // TODO support struct cast check when we support struct - return false; + } else if (originalType instanceof MapType && targetType instanceof MapType) { + return check(((MapType) originalType).getKeyType(), ((MapType) targetType).getKeyType()) + && check(((MapType) originalType).getValueType(), ((MapType) targetType).getValueType()); + } else if (originalType instanceof StructType && targetType instanceof StructType) { + Map targetItems = ((StructType) targetType).getItems(); + for (Map.Entry entry : ((StructType) originalType).getItems().entrySet()) { + if (targetItems.containsKey(entry.getKey())) { + if (!check(entry.getValue(), targetItems.get(entry.getKey()))) { + return false; + } + } else { + return false; + } + } + return true; } else { return checkPrimitiveType(originalType, targetType); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FunctionBinder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FunctionBinder.java index f3821e3cad..e6c1af805b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FunctionBinder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/FunctionBinder.java @@ -20,7 +20,6 @@ package org.apache.doris.nereids.rules.expression.rules; import org.apache.doris.analysis.ArithmeticExpr.Operator; import org.apache.doris.catalog.Env; import org.apache.doris.catalog.FunctionRegistry; -import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.nereids.analyzer.UnboundFunction; import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.rules.analysis.ArithmeticFunctionBinder; @@ -43,12 +42,14 @@ import org.apache.doris.nereids.trees.expressions.ListQuery; import org.apache.doris.nereids.trees.expressions.Match; import org.apache.doris.nereids.trees.expressions.Not; import org.apache.doris.nereids.trees.expressions.TimestampArithmetic; +import org.apache.doris.nereids.trees.expressions.WhenClause; import org.apache.doris.nereids.trees.expressions.functions.BoundFunction; import org.apache.doris.nereids.trees.expressions.functions.FunctionBuilder; import org.apache.doris.nereids.trees.expressions.functions.udf.AliasUdfBuilder; import org.apache.doris.nereids.trees.expressions.typecoercion.ImplicitCastInputTypes; import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; +import org.apache.doris.nereids.types.BooleanType; +import org.apache.doris.nereids.types.DataType; import org.apache.doris.nereids.util.TypeCoercionUtils; import com.google.common.collect.ImmutableList; @@ -70,7 +71,7 @@ public class FunctionBinder extends AbstractExpressionRewriteRule { expr.checkLegalityBeforeTypeCoercion(); // this cannot be removed, because some function already construct in parser. if (expr instanceof ImplicitCastInputTypes) { - List expectedInputTypes = ((ImplicitCastInputTypes) expr).expectedInputTypes(); + List expectedInputTypes = ((ImplicitCastInputTypes) expr).expectedInputTypes(); if (!expectedInputTypes.isEmpty()) { return TypeCoercionUtils.implicitCastInputTypes(expr, expectedInputTypes); } @@ -125,6 +126,7 @@ public class FunctionBinder extends AbstractExpressionRewriteRule { Expression left = arithmetic.left().accept(this, context); Expression right = arithmetic.right().accept(this, context); + arithmetic = (TimestampArithmetic) arithmetic.withChildren(left, right); // bind function String funcOpName; if (arithmetic.getFuncName() == null) { @@ -137,7 +139,7 @@ public class FunctionBinder extends AbstractExpressionRewriteRule { arithmetic = (TimestampArithmetic) arithmetic.withFuncName(funcOpName.toLowerCase(Locale.ROOT)); // type coercion - return TypeCoercionUtils.processTimestampArithmetic(arithmetic, left, right); + return TypeCoercionUtils.processTimestampArithmetic(arithmetic); } /* ******************************************************************************************** @@ -148,7 +150,7 @@ public class FunctionBinder extends AbstractExpressionRewriteRule { public Expression visitBitNot(BitNot bitNot, ExpressionRewriteContext context) { Expression child = bitNot.child().accept(this, context); // type coercion - if (child.getDataType().toCatalogDataType().getPrimitiveType().ordinal() > PrimitiveType.LARGEINT.ordinal()) { + if (!(child.getDataType().isIntegralType() || child.getDataType().isBooleanType())) { child = new Cast(child, BigIntType.INSTANCE); } return bitNot.withChildren(child); @@ -158,25 +160,26 @@ public class FunctionBinder extends AbstractExpressionRewriteRule { public Expression visitDivide(Divide divide, ExpressionRewriteContext context) { Expression left = divide.left().accept(this, context); Expression right = divide.right().accept(this, context); - + divide = (Divide) divide.withChildren(left, right); // type coercion - return TypeCoercionUtils.processDivide(divide, left, right); + return TypeCoercionUtils.processDivide(divide); } @Override public Expression visitIntegralDivide(IntegralDivide integralDivide, ExpressionRewriteContext context) { Expression left = integralDivide.left().accept(this, context); Expression right = integralDivide.right().accept(this, context); - + integralDivide = (IntegralDivide) integralDivide.withChildren(left, right); // type coercion - return TypeCoercionUtils.processIntegralDivide(integralDivide, left, right); + return TypeCoercionUtils.processIntegralDivide(integralDivide); } @Override public Expression visitBinaryArithmetic(BinaryArithmetic binaryArithmetic, ExpressionRewriteContext context) { Expression left = binaryArithmetic.left().accept(this, context); Expression right = binaryArithmetic.right().accept(this, context); - return TypeCoercionUtils.processBinaryArithmetic(binaryArithmetic, left, right); + binaryArithmetic = (BinaryArithmetic) binaryArithmetic.withChildren(left, right); + return TypeCoercionUtils.processBinaryArithmetic(binaryArithmetic); } @Override @@ -203,7 +206,8 @@ public class FunctionBinder extends AbstractExpressionRewriteRule { public Expression visitComparisonPredicate(ComparisonPredicate cp, ExpressionRewriteContext context) { Expression left = cp.left().accept(this, context); Expression right = cp.right().accept(this, context); - return TypeCoercionUtils.processComparisonPredicate(cp, left, right); + cp = (ComparisonPredicate) cp.withChildren(left, right); + return TypeCoercionUtils.processComparisonPredicate(cp); } @Override @@ -215,6 +219,13 @@ public class FunctionBinder extends AbstractExpressionRewriteRule { return TypeCoercionUtils.processCaseWhen(newCaseWhen); } + @Override + public Expression visitWhenClause(WhenClause whenClause, ExpressionRewriteContext context) { + return whenClause.withChildren(TypeCoercionUtils.castIfNotSameType( + whenClause.getOperand().accept(this, context), BooleanType.INSTANCE), + whenClause.getResult().accept(this, context)); + } + @Override public Expression visitInPredicate(InPredicate inPredicate, ExpressionRewriteContext context) { List rewrittenChildren = inPredicate.children().stream() @@ -235,10 +246,8 @@ public class FunctionBinder extends AbstractExpressionRewriteRule { public Expression visitInSubquery(InSubquery inSubquery, ExpressionRewriteContext context) { Expression newCompareExpr = inSubquery.getCompareExpr().accept(this, context); Expression newListQuery = inSubquery.getListQuery().accept(this, context); - ComparisonPredicate newCpAfterUnNestingSubquery = - new EqualTo(newCompareExpr, ((ListQuery) newListQuery).getQueryPlan().getOutput().get(0)); ComparisonPredicate afterTypeCoercion = (ComparisonPredicate) TypeCoercionUtils.processComparisonPredicate( - newCpAfterUnNestingSubquery, newCompareExpr, newListQuery); + new EqualTo(newCompareExpr, newListQuery)); if (newListQuery.getDataType().isBitmapType()) { if (!newCompareExpr.getDataType().isBigIntType()) { newCompareExpr = new Cast(newCompareExpr, BigIntType.INSTANCE); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticComparisonRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticComparisonRule.java index c5ab5119ce..28c66a3ac5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticComparisonRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyArithmeticComparisonRule.java @@ -73,7 +73,8 @@ public class SimplifyArithmeticComparisonRule extends AbstractExpressionRewriteR } } if (left != predicate.left() || right != predicate.right()) { - return TypeCoercionUtils.processComparisonPredicate(predicate, left, right); + predicate = (ComparisonPredicate) predicate.withChildren(left, right); + return TypeCoercionUtils.processComparisonPredicate(predicate); } else { return predicate; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CheckDataTypes.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CheckDataTypes.java index 7713cfb906..ad889a944c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CheckDataTypes.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CheckDataTypes.java @@ -25,7 +25,6 @@ import org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionVisit import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; import org.apache.doris.nereids.trees.plans.visitor.CustomRewriter; -import org.apache.doris.nereids.types.ArrayType; import org.apache.doris.nereids.types.DataType; import org.apache.doris.nereids.types.JsonType; import org.apache.doris.nereids.types.MapType; @@ -41,7 +40,7 @@ import java.util.Set; public class CheckDataTypes implements CustomRewriter { private static final Set> UNSUPPORTED_TYPE = ImmutableSet.of( - MapType.class, StructType.class, JsonType.class, ArrayType.class); + MapType.class, StructType.class, JsonType.class); @Override public Plan rewriteRoot(Plan rootPlan, JobContext jobContext) { @@ -51,20 +50,20 @@ public class CheckDataTypes implements CustomRewriter { private void checkPlan(Plan plan) { if (plan instanceof LogicalJoin) { - checkLogicalJoin((LogicalJoin) plan); + checkLogicalJoin((LogicalJoin) plan); } plan.getExpressions().forEach(ExpressionChecker.INSTANCE::check); - plan.children().forEach(child -> checkPlan(child)); + plan.children().forEach(this::checkPlan); } - private void checkLogicalJoin(LogicalJoin plan) { - plan.getHashJoinConjuncts().stream().forEach(expr -> { - DataType leftType = ((Expression) expr).child(0).getDataType(); - DataType rightType = ((Expression) expr).child(1).getDataType(); + private void checkLogicalJoin(LogicalJoin plan) { + plan.getHashJoinConjuncts().forEach(expr -> { + DataType leftType = expr.child(0).getDataType(); + DataType rightType = expr.child(1).getDataType(); if (!leftType.acceptsType(rightType)) { throw new AnalysisException( String.format("type %s is not same as %s in hash join condition %s", - leftType, rightType, ((Expression) expr).toSql())); + leftType, rightType, expr.toSql())); } }); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/SelectMaterializedIndexWithAggregate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/SelectMaterializedIndexWithAggregate.java index d9cbe99fd9..ce2c5e3687 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/SelectMaterializedIndexWithAggregate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/SelectMaterializedIndexWithAggregate.java @@ -30,7 +30,6 @@ import org.apache.doris.nereids.parser.NereidsParser; import org.apache.doris.nereids.rules.Rule; import org.apache.doris.nereids.rules.RuleType; import org.apache.doris.nereids.rules.rewrite.RewriteRuleFactory; -import org.apache.doris.nereids.rules.rewrite.mv.AbstractSelectMaterializedIndexRule.SlotContext; import org.apache.doris.nereids.trees.expressions.Alias; import org.apache.doris.nereids.trees.expressions.ExprId; import org.apache.doris.nereids.trees.expressions.Expression; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BinaryArithmetic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BinaryArithmetic.java index 501af7470c..8fe86c98c0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BinaryArithmetic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BinaryArithmetic.java @@ -18,18 +18,16 @@ package org.apache.doris.nereids.trees.expressions; import org.apache.doris.analysis.ArithmeticExpr.Operator; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.exceptions.UnboundException; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DataType; import org.apache.doris.nereids.types.DecimalV2Type; import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.NumericType; import org.apache.doris.nereids.util.TypeCoercionUtils; -import com.google.common.base.Preconditions; - import java.util.List; /** @@ -49,7 +47,7 @@ public abstract class BinaryArithmetic extends BinaryOperator implements Propaga } @Override - public AbstractDataType inputType() { + public DataType inputType() { return NumericType.INSTANCE; } @@ -84,9 +82,8 @@ public abstract class BinaryArithmetic extends BinaryOperator implements Propaga } } // should not come here - Preconditions.checkState(false, "Both side of binary arithmetic is not numeric." + throw new AnalysisException("Both side of binary arithmetic is not numeric." + " left type is " + left().getDataType() + " and right type is " + right().getDataType()); - return left().getDataType(); } public R accept(ExpressionVisitor visitor, C context) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BinaryOperator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BinaryOperator.java index 3327680137..c3006fa927 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BinaryOperator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BinaryOperator.java @@ -19,7 +19,7 @@ package org.apache.doris.nereids.trees.expressions; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.typecoercion.ExpectsInputTypes; -import org.apache.doris.nereids.types.coercion.AbstractDataType; +import org.apache.doris.nereids.types.DataType; import com.google.common.collect.ImmutableList; @@ -38,10 +38,10 @@ public abstract class BinaryOperator extends Expression implements BinaryExpress this.symbol = symbol; } - public abstract AbstractDataType inputType(); + public abstract DataType inputType(); @Override - public List expectedInputTypes() { + public List expectedInputTypes() { return ImmutableList.of(inputType(), inputType()); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BitNot.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BitNot.java index 8fea0b0b3c..ea6804e625 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BitNot.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BitNot.java @@ -21,7 +21,6 @@ import org.apache.doris.analysis.ArithmeticExpr.Operator; import org.apache.doris.nereids.exceptions.UnboundException; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.NumericType; import com.google.common.base.Preconditions; @@ -59,7 +58,7 @@ public class BitNot extends UnaryArithmetic { } @Override - public AbstractDataType inputType() { + public DataType inputType() { return NumericType.INSTANCE; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/CaseWhen.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/CaseWhen.java index 1b0e9eb80f..e61d599e7b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/CaseWhen.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/CaseWhen.java @@ -17,6 +17,7 @@ package org.apache.doris.nereids.trees.expressions; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.exceptions.UnboundException; import org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; @@ -29,7 +30,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.stream.Collectors; import java.util.stream.Stream; /** @@ -70,12 +70,6 @@ public class CaseWhen extends Expression { .collect(ImmutableList.toImmutableList()); } - public List expressionForCoercion() { - List ret = whenClauses.stream().map(WhenClause::getResult).collect(Collectors.toList()); - defaultValue.ifPresent(ret::add); - return ret; - } - public R accept(ExpressionVisitor visitor, C context) { return visitor.visitCaseWhen(this, context); } @@ -116,7 +110,7 @@ public class CaseWhen extends Expression { @Override public CaseWhen withChildren(List children) { - Preconditions.checkArgument(children.size() >= 1); + Preconditions.checkArgument(!children.isEmpty(), "case when should has at least 1 child"); List whenClauseList = new ArrayList<>(); Expression defaultValue = null; for (int i = 0; i < children.size(); i++) { @@ -125,7 +119,7 @@ public class CaseWhen extends Expression { } else if (children.size() - 1 == i) { defaultValue = children.get(i); } else { - throw new IllegalArgumentException("The children format needs to be [WhenClause+, DefaultValue?]"); + throw new AnalysisException("The children format needs to be [WhenClause+, DefaultValue?]"); } } if (defaultValue == null) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ComparisonPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ComparisonPredicate.java index f00e2a6f78..bba834967f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ComparisonPredicate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ComparisonPredicate.java @@ -17,12 +17,11 @@ package org.apache.doris.nereids.trees.expressions; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.exceptions.UnboundException; -import org.apache.doris.nereids.trees.expressions.typecoercion.TypeCheckResult; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BooleanType; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.AnyDataType; import java.util.List; @@ -47,8 +46,8 @@ public abstract class ComparisonPredicate extends BinaryOperator { } @Override - public AbstractDataType inputType() { - return AnyDataType.INSTANCE; + public DataType inputType() { + return AnyDataType.INSTANCE_WITHOUT_INDEX; } /** @@ -57,14 +56,11 @@ public abstract class ComparisonPredicate extends BinaryOperator { public abstract ComparisonPredicate commute(); @Override - public TypeCheckResult checkInputDataTypes() { - for (int i = 0; i < super.children().size(); i++) { - Expression input = super.children().get(i); - if (input.getDataType().isObjectType()) { - return new TypeCheckResult(false, - "Bitmap type does not support operator:" + this.toSql()); + public void checkLegalityBeforeTypeCoercion() { + children().forEach(c -> { + if (c.getDataType().isComplexType()) { + throw new AnalysisException("comparison predicate could not contains complex type: " + this.toSql()); } - } - return TypeCheckResult.SUCCESS; + }); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/CompoundPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/CompoundPredicate.java index 6c9d133db9..725d92068d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/CompoundPredicate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/CompoundPredicate.java @@ -21,7 +21,6 @@ import org.apache.doris.nereids.exceptions.UnboundException; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BooleanType; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import java.util.List; @@ -51,7 +50,7 @@ public abstract class CompoundPredicate extends BinaryOperator { } @Override - public AbstractDataType inputType() { + public DataType inputType() { return BooleanType.INSTANCE; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/EqualTo.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/EqualTo.java index 0fa23a57e0..065f6b9340 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/EqualTo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/EqualTo.java @@ -44,11 +44,6 @@ public class EqualTo extends ComparisonPredicate implements PropagateNullable { return left().nullable() || right().nullable(); } - @Override - public String toString() { - return "(" + left() + " = " + right() + ")"; - } - @Override public EqualTo withChildren(List children) { Preconditions.checkArgument(children.size() == 2); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java index 14b999b275..3c90d5c21b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java @@ -27,12 +27,10 @@ import org.apache.doris.nereids.trees.expressions.shape.LeafExpression; import org.apache.doris.nereids.trees.expressions.typecoercion.ExpectsInputTypes; import org.apache.doris.nereids.trees.expressions.typecoercion.TypeCheckResult; 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.coercion.AbstractDataType; -import org.apache.doris.nereids.types.coercion.CharacterType; -import org.apache.doris.nereids.types.coercion.FractionalType; -import org.apache.doris.nereids.types.coercion.IntegralType; -import org.apache.doris.nereids.types.coercion.NumericType; +import org.apache.doris.nereids.types.MapType; +import org.apache.doris.nereids.types.StructType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -68,43 +66,68 @@ public abstract class Expression extends AbstractTreeNode implements * check input data types */ public TypeCheckResult checkInputDataTypes() { + // check all of its children recursively. + for (Expression expression : this.children) { + TypeCheckResult childResult = expression.checkInputDataTypes(); + if (childResult.failed()) { + return childResult; + } + } if (this instanceof ExpectsInputTypes) { ExpectsInputTypes expectsInputTypes = (ExpectsInputTypes) this; - return checkInputDataTypes(children, expectsInputTypes.expectedInputTypes()); + TypeCheckResult commonCheckResult = checkInputDataTypesWithExpectTypes( + children, expectsInputTypes.expectedInputTypes()); + if (commonCheckResult.failed()) { + return commonCheckResult; + } + } + return checkInputDataTypesInternal(); + } + + protected TypeCheckResult checkInputDataTypesInternal() { + return TypeCheckResult.SUCCESS; + } + + private boolean checkInputDataTypesWithExpectType(DataType input, DataType expected) { + if (input instanceof ArrayType && expected instanceof ArrayType) { + return checkInputDataTypesWithExpectType( + ((ArrayType) input).getItemType(), ((ArrayType) expected).getItemType()); + } else if (input instanceof MapType && expected instanceof MapType) { + return checkInputDataTypesWithExpectType( + ((MapType) input).getKeyType(), ((MapType) expected).getKeyType()) + && checkInputDataTypesWithExpectType( + ((MapType) input).getValueType(), ((MapType) expected).getValueType()); + } else if (input instanceof StructType && expected instanceof StructType) { + throw new AnalysisException("not support struct type now."); } else { - List errorMessages = Lists.newArrayList(); - // check all of its children recursively. - for (int i = 0; i < this.children.size(); ++i) { - Expression expression = this.children.get(i); - TypeCheckResult childResult = expression.checkInputDataTypes(); - if (childResult != TypeCheckResult.SUCCESS) { - errorMessages.add(String.format("argument %d type check fail: %s", - i + 1, childResult.getMessage())); - } - } - if (errorMessages.isEmpty()) { - return TypeCheckResult.SUCCESS; - } else { - return new TypeCheckResult(false, StringUtils.join(errorMessages, ", ")); - } + return checkPrimitiveInputDataTypesWithExpectType(input, expected); } } - private TypeCheckResult checkInputDataTypes(List inputs, List inputTypes) { - Preconditions.checkArgument(inputs.size() == inputTypes.size()); + private boolean checkPrimitiveInputDataTypesWithExpectType(DataType input, DataType expected) { + // TODO: complete the cast logic like FunctionCallExpr.analyzeImpl + boolean legacyCastCompatible = false; + try { + legacyCastCompatible = input.toCatalogDataType().matchesType(expected.toCatalogDataType()); + } catch (Throwable t) { + // ignore. + } + if (!legacyCastCompatible && !expected.acceptsType(input)) { + return false; + } + return true; + } + + private TypeCheckResult checkInputDataTypesWithExpectTypes( + List inputs, List expectedTypes) { + Preconditions.checkArgument(inputs.size() == expectedTypes.size()); List errorMessages = Lists.newArrayList(); for (int i = 0; i < inputs.size(); i++) { Expression input = inputs.get(i); - AbstractDataType inputType = inputTypes.get(i); - boolean legacyCastCompatible = inputType instanceof DataType - && !(inputType.getClass().equals(NumericType.class)) - && !(inputType.getClass().equals(IntegralType.class)) - && !(inputType.getClass().equals(FractionalType.class)) - && !(inputType.getClass().equals(CharacterType.class)) - && input.getDataType().toCatalogDataType().matchesType(inputType.toCatalogDataType()); - if (!legacyCastCompatible && !inputType.acceptsType(input.getDataType())) { + DataType expected = expectedTypes.get(i); + if (!checkInputDataTypesWithExpectType(input.getDataType(), expected)) { errorMessages.add(String.format("argument %d requires %s type, however '%s' is of %s type", - i + 1, inputType.simpleString(), input.toSql(), input.getDataType().simpleString())); + i + 1, expected.simpleString(), input.toSql(), input.getDataType().simpleString())); } } if (!errorMessages.isEmpty()) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java index d90ec7489e..a7383d5510 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java @@ -17,6 +17,7 @@ package org.apache.doris.nereids.trees.expressions; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.exceptions.UnboundException; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; @@ -67,6 +68,18 @@ public class InPredicate extends Expression { return children().stream().anyMatch(Expression::nullable); } + @Override + public void checkLegalityBeforeTypeCoercion() { + children().forEach(c -> { + if (c.getDataType().isObjectType()) { + throw new AnalysisException("in predicate could not contains object type: " + this.toSql()); + } + if (c.getDataType().isComplexType()) { + throw new AnalysisException("in predicate could not contains complex type: " + this.toSql()); + } + }); + } + @Override public String toString() { return compareExpr + " IN " + options.stream() diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Match.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Match.java index bc9837eafe..5ff384a8a7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Match.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Match.java @@ -24,7 +24,6 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BooleanType; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.AnyDataType; import java.util.List; @@ -51,7 +50,7 @@ public abstract class Match extends BinaryOperator implements PropagateNullable case "MATCH_PHRASE": return Operator.MATCH_PHRASE; default: - throw new AnalysisException("UnSupported type: " + symbol); + throw new AnalysisException("UnSupported type for match: " + symbol); } } @@ -61,8 +60,8 @@ public abstract class Match extends BinaryOperator implements PropagateNullable } @Override - public AbstractDataType inputType() { - return AnyDataType.INSTANCE; + public DataType inputType() { + return AnyDataType.INSTANCE_WITHOUT_INDEX; } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Not.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Not.java index f62b18a677..7c7ec5283b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Not.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Not.java @@ -24,7 +24,6 @@ import org.apache.doris.nereids.trees.expressions.typecoercion.ExpectsInputTypes import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BooleanType; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -37,7 +36,7 @@ import java.util.Objects; */ public class Not extends Expression implements UnaryExpression, ExpectsInputTypes, PropagateNullable { - public static final List EXPECTS_INPUT_TYPES = ImmutableList.of(BooleanType.INSTANCE); + public static final List EXPECTS_INPUT_TYPES = ImmutableList.of(BooleanType.INSTANCE); public Not(Expression child) { super(ImmutableList.of(child)); @@ -98,7 +97,7 @@ public class Not extends Expression implements UnaryExpression, ExpectsInputType } @Override - public List expectedInputTypes() { + public List expectedInputTypes() { return EXPECTS_INPUT_TYPES; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/TimestampArithmetic.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/TimestampArithmetic.java index 44828b5045..0b2a75038f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/TimestampArithmetic.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/TimestampArithmetic.java @@ -18,6 +18,7 @@ package org.apache.doris.nereids.trees.expressions; import org.apache.doris.analysis.ArithmeticExpr.Operator; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.exceptions.UnboundException; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; import org.apache.doris.nereids.trees.expressions.literal.Interval.TimeUnit; @@ -118,6 +119,18 @@ public class TimestampArithmetic extends Expression implements BinaryExpression, return timeUnit; } + @Override + public void checkLegalityBeforeTypeCoercion() { + children().forEach(c -> { + if (c.getDataType().isObjectType()) { + throw new AnalysisException("timestamp arithmetic could not contains object type: " + this.toSql()); + } + if (c.getDataType().isComplexType()) { + throw new AnalysisException("timestamp arithmetic could not contains complex type: " + this.toSql()); + } + }); + } + @Override public String toString() { return toSql(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/UnaryOperator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/UnaryOperator.java index 42059a7ef2..ace2c648da 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/UnaryOperator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/UnaryOperator.java @@ -19,7 +19,7 @@ package org.apache.doris.nereids.trees.expressions; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.typecoercion.ExpectsInputTypes; -import org.apache.doris.nereids.types.coercion.AbstractDataType; +import org.apache.doris.nereids.types.DataType; import com.google.common.collect.ImmutableList; @@ -38,10 +38,10 @@ public abstract class UnaryOperator extends Expression implements UnaryExpressio this.symbol = symbol; } - public abstract AbstractDataType inputType(); + public abstract DataType inputType(); @Override - public List expectedInputTypes() { + public List expectedInputTypes() { return ImmutableList.of(inputType()); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/WhenClause.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/WhenClause.java index 147dc5f601..dea93d216d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/WhenClause.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/WhenClause.java @@ -23,7 +23,6 @@ import org.apache.doris.nereids.trees.expressions.typecoercion.ExpectsInputTypes import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.BooleanType; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; @@ -37,8 +36,8 @@ import java.util.Objects; */ public class WhenClause extends Expression implements BinaryExpression, ExpectsInputTypes { - public static final List EXPECTS_INPUT_TYPES - = ImmutableList.of(BooleanType.INSTANCE, AnyDataType.INSTANCE); + public static final List EXPECTS_INPUT_TYPES + = ImmutableList.of(BooleanType.INSTANCE, AnyDataType.INSTANCE_WITHOUT_INDEX); public WhenClause(Expression operand, Expression result) { super(ImmutableList.of(operand, result)); @@ -86,7 +85,7 @@ public class WhenClause extends Expression implements BinaryExpression, ExpectsI } @Override - public List expectedInputTypes() { + public List expectedInputTypes() { return EXPECTS_INPUT_TYPES; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputePrecisionForArrayItemAgg.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputePrecisionForArrayItemAgg.java new file mode 100644 index 0000000000..50c9f1adfd --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputePrecisionForArrayItemAgg.java @@ -0,0 +1,43 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.trees.expressions.functions; + +import org.apache.doris.catalog.FunctionSignature; +import org.apache.doris.nereids.types.ArrayType; +import org.apache.doris.nereids.types.DataType; +import org.apache.doris.nereids.types.DecimalV3Type; + +/** ComputePrecisionForSum */ +public interface ComputePrecisionForArrayItemAgg extends ComputePrecision { + @Override + default FunctionSignature computePrecision(FunctionSignature signature) { + if (getArgumentType(0) instanceof ArrayType) { + DataType itemType = ((ArrayType) getArgument(0).getDataType()).getItemType(); + if (itemType instanceof DecimalV3Type) { + DecimalV3Type returnType = DecimalV3Type.createDecimalV3Type( + DecimalV3Type.MAX_DECIMAL128_PRECISION, ((DecimalV3Type) itemType).getScale()); + if (signature.returnType instanceof ArrayType) { + signature = signature.withReturnType(ArrayType.of(returnType)); + } else { + signature = signature.withReturnType(returnType); + } + } + } + return signature; + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignature.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignature.java index 93d6d74928..549053f89b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignature.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignature.java @@ -19,15 +19,19 @@ package org.apache.doris.nereids.trees.expressions.functions; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.annotation.Developing; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureHelper.ComputeSignatureChain; import org.apache.doris.nereids.trees.expressions.typecoercion.ImplicitCastInputTypes; +import org.apache.doris.nereids.types.ArrayType; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; +import org.apache.doris.nereids.types.MapType; +import org.apache.doris.nereids.types.StructType; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; import java.util.List; +import java.util.function.BiFunction; /** * this class is usage to compute function's return type by the argument's type. @@ -67,13 +71,13 @@ public interface ComputeSignature extends FunctionTrait, ImplicitCastInputTypes * @return expectedInputTypes */ @Override - default List expectedInputTypes() { + default List expectedInputTypes() { FunctionSignature signature = getSignature(); int arity = arity(); if (signature.hasVarArgs && arity > signature.arity) { - Builder varTypes = ImmutableList.builder() + Builder varTypes = ImmutableList.builder() .addAll(signature.argumentsTypes); - AbstractDataType varType = signature.getVarArgType().get(); + DataType varType = signature.getVarArgType().get(); for (int i = signature.arity; i < arity; ++i) { varTypes.add(varType); } @@ -88,7 +92,7 @@ public interface ComputeSignature extends FunctionTrait, ImplicitCastInputTypes */ @Override default DataType getDataType() { - return (DataType) getSignature().returnType; + return getSignature().returnType; } @Override @@ -105,10 +109,27 @@ public interface ComputeSignature extends FunctionTrait, ImplicitCastInputTypes // If you want to add some special cases, please override this method in the special // function class, like 'If' function and 'Substring' function. return ComputeSignatureChain.from(this, signature, getArguments()) - .then(ComputeSignatureHelper::implementAbstractReturnType) - .then(ComputeSignatureHelper::normalizeDecimalV2) + .then(ComputeSignatureHelper::implementAnyDataTypeWithIndex) .then(ComputeSignatureHelper::computePrecision) + .then(ComputeSignatureHelper::implementFollowToArgumentReturnType) + .then(ComputeSignatureHelper::normalizeDecimalV2) .then(ComputeSignatureHelper::dynamicComputePropertiesOfArray) .get(); } + + /** default computeSignature */ + static boolean processComplexType(DataType signatureType, DataType realType, + BiFunction processor) { + if (signatureType instanceof ArrayType && realType instanceof ArrayType) { + return processor.apply(((ArrayType) signatureType).getItemType(), + ((ArrayType) realType).getItemType()); + } else if (signatureType instanceof MapType && realType instanceof MapType) { + return processor.apply(((MapType) signatureType).getKeyType(), ((MapType) realType).getKeyType()) + && processor.apply(((MapType) signatureType).getValueType(), ((MapType) realType).getValueType()); + } else if (signatureType instanceof StructType && realType instanceof StructType) { + throw new AnalysisException("do not support struct type now"); + } else { + return processor.apply(signatureType, realType); + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignatureHelper.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignatureHelper.java index e31a8ab6aa..88cad49481 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignatureHelper.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignatureHelper.java @@ -28,32 +28,203 @@ import org.apache.doris.nereids.types.DataType; import org.apache.doris.nereids.types.DateTimeV2Type; import org.apache.doris.nereids.types.DecimalV2Type; import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; +import org.apache.doris.nereids.types.MapType; +import org.apache.doris.nereids.types.NullType; +import org.apache.doris.nereids.types.StructType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import org.apache.doris.nereids.types.coercion.FollowToArgumentType; import org.apache.doris.nereids.util.ResponsibilityChain; +import org.apache.doris.nereids.util.TypeCoercionUtils; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import java.math.BigDecimal; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; import java.util.function.BiFunction; import java.util.stream.Collectors; /** ComputeSignatureHelper */ public class ComputeSignatureHelper { + /** implementAbstractReturnType */ - public static FunctionSignature implementAbstractReturnType( + public static FunctionSignature implementFollowToArgumentReturnType( FunctionSignature signature, List arguments) { - if (!(signature.returnType instanceof DataType)) { - if (signature.returnType instanceof FollowToArgumentType) { - int argumentIndex = ((FollowToArgumentType) signature.returnType).argumentIndex; - return signature.withReturnType(arguments.get(argumentIndex).getDataType()); - } - throw new AnalysisException("Not implemented abstract return type: " + signature.returnType); + if (signature.returnType instanceof FollowToArgumentType) { + int argumentIndex = ((FollowToArgumentType) signature.returnType).argumentIndex; + return signature.withReturnType(arguments.get(argumentIndex).getDataType()); } return signature; } + private static void collectAnyDataType(DataType sigType, DataType expressionType, + Map> indexToArgumentTypes) { + if (expressionType instanceof NullType) { + if (sigType instanceof ArrayType) { + collectAnyDataType(((ArrayType) sigType).getItemType(), NullType.INSTANCE, indexToArgumentTypes); + } else if (sigType instanceof MapType) { + collectAnyDataType(((MapType) sigType).getKeyType(), NullType.INSTANCE, indexToArgumentTypes); + collectAnyDataType(((MapType) sigType).getValueType(), NullType.INSTANCE, indexToArgumentTypes); + } else if (sigType instanceof StructType) { + throw new AnalysisException("do not support struct type now"); + } else { + if (sigType instanceof AnyDataType && ((AnyDataType) sigType).getIndex() >= 0) { + List dataTypes = indexToArgumentTypes.computeIfAbsent( + ((AnyDataType) sigType).getIndex(), i -> Lists.newArrayList()); + dataTypes.add(expressionType); + } + } + } else if (sigType instanceof ArrayType && expressionType instanceof ArrayType) { + collectAnyDataType(((ArrayType) sigType).getItemType(), + ((ArrayType) expressionType).getItemType(), indexToArgumentTypes); + } else if (sigType instanceof MapType && expressionType instanceof MapType) { + collectAnyDataType(((MapType) sigType).getKeyType(), + ((MapType) expressionType).getKeyType(), indexToArgumentTypes); + collectAnyDataType(((MapType) sigType).getValueType(), + ((MapType) expressionType).getValueType(), indexToArgumentTypes); + } else if (sigType instanceof StructType && expressionType instanceof StructType) { + throw new AnalysisException("do not support struct type now"); + } else { + if (sigType instanceof AnyDataType && ((AnyDataType) sigType).getIndex() >= 0) { + List dataTypes = indexToArgumentTypes.computeIfAbsent( + ((AnyDataType) sigType).getIndex(), i -> Lists.newArrayList()); + dataTypes.add(expressionType); + } + } + } + + private static void collectFollowToAnyDataType(DataType sigType, DataType expressionType, + Map> indexToArgumentTypes, Set allNullTypeIndex) { + if (expressionType instanceof NullType) { + if (sigType instanceof ArrayType) { + collectFollowToAnyDataType(((ArrayType) sigType).getItemType(), + NullType.INSTANCE, indexToArgumentTypes, allNullTypeIndex); + } else if (sigType instanceof MapType) { + collectFollowToAnyDataType(((MapType) sigType).getKeyType(), + NullType.INSTANCE, indexToArgumentTypes, allNullTypeIndex); + collectFollowToAnyDataType(((MapType) sigType).getValueType(), + NullType.INSTANCE, indexToArgumentTypes, allNullTypeIndex); + } else if (sigType instanceof StructType) { + throw new AnalysisException("do not support struct type now"); + } else { + if (sigType instanceof FollowToAnyDataType + && allNullTypeIndex.contains(((FollowToAnyDataType) sigType).getIndex())) { + List dataTypes = indexToArgumentTypes.computeIfAbsent( + ((FollowToAnyDataType) sigType).getIndex(), i -> Lists.newArrayList()); + dataTypes.add(expressionType); + } + } + } else if (sigType instanceof ArrayType && expressionType instanceof ArrayType) { + collectFollowToAnyDataType(((ArrayType) sigType).getItemType(), + ((ArrayType) expressionType).getItemType(), indexToArgumentTypes, allNullTypeIndex); + } else if (sigType instanceof MapType && expressionType instanceof MapType) { + collectFollowToAnyDataType(((MapType) sigType).getKeyType(), + ((MapType) expressionType).getKeyType(), indexToArgumentTypes, allNullTypeIndex); + collectFollowToAnyDataType(((MapType) sigType).getValueType(), + ((MapType) expressionType).getValueType(), indexToArgumentTypes, allNullTypeIndex); + } else if (sigType instanceof StructType && expressionType instanceof StructType) { + throw new AnalysisException("do not support struct type now"); + } else { + if (sigType instanceof FollowToAnyDataType + && allNullTypeIndex.contains(((FollowToAnyDataType) sigType).getIndex())) { + List dataTypes = indexToArgumentTypes.computeIfAbsent( + ((FollowToAnyDataType) sigType).getIndex(), i -> Lists.newArrayList()); + dataTypes.add(expressionType); + } + } + } + + private static DataType replaceAnyDataType(DataType dataType, + Map> indexToCommonTypes) { + if (dataType instanceof ArrayType) { + return ArrayType.of(replaceAnyDataType(((ArrayType) dataType).getItemType(), indexToCommonTypes)); + } else if (dataType instanceof MapType) { + return MapType.of(replaceAnyDataType(((MapType) dataType).getKeyType(), indexToCommonTypes), + replaceAnyDataType(((MapType) dataType).getValueType(), indexToCommonTypes)); + } else if (dataType instanceof StructType) { + throw new AnalysisException("do not support struct type now"); + } else { + if (dataType instanceof AnyDataType && ((AnyDataType) dataType).getIndex() >= 0) { + Optional optionalDataType = indexToCommonTypes.get(((AnyDataType) dataType).getIndex()); + if (optionalDataType != null && optionalDataType.isPresent()) { + return optionalDataType.get(); + } + } else if (dataType instanceof FollowToAnyDataType) { + Optional optionalDataType = indexToCommonTypes.get( + ((FollowToAnyDataType) dataType).getIndex()); + if (optionalDataType != null && optionalDataType.isPresent()) { + return optionalDataType.get(); + } + } + return dataType; + } + } + + /** implementFollowToAnyDataType */ + public static FunctionSignature implementAnyDataTypeWithIndex( + FunctionSignature signature, List arguments) { + // collect all any data type with index + Map> indexToArgumentTypes = Maps.newHashMap(); + Map> indexToCommonTypes = Maps.newHashMap(); + for (int i = 0; i < arguments.size(); i++) { + DataType sigType; + if (i >= signature.argumentsTypes.size()) { + sigType = signature.getVarArgType().orElseThrow( + () -> new IllegalStateException("function arity not match with signature")); + } else { + sigType = signature.argumentsTypes.get(i); + } + DataType expressionType = arguments.get(i).getDataType(); + collectAnyDataType(sigType, expressionType, indexToArgumentTypes); + } + // if all any data type's expression is NULL, we should use follow to any data type to do type coercion + Set allNullTypeIndex = indexToArgumentTypes.entrySet().stream() + .filter(entry -> entry.getValue().stream().allMatch(NullType.class::isInstance)) + .map(Entry::getKey) + .collect(ImmutableSet.toImmutableSet()); + if (!allNullTypeIndex.isEmpty()) { + for (int i = 0; i < arguments.size(); i++) { + DataType sigType; + if (i >= signature.argumentsTypes.size()) { + sigType = signature.getVarArgType().orElseThrow( + () -> new IllegalStateException("function arity not match with signature")); + } else { + sigType = signature.argumentsTypes.get(i); + } + DataType expressionType = arguments.get(i).getDataType(); + collectFollowToAnyDataType(sigType, expressionType, indexToArgumentTypes, allNullTypeIndex); + } + } + + // get all common type for any data type + for (Map.Entry> dataTypes : indexToArgumentTypes.entrySet()) { + // TODO: should use the same common type method of implicitCast + Optional dataType = TypeCoercionUtils.findWiderCommonTypeForComparison(dataTypes.getValue()); + // TODO: should we use tinyint when all any data type's expression is null type? + // if (dataType.isPresent() && dataType.get() instanceof NullType) { + // dataType = Optional.of(TinyIntType.INSTANCE); + // } + indexToCommonTypes.put(dataTypes.getKey(), dataType); + } + + // replace any data type and follow to any data type with real data type + List newArgTypes = Lists.newArrayList(); + for (DataType sigType : signature.argumentsTypes) { + newArgTypes.add(replaceAnyDataType(sigType, indexToCommonTypes)); + } + signature = signature.withArgumentTypes(signature.hasVarArgs, newArgTypes); + DataType returnType = replaceAnyDataType(signature.returnType, indexToCommonTypes); + signature = signature.withReturnType(returnType); + return signature; + } + public static FunctionSignature normalizeDecimalV2( FunctionSignature signature, List arguments) { if ((signature.returnType instanceof DecimalV2Type && signature.returnType != DecimalV2Type.SYSTEM_DEFAULT)) { @@ -65,9 +236,6 @@ public class ComputeSignatureHelper { /** computePrecision */ public static FunctionSignature computePrecision( ComputeSignature computeSignature, FunctionSignature signature, List arguments) { - if (!(signature.returnType instanceof DataType)) { - return signature; - } if (computeSignature instanceof DateTimeWithPrecision) { return signature; } @@ -112,7 +280,7 @@ public class ComputeSignatureHelper { FunctionSignature signature, List arguments) { DateTimeV2Type finalType = null; for (int i = 0; i < arguments.size(); i++) { - AbstractDataType targetType; + DataType targetType; if (i >= signature.argumentsTypes.size()) { Preconditions.checkState(signature.getVarArgType().isPresent(), "argument size larger than signature"); @@ -137,7 +305,7 @@ public class ComputeSignatureHelper { } } DateTimeV2Type argType = finalType; - List newArgTypes = signature.argumentsTypes.stream().map(t -> { + List newArgTypes = signature.argumentsTypes.stream().map(t -> { if (t instanceof DateTimeV2Type) { return argType; } else { @@ -155,7 +323,7 @@ public class ComputeSignatureHelper { FunctionSignature signature, List arguments) { DataType finalType = null; for (int i = 0; i < arguments.size(); i++) { - AbstractDataType targetType; + DataType targetType; if (i >= signature.argumentsTypes.size()) { Preconditions.checkState(signature.getVarArgType().isPresent(), "argument size larger than signature"); @@ -183,7 +351,7 @@ public class ComputeSignatureHelper { "decimalv3 precision promotion failed."); } DataType argType = finalType; - List newArgTypes = signature.argumentsTypes.stream().map(t -> { + List newArgTypes = signature.argumentsTypes.stream().map(t -> { if (t instanceof DecimalV3Type) { return argType; } else { @@ -198,7 +366,7 @@ public class ComputeSignatureHelper { } static class ComputeSignatureChain { - private ResponsibilityChain computeChain; + private final ResponsibilityChain computeChain; public ComputeSignatureChain( ResponsibilityChain computeChain) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExplicitlyCastableSignature.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExplicitlyCastableSignature.java index 7c3fdc5285..054e2f947e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExplicitlyCastableSignature.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExplicitlyCastableSignature.java @@ -19,8 +19,10 @@ package org.apache.doris.nereids.trees.expressions.functions; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; +import org.apache.doris.nereids.types.DataType; +import org.apache.doris.nereids.types.NullType; import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import java.util.List; @@ -32,16 +34,26 @@ import java.util.List; */ public interface ExplicitlyCastableSignature extends ComputeSignature { + static boolean isExplicitlyCastable(DataType signatureType, DataType realType) { + return ComputeSignature.processComplexType( + signatureType, realType, ExplicitlyCastableSignature::isPrimitiveExplicitlyCastable); + } + /** isExplicitlyCastable */ - static boolean isExplicitlyCastable(AbstractDataType signatureType, AbstractDataType realType) { - if (signatureType instanceof AnyDataType || signatureType.isAssignableFrom(realType)) { + static boolean isPrimitiveExplicitlyCastable(DataType signatureType, DataType realType) { + if (signatureType instanceof AnyDataType + || signatureType instanceof FollowToAnyDataType + || signatureType.isAssignableFrom(realType)) { + return true; + } + if (realType instanceof NullType) { return true; } try { // TODO: copy canCastTo method to DataType return Type.canCastTo(realType.toCatalogDataType(), signatureType.toCatalogDataType()); } catch (Throwable t) { - // the signatureType maybe AbstractDataType and can not cast to catalog data type. + // the signatureType maybe DataType and can not cast to catalog data type. return false; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/IdenticalSignature.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/IdenticalSignature.java index 5b036a1baa..829f9125e4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/IdenticalSignature.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/IdenticalSignature.java @@ -18,7 +18,7 @@ package org.apache.doris.nereids.trees.expressions.functions; import org.apache.doris.catalog.FunctionSignature; -import org.apache.doris.nereids.types.coercion.AbstractDataType; +import org.apache.doris.nereids.types.DataType; import java.util.List; @@ -30,12 +30,12 @@ import java.util.List; */ public interface IdenticalSignature extends ComputeSignature { /** isIdentical */ - static boolean isIdentical(AbstractDataType signatureType, AbstractDataType realType) { + static boolean isIdentical(DataType signatureType, DataType realType) { try { // TODO: copy matchesType to DataType return realType.toCatalogDataType().matchesType(signatureType.toCatalogDataType()); } catch (Throwable t) { - // the signatureType maybe AbstractDataType and can not cast to catalog data type. + // the signatureType maybe DataType and can not cast to catalog data type. return false; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ImplicitlyCastableSignature.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ImplicitlyCastableSignature.java index 56f7bd710c..0a0f2a972f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ImplicitlyCastableSignature.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ImplicitlyCastableSignature.java @@ -20,8 +20,9 @@ package org.apache.doris.nereids.trees.expressions.functions; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.catalog.Type; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; +import org.apache.doris.nereids.types.NullType; import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import java.util.List; @@ -33,9 +34,19 @@ import java.util.List; */ public interface ImplicitlyCastableSignature extends ComputeSignature { + static boolean isImplicitlyCastable(DataType signatureType, DataType realType) { + return ComputeSignature.processComplexType( + signatureType, realType, ImplicitlyCastableSignature::isPrimitiveImplicitlyCastable); + } + /** isImplicitlyCastable */ - static boolean isImplicitlyCastable(AbstractDataType signatureType, AbstractDataType realType) { - if (signatureType instanceof AnyDataType || signatureType.isAssignableFrom(realType)) { + static boolean isPrimitiveImplicitlyCastable(DataType signatureType, DataType realType) { + if (signatureType instanceof AnyDataType + || signatureType instanceof FollowToAnyDataType + || signatureType.isAssignableFrom(realType)) { + return true; + } + if (realType instanceof NullType) { return true; } try { @@ -43,14 +54,16 @@ public interface ImplicitlyCastableSignature extends ComputeSignature { if (Type.isImplicitlyCastable(realType.toCatalogDataType(), signatureType.toCatalogDataType(), true)) { return true; } - if (realType instanceof DataType) { - List allPromotions = ((DataType) realType).getAllPromotions(); - if (allPromotions.stream().anyMatch(promotion -> isImplicitlyCastable(signatureType, promotion))) { - return true; - } + } catch (Throwable t) { + // the signatureType maybe DataType and can not cast to catalog data type. + } + try { + List allPromotions = realType.getAllPromotions(); + if (allPromotions.stream().anyMatch(promotion -> isImplicitlyCastable(signatureType, promotion))) { + return true; } } catch (Throwable t) { - // the signatureType maybe AbstractDataType and can not cast to catalog data type. + // the signatureType maybe DataType and can not cast to catalog data type. } return false; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/NullOrIdenticalSignature.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/NullOrIdenticalSignature.java index 0e8913d660..5ed0bea656 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/NullOrIdenticalSignature.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/NullOrIdenticalSignature.java @@ -18,8 +18,8 @@ package org.apache.doris.nereids.trees.expressions.functions; import org.apache.doris.catalog.FunctionSignature; +import org.apache.doris.nereids.types.DataType; import org.apache.doris.nereids.types.NullType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import java.util.List; @@ -31,13 +31,13 @@ import java.util.List; */ public interface NullOrIdenticalSignature extends ComputeSignature { /** isNullOrIdentical */ - static boolean isNullOrIdentical(AbstractDataType signatureType, AbstractDataType realType) { + static boolean isNullOrIdentical(DataType signatureType, DataType realType) { try { // TODO: copy matchesType to DataType return realType instanceof NullType || realType.toCatalogDataType().matchesType(signatureType.toCatalogDataType()); } catch (Throwable t) { - // the signatureType maybe AbstractDataType and can not cast to catalog data type. + // the signatureType maybe DataType and can not cast to catalog data type. return false; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/SearchSignature.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/SearchSignature.java index 496b51d9ca..1898c93a3b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/SearchSignature.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/SearchSignature.java @@ -26,7 +26,6 @@ import org.apache.doris.nereids.types.DataType; import org.apache.doris.nereids.types.DateType; import org.apache.doris.nereids.types.DateV2Type; import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.util.TypeCoercionUtils; import com.google.common.collect.Lists; @@ -50,7 +49,7 @@ public class SearchSignature { // param1: signature type // param2: real argument type // return: is the real argument type matches the signature type? - private final List> typePredicatePerRound + private final List> typePredicatePerRound = Lists.newArrayList(); private SearchSignature(ComputeSignature computeSignature, @@ -65,7 +64,7 @@ public class SearchSignature { return new SearchSignature(computeSignature, signatures, arguments); } - public SearchSignature orElseSearch(BiFunction typePredicate) { + public SearchSignature orElseSearch(BiFunction typePredicate) { typePredicatePerRound.add(typePredicate); return this; } @@ -76,7 +75,7 @@ public class SearchSignature { */ public Optional result() { // search every round - for (BiFunction typePredicate : typePredicatePerRound) { + for (BiFunction typePredicate : typePredicatePerRound) { int candidateNonStrictMatched = Integer.MAX_VALUE; int candidateDateToDateV2Count = Integer.MIN_VALUE; FunctionSignature candidate = null; @@ -134,7 +133,7 @@ public class SearchSignature { private boolean checkDecimalV3Precision(FunctionSignature signature) { DataType finalType = null; for (int i = 0; i < arguments.size(); i++) { - AbstractDataType targetType; + DataType targetType; if (i >= signature.argumentsTypes.size()) { if (signature.getVarArgType().isPresent()) { targetType = signature.getVarArgType().get(); @@ -144,10 +143,7 @@ public class SearchSignature { } else { targetType = signature.getArgType(i); } - if (!(targetType instanceof DataType)) { - continue; - } - if (!((DataType) targetType).isDecimalV3Type()) { + if (!targetType.isDecimalV3Type()) { continue; } if (finalType == null) { @@ -189,8 +185,8 @@ public class SearchSignature { int dateToDateV2Count = 0; int arity = arguments.size(); for (int i = 0; i < arity; i++) { - AbstractDataType sigArgType = sig.getArgType(i); - AbstractDataType realType = arguments.get(i).getDataType(); + DataType sigArgType = sig.getArgType(i); + DataType realType = arguments.get(i).getDataType(); if (!IdenticalSignature.isIdentical(sigArgType, realType)) { nonStrictMatched++; if (sigArgType instanceof DateV2Type && realType instanceof DateType) { @@ -202,17 +198,17 @@ public class SearchSignature { } private boolean doMatchTypes(FunctionSignature sig, List arguments, - BiFunction typePredicate) { + BiFunction typePredicate) { int arity = arguments.size(); for (int i = 0; i < arity; i++) { - AbstractDataType sigArgType = sig.getArgType(i); + DataType sigArgType = sig.getArgType(i); DataType realType = arguments.get(i).getDataType(); // we need to try to do string literal coercion when search signature. // for example, FUNC_A has two signature FUNC_A(datetime) and FUNC_A(string) // if SQL block is `FUNC_A('2020-02-02 00:00:00')`, we should return signature FUNC_A(datetime). - if (arguments.get(i).isLiteral() && realType.isStringLikeType() && sigArgType instanceof DataType) { + if (arguments.get(i).isLiteral() && realType.isStringLikeType()) { realType = TypeCoercionUtils.characterLiteralTypeCoercion(((Literal) arguments.get(i)).getStringValue(), - (DataType) sigArgType).orElse(arguments.get(i)).getDataType(); + sigArgType).orElse(arguments.get(i)).getDataType(); } if (!typePredicate.apply(sigArgType, realType)) { return false; @@ -221,7 +217,7 @@ public class SearchSignature { return true; } - private static void throwCanNotFoundFunctionException(String name, List arguments) { + public static void throwCanNotFoundFunctionException(String name, List arguments) { String missingSignature = name + arguments.stream() .map(Expression::getDataType) .map(DataType::toSql) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/AnyValue.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/AnyValue.java index 78743cd89c..aafc8d3599 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/AnyValue.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/AnyValue.java @@ -37,7 +37,7 @@ public class AnyValue extends AggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.retArgType(0).args(AnyDataType.INSTANCE) + FunctionSignature.retArgType(0).args(AnyDataType.INSTANCE_WITHOUT_INDEX) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CollectList.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CollectList.java index 32f8fd4a81..9e02435ef5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CollectList.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CollectList.java @@ -24,21 +24,9 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.CharType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -52,21 +40,9 @@ public class CollectList extends AggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)).args(BooleanType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)).args(TinyIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)).args(SmallIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)).args(IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)).args(LargeIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)).args(FloatType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).args(DoubleType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.CATALOG_DEFAULT)).args(DecimalV2Type.CATALOG_DEFAULT), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)).args(DateType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)).args(DateTimeType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE)).args(DateV2Type.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)).args(DateTimeV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(ArrayType.of(CharType.SYSTEM_DEFAULT)).args(CharType.SYSTEM_DEFAULT), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)).args(StringType.INSTANCE) + FunctionSignature.ret(ArrayType.of(new FollowToAnyDataType(0))).args(new AnyDataType(0)), + FunctionSignature.ret(ArrayType.of(new FollowToAnyDataType(0))) + .args(new AnyDataType(0), IntegerType.INSTANCE) ); /** @@ -76,6 +52,13 @@ public class CollectList extends AggregateFunction super("collect_list", arg); } + /** + * constructor with 2 argument. + */ + public CollectList(Expression arg0, Expression arg1) { + super("collect_list", arg0, arg1); + } + /** * constructor with 1 argument. */ @@ -83,6 +66,13 @@ public class CollectList extends AggregateFunction super("collect_list", distinct, arg); } + /** + * constructor with 2 argument. + */ + public CollectList(boolean distinct, Expression arg0, Expression arg1) { + super("collect_list", distinct, arg0, arg1); + } + @Override public FunctionSignature computeSignature(FunctionSignature signature) { signature = signature.withReturnType(ArrayType.of(getArgumentType(0))); @@ -94,8 +84,12 @@ public class CollectList extends AggregateFunction */ @Override public CollectList withDistinctAndChildren(boolean distinct, List children) { - Preconditions.checkArgument(children.size() == 1); - return new CollectList(distinct, children.get(0)); + Preconditions.checkArgument(children.size() == 1 || children.size() == 2); + if (children.size() == 1) { + return new CollectList(distinct, children.get(0)); + } else { + return new CollectList(distinct, children.get(0), children.get(1)); + } } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CollectSet.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CollectSet.java index 911edb803d..57af28a957 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CollectSet.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/CollectSet.java @@ -24,21 +24,9 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.CharType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -52,21 +40,9 @@ public class CollectSet extends AggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)).args(BooleanType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)).args(TinyIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)).args(SmallIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)).args(IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)).args(LargeIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)).args(FloatType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).args(DoubleType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.CATALOG_DEFAULT)).args(DecimalV2Type.CATALOG_DEFAULT), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)).args(DateType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)).args(DateTimeType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE)).args(DateV2Type.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)).args(DateTimeV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(ArrayType.of(CharType.SYSTEM_DEFAULT)).args(CharType.SYSTEM_DEFAULT), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)).args(StringType.INSTANCE) + FunctionSignature.ret(ArrayType.of(new FollowToAnyDataType(0))).args(new AnyDataType(0)), + FunctionSignature.ret(ArrayType.of(new FollowToAnyDataType(0))) + .args(new AnyDataType(0), IntegerType.INSTANCE) ); /** @@ -76,6 +52,13 @@ public class CollectSet extends AggregateFunction super("collect_set", arg); } + /** + * constructor with 1 argument. + */ + public CollectSet(Expression arg0, Expression arg1) { + super("collect_set", arg0, arg1); + } + /** * constructor with 1 argument. */ @@ -83,6 +66,13 @@ public class CollectSet extends AggregateFunction super("collect_set", distinct, arg); } + /** + * constructor with 1 argument. + */ + public CollectSet(boolean distinct, Expression arg0, Expression arg1) { + super("collect_set", distinct, arg0, arg1); + } + @Override public FunctionSignature computeSignature(FunctionSignature signature) { signature = signature.withReturnType(ArrayType.of(getArgumentType(0))); @@ -94,8 +84,12 @@ public class CollectSet extends AggregateFunction */ @Override public CollectSet withDistinctAndChildren(boolean distinct, List children) { - Preconditions.checkArgument(children.size() == 1); - return new CollectSet(distinct, children.get(0)); + Preconditions.checkArgument(children.size() == 1 || children.size() == 2); + if (children.size() == 1) { + return new CollectSet(distinct, children.get(0)); + } else { + return new CollectSet(distinct, children.get(0), children.get(1)); + } } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Count.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Count.java index 1defb09d46..a9fe3a688b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Count.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Count.java @@ -42,7 +42,7 @@ public class Count extends AggregateFunction public static final List SIGNATURES = ImmutableList.of( // count(*) FunctionSignature.ret(BigIntType.INSTANCE).args(), - FunctionSignature.ret(BigIntType.INSTANCE).varArgs(AnyDataType.INSTANCE) + FunctionSignature.ret(BigIntType.INSTANCE).varArgs(AnyDataType.INSTANCE_WITHOUT_INDEX) ); private final boolean isStar; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupConcat.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupConcat.java index 68f94433be..0f2e7bcb03 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupConcat.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/GroupConcat.java @@ -42,9 +42,9 @@ public class GroupConcat extends NullableAggregateFunction public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).args(VarcharType.SYSTEM_DEFAULT), FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .varArgs(VarcharType.SYSTEM_DEFAULT, AnyDataType.INSTANCE), + .varArgs(VarcharType.SYSTEM_DEFAULT, AnyDataType.INSTANCE_WITHOUT_INDEX), FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .varArgs(VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT, AnyDataType.INSTANCE) + .varArgs(VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT, AnyDataType.INSTANCE_WITHOUT_INDEX) ); private final int nonOrderArguments; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MaxBy.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MaxBy.java index 55ce8623a7..17243e5d41 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MaxBy.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MaxBy.java @@ -38,7 +38,7 @@ public class MaxBy extends NullableAggregateFunction implements BinaryExpression, ExplicitlyCastableSignature { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.retArgType(0).args(AnyDataType.INSTANCE, AnyDataType.INSTANCE) + FunctionSignature.retArgType(0).args(AnyDataType.INSTANCE_WITHOUT_INDEX, AnyDataType.INSTANCE_WITHOUT_INDEX) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MinBy.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MinBy.java index 42989e282f..34cbf93362 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MinBy.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MinBy.java @@ -38,7 +38,7 @@ public class MinBy extends NullableAggregateFunction implements BinaryExpression, ExplicitlyCastableSignature { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.retArgType(0).args(AnyDataType.INSTANCE, AnyDataType.INSTANCE) + FunctionSignature.retArgType(0).args(AnyDataType.INSTANCE_WITHOUT_INDEX, AnyDataType.INSTANCE_WITHOUT_INDEX) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java index b9e7c1fdb1..3244ae563d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java @@ -38,7 +38,7 @@ public class MultiDistinctCount extends AggregateFunction implements AlwaysNotNullable, ExplicitlyCastableSignature, MultiDistinction { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BigIntType.INSTANCE).varArgs(AnyDataType.INSTANCE) + FunctionSignature.ret(BigIntType.INSTANCE).varArgs(AnyDataType.INSTANCE_WITHOUT_INDEX) ); // MultiDistinctCount is created in AggregateStrategies phase diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java index 5f5bb6815a..d400315ad4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctGroupConcat.java @@ -41,21 +41,21 @@ public class MultiDistinctGroupConcat extends NullableAggregateFunction public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).args(VarcharType.SYSTEM_DEFAULT), FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).varArgs(VarcharType.SYSTEM_DEFAULT, - AnyDataType.INSTANCE), + AnyDataType.INSTANCE_WITHOUT_INDEX), FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).varArgs(VarcharType.SYSTEM_DEFAULT, - VarcharType.SYSTEM_DEFAULT, AnyDataType.INSTANCE), + VarcharType.SYSTEM_DEFAULT, AnyDataType.INSTANCE_WITHOUT_INDEX), FunctionSignature.ret(StringType.INSTANCE).args(StringType.INSTANCE), FunctionSignature.ret(StringType.INSTANCE).varArgs(StringType.INSTANCE, - AnyDataType.INSTANCE), + AnyDataType.INSTANCE_WITHOUT_INDEX), FunctionSignature.ret(StringType.INSTANCE).varArgs(StringType.INSTANCE, - StringType.INSTANCE, AnyDataType.INSTANCE), + StringType.INSTANCE, AnyDataType.INSTANCE_WITHOUT_INDEX), FunctionSignature.ret(CharType.SYSTEM_DEFAULT).args(CharType.SYSTEM_DEFAULT), FunctionSignature.ret(CharType.SYSTEM_DEFAULT).varArgs(CharType.SYSTEM_DEFAULT, - AnyDataType.INSTANCE), + AnyDataType.INSTANCE_WITHOUT_INDEX), FunctionSignature.ret(CharType.SYSTEM_DEFAULT).varArgs(CharType.SYSTEM_DEFAULT, - CharType.SYSTEM_DEFAULT, AnyDataType.INSTANCE)); + CharType.SYSTEM_DEFAULT, AnyDataType.INSTANCE_WITHOUT_INDEX)); private final int nonOrderArguments; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Ndv.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Ndv.java index 337ab708d9..08503bf887 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Ndv.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Ndv.java @@ -40,7 +40,7 @@ public class Ndv extends AggregateFunction implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BigIntType.INSTANCE).args(AnyDataType.INSTANCE) + FunctionSignature.ret(BigIntType.INSTANCE).args(AnyDataType.INSTANCE_WITHOUT_INDEX) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNArray.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNArray.java index 85f9e032f2..6a63a5e1c8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNArray.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/TopNArray.java @@ -23,21 +23,9 @@ import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSi import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.CharType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -51,57 +39,10 @@ public class TopNArray extends AggregateFunction implements ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)).args(BooleanType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)).args(TinyIntType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) - .args(SmallIntType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)).args(IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(BigIntType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) - .args(LargeIntType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)).args(FloatType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).args(DoubleType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.CATALOG_DEFAULT)) - .args(DecimalV2Type.CATALOG_DEFAULT, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)).args(DateType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)) - .args(DateTimeType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE)).args(DateV2Type.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) - .args(DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(CharType.SYSTEM_DEFAULT)) - .args(CharType.SYSTEM_DEFAULT, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)).args(StringType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) - .args(BooleanType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) - .args(TinyIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) - .args(SmallIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) - .args(IntegerType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) - .args(BigIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) - .args(LargeIntType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) - .args(FloatType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) - .args(DoubleType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.CATALOG_DEFAULT)) - .args(DecimalV2Type.CATALOG_DEFAULT, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)) - .args(DateType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)) - .args(DateTimeType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE)) - .args(DateV2Type.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) - .args(DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(CharType.SYSTEM_DEFAULT)) - .args(CharType.SYSTEM_DEFAULT, IntegerType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)) - .args(StringType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE) + FunctionSignature.ret(ArrayType.of(new FollowToAnyDataType(0))) + .args(new AnyDataType(0), IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(new FollowToAnyDataType(0))) + .args(new AnyDataType(0), IntegerType.INSTANCE, IntegerType.INSTANCE) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Array.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Array.java index faaef0ccd1..a377cec5f9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Array.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Array.java @@ -21,30 +21,20 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.util.TypeCoercionUtils; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * ScalarFunction 'array'. This class is generated by GenerateFunction. @@ -53,23 +43,7 @@ public class Array extends ScalarFunction implements ExplicitlyCastableSignature, AlwaysNotNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.SYSTEM_DEFAULT).args(), - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)).varArgs(BooleanType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)).varArgs(TinyIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)).varArgs(SmallIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)).varArgs(IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).varArgs(BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)).varArgs(LargeIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)).varArgs(DateTimeType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)).varArgs(DateType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)).varArgs(DateTimeV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE)).varArgs(DateV2Type.INSTANCE), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)).varArgs(FloatType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).varArgs(DoubleType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)).varArgs(DecimalV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)).varArgs(DecimalV3Type.WILDCARD), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)).varArgs(VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)).varArgs(StringType.INSTANCE) + FunctionSignature.ret(ArrayType.SYSTEM_DEFAULT).args() ); /** @@ -79,41 +53,12 @@ public class Array extends ScalarFunction super("array", varArgs); } - @Override - public FunctionSignature computeSignature(FunctionSignature signature) { - if (arity() > 0) { - signature = signature.withReturnType(ArrayType.of(getArgumentType(0))); - } - return super.computeSignature(signature); - } - - @Override - protected Expression uncheckedCastTo(DataType targetType) { - if (targetType instanceof ArrayType) { - ArrayType arrayType = (ArrayType) targetType; - DataType castItemType = arrayType.getItemType(); - boolean hasCast = false; - List newArguments = Lists.newArrayList(); - for (int i = 0; i < arity(); i++) { - Expression argument = getArgument(i); - if (!argument.getDataType().equals(castItemType)) { - hasCast = true; - newArguments.add(argument.castTo(castItemType)); - } else { - newArguments.add(argument); - } - } - return hasCast ? new Array(newArguments.stream().toArray(Expression[]::new)) : this; - } - return super.uncheckedCastTo(targetType); - } - /** * withChildren. */ @Override public Array withChildren(List children) { - return new Array(children.stream().toArray(Expression[]::new)); + return new Array(children.toArray(new Expression[0])); } @Override @@ -123,6 +68,20 @@ public class Array extends ScalarFunction @Override public List getSignatures() { - return SIGNATURES; + if (arity() == 0) { + return SIGNATURES; + } else { + Map> partitioned = children.stream() + .map(ExpressionTrait::getDataType) + .collect(Collectors.partitioningBy(TypeCoercionUtils::hasCharacterType)); + List needTypeCoercion = Lists.newArrayList(Sets.newHashSet(partitioned.get(true))); + if (needTypeCoercion.size() > 1 || !partitioned.get(false).isEmpty()) { + needTypeCoercion = Lists.newArrayList(StringType.INSTANCE); + } + needTypeCoercion.addAll(partitioned.get(false)); + return needTypeCoercion.stream() + .map(dataType -> FunctionSignature.ret(ArrayType.of(dataType)).varArgs(dataType)) + .collect(ImmutableList.toImmutableList()); + } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayAvg.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayAvg.java index 781d583149..eac07935a3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayAvg.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayAvg.java @@ -20,6 +20,8 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.ComputePrecisionForArrayItemAgg; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; @@ -42,8 +44,8 @@ import java.util.List; /** * ScalarFunction 'array_avg'. This class is generated by GenerateFunction. */ -public class ArrayAvg extends CompatibleTypeArrayFunction - implements UnaryExpression, AlwaysNullable { +public class ArrayAvg extends ScalarFunction implements ExplicitlyCastableSignature, + ComputePrecisionForArrayItemAgg, UnaryExpression, AlwaysNullable { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE)), @@ -52,10 +54,10 @@ public class ArrayAvg extends CompatibleTypeArrayFunction FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(IntegerType.INSTANCE)), FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(BigIntType.INSTANCE)), FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(DoubleType.INSTANCE)), + FunctionSignature.ret(DecimalV3Type.WILDCARD).args(ArrayType.of(DecimalV3Type.WILDCARD)), FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(DecimalV3Type.WILDCARD).args(ArrayType.of(DecimalV3Type.WILDCARD)) + FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(FloatType.INSTANCE)), + FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(DoubleType.INSTANCE)) ); /** @@ -65,6 +67,35 @@ public class ArrayAvg extends CompatibleTypeArrayFunction super("array_avg", arg); } + // TODO use this computePrecision if be support dynamic scale + // @Override + // public FunctionSignature computePrecision(FunctionSignature signature) { + // DataType argumentType = getArgumentType(0); + // if (argumentType instanceof ArrayType) { + // DataType argType = ((ArrayType) argumentType).getItemType(); + // DataType sigType = ((ArrayType) signature.getArgType(0)).getItemType(); + // if (sigType instanceof DecimalV3Type) { + // DecimalV3Type decimalV3Type = DecimalV3Type.forType(argType); + // // DecimalV3 scale lower than DEFAULT_MIN_AVG_DECIMAL128_SCALE should do cast + // int precision = decimalV3Type.getPrecision(); + // int scale = decimalV3Type.getScale(); + // if (decimalV3Type.getScale() < ScalarType.DEFAULT_MIN_AVG_DECIMAL128_SCALE) { + // scale = ScalarType.DEFAULT_MIN_AVG_DECIMAL128_SCALE; + // precision = precision - decimalV3Type.getScale() + scale; + // if (precision > DecimalV3Type.MAX_DECIMAL128_PRECISION) { + // precision = DecimalV3Type.MAX_DECIMAL128_PRECISION; + // } + // } + // decimalV3Type = DecimalV3Type.createDecimalV3Type(precision, scale); + // return signature.withArgumentType(0, ArrayType.of(decimalV3Type)) + // .withReturnType(ArrayType.of(DecimalV3Type.createDecimalV3Type( + // DecimalV3Type.MAX_DECIMAL128_PRECISION, decimalV3Type.getScale() + // ))); + // } + // } + // return signature; + // } + /** * withChildren. */ diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayCompact.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayCompact.java index 2cb565c362..d631be46cf 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayCompact.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayCompact.java @@ -24,21 +24,7 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -52,25 +38,7 @@ public class ArrayCompact extends ScalarFunction implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)).args(ArrayType.of(BooleanType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)).args(ArrayType.of(TinyIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)).args(ArrayType.of(SmallIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)).args(ArrayType.of(IntegerType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(BigIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)).args(ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)).args(ArrayType.of(DateTimeType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)).args(ArrayType.of(DateType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE)).args(ArrayType.of(DateV2Type.INSTANCE)), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)).args(ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).args(ArrayType.of(DoubleType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(ArrayType.of(DecimalV3Type.WILDCARD)), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) + FunctionSignature.retArgType(0).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX)) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayContains.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayContains.java index 1f5e7808f9..9b02b6ce76 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayContains.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayContains.java @@ -24,22 +24,9 @@ import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSi 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.BigIntType; import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -53,29 +40,8 @@ public class ArrayContains extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BooleanType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE), BooleanType.INSTANCE), - FunctionSignature.ret(BooleanType.INSTANCE).args(ArrayType.of(TinyIntType.INSTANCE), TinyIntType.INSTANCE), FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(SmallIntType.INSTANCE), SmallIntType.INSTANCE), - FunctionSignature.ret(BooleanType.INSTANCE).args(ArrayType.of(IntegerType.INSTANCE), IntegerType.INSTANCE), - FunctionSignature.ret(BooleanType.INSTANCE).args(ArrayType.of(BigIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(LargeIntType.INSTANCE), LargeIntType.INSTANCE), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(DateTimeType.INSTANCE), DateTimeType.INSTANCE), - FunctionSignature.ret(BooleanType.INSTANCE).args(ArrayType.of(DateType.INSTANCE), DateType.INSTANCE), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT), DateTimeV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(BooleanType.INSTANCE).args(ArrayType.of(DateV2Type.INSTANCE), DateV2Type.INSTANCE), - FunctionSignature.ret(BooleanType.INSTANCE).args(ArrayType.of(FloatType.INSTANCE), FloatType.INSTANCE), - FunctionSignature.ret(BooleanType.INSTANCE).args(ArrayType.of(DoubleType.INSTANCE), DoubleType.INSTANCE), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), DecimalV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(DecimalV3Type.WILDCARD), DecimalV3Type.WILDCARD), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(BooleanType.INSTANCE).args(ArrayType.of(StringType.INSTANCE), StringType.INSTANCE) + .args(ArrayType.of(new AnyDataType(0)), new FollowToAnyDataType(0)) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayPopback.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayCumSum.java similarity index 60% rename from fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayPopback.java rename to fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayCumSum.java index 628b0de33e..f3f0e54e5c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayPopback.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayCumSum.java @@ -19,15 +19,13 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.ComputePrecisionForArrayItemAgg; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateType; import org.apache.doris.nereids.types.DecimalV2Type; import org.apache.doris.nereids.types.DecimalV3Type; import org.apache.doris.nereids.types.DoubleType; @@ -35,9 +33,7 @@ import org.apache.doris.nereids.types.FloatType; import org.apache.doris.nereids.types.IntegerType; import org.apache.doris.nereids.types.LargeIntType; import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -45,50 +41,43 @@ import com.google.common.collect.ImmutableList; import java.util.List; /** - * ScalarFunction 'array_popback'. This class is generated by GenerateFunction. + * ScalarFunction 'array_min'. This class is generated by GenerateFunction. */ -public class ArrayPopback extends ScalarFunction - implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { +public class ArrayCumSum extends ScalarFunction + implements ExplicitlyCastableSignature, ComputePrecisionForArrayItemAgg, UnaryExpression, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)).args(ArrayType.of(BooleanType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)).args(ArrayType.of(TinyIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)).args(ArrayType.of(SmallIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)).args(ArrayType.of(IntegerType.INSTANCE)), + FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(TinyIntType.INSTANCE)), + FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(SmallIntType.INSTANCE)), + FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(IntegerType.INSTANCE)), FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(BigIntType.INSTANCE)), FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)).args(ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)).args(ArrayType.of(DateTimeType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)).args(ArrayType.of(DateType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)).args(ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).args(ArrayType.of(DoubleType.INSTANCE)), + FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)).args(ArrayType.of(DecimalV3Type.WILDCARD)), FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(ArrayType.of(DecimalV3Type.WILDCARD)), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)).args(ArrayType.of(StringType.INSTANCE)) + FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).args(ArrayType.of(FloatType.INSTANCE)), + FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).args(ArrayType.of(DoubleType.INSTANCE)) ); /** * constructor with 1 argument. */ - public ArrayPopback(Expression arg) { - super("array_popback", arg); + public ArrayCumSum(Expression arg) { + super("array_cum_sum", arg); } /** * withChildren. */ @Override - public ArrayPopback withChildren(List children) { + public ArrayCumSum withChildren(List children) { Preconditions.checkArgument(children.size() == 1); - return new ArrayPopback(children.get(0)); + return new ArrayCumSum(children.get(0)); } @Override public R accept(ExpressionVisitor visitor, C context) { - return visitor.visitArrayPopback(this, context); + return visitor.visitArrayCumSum(this, context); } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayDistinct.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayDistinct.java index a6a97ca389..36f225fec4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayDistinct.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayDistinct.java @@ -19,26 +19,12 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -48,30 +34,11 @@ import java.util.List; /** * ScalarFunction 'array_distinct'. This class is generated by GenerateFunction. */ -public class ArrayDistinct extends CompatibleTypeArrayFunction - implements UnaryExpression, PropagateNullable { +public class ArrayDistinct extends ScalarFunction + implements ExplicitlyCastableSignature, UnaryExpression, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)).args(ArrayType.of(BooleanType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)).args(ArrayType.of(TinyIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)).args(ArrayType.of(SmallIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)).args(ArrayType.of(IntegerType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(BigIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)).args(ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)).args(ArrayType.of(DateTimeType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)).args(ArrayType.of(DateType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE)).args(ArrayType.of(DateV2Type.INSTANCE)), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)).args(ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).args(ArrayType.of(DoubleType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(ArrayType.of(DecimalV3Type.WILDCARD)), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)).args(ArrayType.of(StringType.INSTANCE)) + FunctionSignature.retArgType(0).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX)) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayEnumerate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayEnumerate.java index c3c85004f9..444dc5bedd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayEnumerate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayEnumerate.java @@ -25,21 +25,7 @@ import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -53,22 +39,8 @@ public class ArrayEnumerate extends ScalarFunction implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(BooleanType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(TinyIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(SmallIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(IntegerType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(BigIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(DateTimeType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(DateType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(DateV2Type.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(DoubleType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(DecimalV3Type.WILDCARD)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(VarcharType.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(StringType.INSTANCE)) + FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) + .args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX)) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayExcept.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayExcept.java index dd3c10677e..b87460b766 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayExcept.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayExcept.java @@ -19,26 +19,13 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; 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.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -48,42 +35,12 @@ import java.util.List; /** * ScalarFunction 'array_except'. This class is generated by GenerateFunction. */ -public class ArrayExcept extends CompatibleTypeArrayFunction - implements BinaryExpression, PropagateNullable { +public class ArrayExcept extends ScalarFunction implements ExplicitlyCastableSignature, + BinaryExpression, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) - .args(ArrayType.of(BooleanType.INSTANCE), ArrayType.of(BooleanType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) - .args(ArrayType.of(TinyIntType.INSTANCE), ArrayType.of(TinyIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) - .args(ArrayType.of(SmallIntType.INSTANCE), ArrayType.of(SmallIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) - .args(ArrayType.of(IntegerType.INSTANCE), ArrayType.of(IntegerType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) - .args(ArrayType.of(BigIntType.INSTANCE), ArrayType.of(BigIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) - .args(ArrayType.of(LargeIntType.INSTANCE), ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) - .args(ArrayType.of(FloatType.INSTANCE), ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) - .args(ArrayType.of(DoubleType.INSTANCE), ArrayType.of(DoubleType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(ArrayType.of(DecimalV3Type.WILDCARD), ArrayType.of(DecimalV3Type.WILDCARD)), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)) - .args(ArrayType.of(DateTimeType.INSTANCE), ArrayType.of(DateTimeType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)) - .args(ArrayType.of(DateType.INSTANCE), ArrayType.of(DateType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT), ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE)) - .args(ArrayType.of(DateV2Type.INSTANCE), ArrayType.of(DateV2Type.INSTANCE)), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), ArrayType.of(VarcharType.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)) - .args(ArrayType.of(StringType.INSTANCE), ArrayType.of(StringType.INSTANCE)) + FunctionSignature.retArgType(0) + .args(ArrayType.of(new AnyDataType(0)), ArrayType.of(new FollowToAnyDataType(0))) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayIntersect.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayIntersect.java index 2603ce35a9..0dc4f38151 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayIntersect.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayIntersect.java @@ -19,26 +19,13 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; 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.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -48,42 +35,12 @@ import java.util.List; /** * ScalarFunction 'array_intersect'. This class is generated by GenerateFunction. */ -public class ArrayIntersect extends CompatibleTypeArrayFunction - implements BinaryExpression, PropagateNullable { +public class ArrayIntersect extends ScalarFunction implements ExplicitlyCastableSignature, + BinaryExpression, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) - .args(ArrayType.of(BooleanType.INSTANCE), ArrayType.of(BooleanType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) - .args(ArrayType.of(TinyIntType.INSTANCE), ArrayType.of(TinyIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) - .args(ArrayType.of(SmallIntType.INSTANCE), ArrayType.of(SmallIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) - .args(ArrayType.of(IntegerType.INSTANCE), ArrayType.of(IntegerType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) - .args(ArrayType.of(BigIntType.INSTANCE), ArrayType.of(BigIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) - .args(ArrayType.of(LargeIntType.INSTANCE), ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) - .args(ArrayType.of(FloatType.INSTANCE), ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) - .args(ArrayType.of(DoubleType.INSTANCE), ArrayType.of(DoubleType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(ArrayType.of(DecimalV3Type.WILDCARD), ArrayType.of(DecimalV3Type.WILDCARD)), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)) - .args(ArrayType.of(DateTimeType.INSTANCE), ArrayType.of(DateTimeType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)) - .args(ArrayType.of(DateType.INSTANCE), ArrayType.of(DateType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT), ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE)) - .args(ArrayType.of(DateV2Type.INSTANCE), ArrayType.of(DateV2Type.INSTANCE)), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), ArrayType.of(VarcharType.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)) - .args(ArrayType.of(StringType.INSTANCE), ArrayType.of(StringType.INSTANCE)) + FunctionSignature.retArgType(0) + .args(ArrayType.of(new AnyDataType(0)), ArrayType.of(new FollowToAnyDataType(0))) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayJoin.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayJoin.java index aa83dbc064..0da1ab7875 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayJoin.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayJoin.java @@ -23,22 +23,9 @@ import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSi import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -53,73 +40,10 @@ public class ArrayJoin extends ScalarFunction public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(BooleanType.INSTANCE), VarcharType.SYSTEM_DEFAULT), + .args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX), VarcharType.SYSTEM_DEFAULT), FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(TinyIntType.INSTANCE), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(SmallIntType.INSTANCE), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(IntegerType.INSTANCE), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(BigIntType.INSTANCE), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(LargeIntType.INSTANCE), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(DateTimeType.INSTANCE), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(DateType.INSTANCE), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(DateV2Type.INSTANCE), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(FloatType.INSTANCE), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(DoubleType.INSTANCE), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(DecimalV3Type.WILDCARD), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(StringType.INSTANCE), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(BooleanType.INSTANCE), VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(TinyIntType.INSTANCE), VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(SmallIntType.INSTANCE), VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(IntegerType.INSTANCE), VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(BigIntType.INSTANCE), VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(LargeIntType.INSTANCE), VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(DateTimeType.INSTANCE), VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(DateType.INSTANCE), VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT), - VarcharType.SYSTEM_DEFAULT, - VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(DateV2Type.INSTANCE), VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(FloatType.INSTANCE), VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(DoubleType.INSTANCE), VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), - VarcharType.SYSTEM_DEFAULT, - VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), - VarcharType.SYSTEM_DEFAULT, - VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE) - .args(ArrayType.of(StringType.INSTANCE), VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT) + .args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX), + VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayMax.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayMax.java index 55b3f3fade..c1d0eff1b2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayMax.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayMax.java @@ -20,24 +20,13 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.TinyIntType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -47,24 +36,11 @@ import java.util.List; /** * ScalarFunction 'array_max'. This class is generated by GenerateFunction. */ -public class ArrayMax extends CompatibleTypeArrayFunction - implements UnaryExpression, AlwaysNullable { +public class ArrayMax extends ScalarFunction implements ExplicitlyCastableSignature, + UnaryExpression, AlwaysNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BooleanType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE)), - FunctionSignature.ret(TinyIntType.INSTANCE).args(ArrayType.of(TinyIntType.INSTANCE)), - FunctionSignature.ret(SmallIntType.INSTANCE).args(ArrayType.of(SmallIntType.INSTANCE)), - FunctionSignature.ret(IntegerType.INSTANCE).args(ArrayType.of(IntegerType.INSTANCE)), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BigIntType.INSTANCE)), - FunctionSignature.ret(LargeIntType.INSTANCE).args(ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(FloatType.INSTANCE).args(ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(DoubleType.INSTANCE)), - FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(DecimalV3Type.WILDCARD).args(ArrayType.of(DecimalV3Type.WILDCARD)), - FunctionSignature.ret(DateType.INSTANCE).args(ArrayType.of(DateType.INSTANCE)), - FunctionSignature.ret(DateTimeType.INSTANCE).args(ArrayType.of(DateTimeType.INSTANCE)), - FunctionSignature.ret(DateV2Type.INSTANCE).args(ArrayType.of(DateV2Type.INSTANCE)), - FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) + FunctionSignature.ret(new FollowToAnyDataType(0)).args(ArrayType.of(new AnyDataType(0))) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayMin.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayMin.java index 5106f441a0..dbfba39a2c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayMin.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayMin.java @@ -20,24 +20,13 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.TinyIntType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -47,24 +36,11 @@ import java.util.List; /** * ScalarFunction 'array_min'. This class is generated by GenerateFunction. */ -public class ArrayMin extends CompatibleTypeArrayFunction - implements UnaryExpression, AlwaysNullable { +public class ArrayMin extends ScalarFunction implements ExplicitlyCastableSignature, + UnaryExpression, AlwaysNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BooleanType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE)), - FunctionSignature.ret(TinyIntType.INSTANCE).args(ArrayType.of(TinyIntType.INSTANCE)), - FunctionSignature.ret(SmallIntType.INSTANCE).args(ArrayType.of(SmallIntType.INSTANCE)), - FunctionSignature.ret(IntegerType.INSTANCE).args(ArrayType.of(IntegerType.INSTANCE)), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BigIntType.INSTANCE)), - FunctionSignature.ret(LargeIntType.INSTANCE).args(ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(FloatType.INSTANCE).args(ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(DoubleType.INSTANCE)), - FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(DecimalV3Type.WILDCARD).args(ArrayType.of(DecimalV3Type.WILDCARD)), - FunctionSignature.ret(DateType.INSTANCE).args(ArrayType.of(DateType.INSTANCE)), - FunctionSignature.ret(DateTimeType.INSTANCE).args(ArrayType.of(DateTimeType.INSTANCE)), - FunctionSignature.ret(DateV2Type.INSTANCE).args(ArrayType.of(DateV2Type.INSTANCE)), - FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) + FunctionSignature.ret(new FollowToAnyDataType(0)).args(ArrayType.of(new AnyDataType(0))) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySize.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayPopBack.java similarity index 78% rename from fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySize.java rename to fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayPopBack.java index db5e937f1e..d3847c8c52 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySize.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayPopBack.java @@ -24,7 +24,7 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; +import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -32,34 +32,34 @@ import com.google.common.collect.ImmutableList; import java.util.List; /** - * ScalarFunction 'array_size'. This class is generated by GenerateFunction. + * ScalarFunction 'array_popback'. This class is generated by GenerateFunction. */ -public class ArraySize extends ScalarFunction +public class ArrayPopBack extends ScalarFunction implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.SYSTEM_DEFAULT) + FunctionSignature.retArgType(0).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX)) ); /** * constructor with 1 argument. */ - public ArraySize(Expression arg) { - super("array_size", arg); + public ArrayPopBack(Expression arg) { + super("array_popback", arg); } /** * withChildren. */ @Override - public ArraySize withChildren(List children) { + public ArrayPopBack withChildren(List children) { Preconditions.checkArgument(children.size() == 1); - return new ArraySize(children.get(0)); + return new ArrayPopBack(children.get(0)); } @Override public R accept(ExpressionVisitor visitor, C context) { - return visitor.visitArraySize(this, context); + return visitor.visitArrayPopBack(this, context); } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Size.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayPopFront.java similarity index 78% rename from fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Size.java rename to fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayPopFront.java index ac85ca3023..218e903ff1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Size.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayPopFront.java @@ -24,7 +24,7 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; +import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -32,34 +32,34 @@ import com.google.common.collect.ImmutableList; import java.util.List; /** - * ScalarFunction 'size'. This class is generated by GenerateFunction. + * ScalarFunction 'array_popback'. This class is generated by GenerateFunction. */ -public class Size extends ScalarFunction +public class ArrayPopFront extends ScalarFunction implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.SYSTEM_DEFAULT) + FunctionSignature.retArgType(0).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX)) ); /** * constructor with 1 argument. */ - public Size(Expression arg) { - super("size", arg); + public ArrayPopFront(Expression arg) { + super("array_popfront", arg); } /** * withChildren. */ @Override - public Size withChildren(List children) { + public ArrayPopFront withChildren(List children) { Preconditions.checkArgument(children.size() == 1); - return new Size(children.get(0)); + return new ArrayPopFront(children.get(0)); } @Override public R accept(ExpressionVisitor visitor, C context) { - return visitor.visitSize(this, context); + return visitor.visitArrayPopFront(this, context); } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayPosition.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayPosition.java index 6c3a0c77dd..ecaac29e7c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayPosition.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayPosition.java @@ -25,21 +25,8 @@ 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.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -53,26 +40,8 @@ public class ArrayPosition extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE), BooleanType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(TinyIntType.INSTANCE), TinyIntType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(SmallIntType.INSTANCE), SmallIntType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(IntegerType.INSTANCE), IntegerType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BigIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(LargeIntType.INSTANCE), LargeIntType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(DateTimeType.INSTANCE), DateTimeType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(DateType.INSTANCE), DateType.INSTANCE), FunctionSignature.ret(BigIntType.INSTANCE) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT), DateTimeV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(DateV2Type.INSTANCE), DateV2Type.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(FloatType.INSTANCE), FloatType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(DoubleType.INSTANCE), DoubleType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), DecimalV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(BigIntType.INSTANCE) - .args(ArrayType.of(DecimalV3Type.WILDCARD), DecimalV3Type.WILDCARD), - FunctionSignature.ret(BigIntType.INSTANCE) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(StringType.INSTANCE), StringType.INSTANCE) + .args(ArrayType.of(new AnyDataType(0)), new FollowToAnyDataType(0)) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayProduct.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayProduct.java index c77519eebb..16aaf27c14 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayProduct.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayProduct.java @@ -20,6 +20,8 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.ComputePrecisionForArrayItemAgg; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; @@ -42,8 +44,8 @@ import java.util.List; /** * ScalarFunction 'array_product'. This class is generated by GenerateFunction. */ -public class ArrayProduct extends CompatibleTypeArrayFunction - implements UnaryExpression, AlwaysNullable { +public class ArrayProduct extends ScalarFunction implements ExplicitlyCastableSignature, + ComputePrecisionForArrayItemAgg, UnaryExpression, AlwaysNullable { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE)), @@ -52,10 +54,10 @@ public class ArrayProduct extends CompatibleTypeArrayFunction FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(IntegerType.INSTANCE)), FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(BigIntType.INSTANCE)), FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(DoubleType.INSTANCE)), + FunctionSignature.ret(DecimalV3Type.WILDCARD).args(ArrayType.of(DecimalV3Type.WILDCARD)), FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(DecimalV3Type.WILDCARD).args(ArrayType.of(DecimalV3Type.WILDCARD)) + FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(FloatType.INSTANCE)), + FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(DoubleType.INSTANCE)) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRemove.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRemove.java index 2eeb78f69a..acf731b8bb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRemove.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRemove.java @@ -24,22 +24,8 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; 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.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -53,38 +39,8 @@ public class ArrayRemove extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) - .args(ArrayType.of(BooleanType.INSTANCE), BooleanType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) - .args(ArrayType.of(TinyIntType.INSTANCE), TinyIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) - .args(ArrayType.of(SmallIntType.INSTANCE), SmallIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) - .args(ArrayType.of(IntegerType.INSTANCE), IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) - .args(ArrayType.of(BigIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) - .args(ArrayType.of(LargeIntType.INSTANCE), LargeIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) - .args(ArrayType.of(FloatType.INSTANCE), FloatType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) - .args(ArrayType.of(DoubleType.INSTANCE), DoubleType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), DecimalV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(ArrayType.of(DecimalV3Type.WILDCARD), DecimalV3Type.WILDCARD), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)) - .args(ArrayType.of(DateTimeType.INSTANCE), DateTimeType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)) - .args(ArrayType.of(DateType.INSTANCE), DateType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT), DateTimeV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE)) - .args(ArrayType.of(DateV2Type.INSTANCE), DateV2Type.INSTANCE), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)) - .args(ArrayType.of(StringType.INSTANCE), StringType.INSTANCE) + FunctionSignature.retArgType(0).args( + ArrayType.of(new AnyDataType(0)), new FollowToAnyDataType(0)) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayReverseSort.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayReverseSort.java new file mode 100644 index 0000000000..bcdc1d852f --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayReverseSort.java @@ -0,0 +1,69 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.trees.expressions.functions.scalar; + +import org.apache.doris.catalog.FunctionSignature; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; +import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; +import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; +import org.apache.doris.nereids.types.ArrayType; +import org.apache.doris.nereids.types.coercion.AnyDataType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'array_sort'. This class is generated by GenerateFunction. + */ +public class ArrayReverseSort extends ScalarFunction + implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { + + public static final List SIGNATURES = ImmutableList.of( + FunctionSignature.retArgType(0).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX)) + ); + + /** + * constructor with 1 argument. + */ + public ArrayReverseSort(Expression arg) { + super("array_reverse_sort", arg); + } + + /** + * withChildren. + */ + @Override + public ArrayReverseSort withChildren(List children) { + Preconditions.checkArgument(children.size() == 1); + return new ArrayReverseSort(children.get(0)); + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitArrayReverseSort(this, context); + } + + @Override + public List getSignatures() { + return SIGNATURES; + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySlice.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySlice.java index 1c0d4b1904..54560c7e0c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySlice.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySlice.java @@ -24,19 +24,7 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -50,62 +38,10 @@ public class ArraySlice extends ScalarFunction implements ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) - .args(ArrayType.of(BooleanType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) - .args(ArrayType.of(TinyIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) - .args(ArrayType.of(SmallIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) - .args(ArrayType.of(IntegerType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) - .args(ArrayType.of(BigIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) - .args(ArrayType.of(LargeIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)) - .args(ArrayType.of(DateTimeType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)) - .args(ArrayType.of(DateType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) - .args(ArrayType.of(FloatType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) - .args(ArrayType.of(DoubleType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(ArrayType.of(DecimalV3Type.WILDCARD), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)) - .args(ArrayType.of(StringType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) - .args(ArrayType.of(BooleanType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) - .args(ArrayType.of(TinyIntType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) - .args(ArrayType.of(SmallIntType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) - .args(ArrayType.of(IntegerType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) - .args(ArrayType.of(BigIntType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) - .args(ArrayType.of(LargeIntType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)) - .args(ArrayType.of(DateTimeType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)) - .args(ArrayType.of(DateType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) - .args(ArrayType.of(FloatType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) - .args(ArrayType.of(DoubleType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(ArrayType.of(DecimalV3Type.WILDCARD), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)) - .args(ArrayType.of(StringType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE) + FunctionSignature.retArgType(0) + .args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX), BigIntType.INSTANCE), + FunctionSignature.retArgType(0) + .args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX), BigIntType.INSTANCE, BigIntType.INSTANCE) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySort.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySort.java index ebafa5894c..5953d69b66 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySort.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySort.java @@ -24,22 +24,7 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -53,26 +38,7 @@ public class ArraySort extends ScalarFunction implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)).args(ArrayType.of(BooleanType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)).args(ArrayType.of(TinyIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)).args(ArrayType.of(SmallIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)).args(ArrayType.of(IntegerType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(BigIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)).args(ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)).args(ArrayType.of(DateTimeType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)).args(ArrayType.of(DateType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE)).args(ArrayType.of(DateV2Type.INSTANCE)), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)).args(ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).args(ArrayType.of(DoubleType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(ArrayType.of(DecimalV3Type.WILDCARD)), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)).args(ArrayType.of(StringType.INSTANCE)) + FunctionSignature.retArgType(0).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX)) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySum.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySum.java index 2d346ff405..2a28a4d18b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySum.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySum.java @@ -20,6 +20,8 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.ComputePrecisionForArrayItemAgg; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; @@ -42,8 +44,8 @@ import java.util.List; /** * ScalarFunction 'array_sum'. This class is generated by GenerateFunction. */ -public class ArraySum extends CompatibleTypeArrayFunction - implements UnaryExpression, AlwaysNullable { +public class ArraySum extends ScalarFunction implements ExplicitlyCastableSignature, + ComputePrecisionForArrayItemAgg, UnaryExpression, AlwaysNullable { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE)), @@ -52,10 +54,11 @@ public class ArraySum extends CompatibleTypeArrayFunction FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(IntegerType.INSTANCE)), FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BigIntType.INSTANCE)), FunctionSignature.ret(LargeIntType.INSTANCE).args(ArrayType.of(LargeIntType.INSTANCE)), + FunctionSignature.ret(DecimalV3Type.WILDCARD).args(ArrayType.of(DecimalV3Type.WILDCARD)), FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(FloatType.INSTANCE)), FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(DoubleType.INSTANCE)), - FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(DecimalV3Type.WILDCARD).args(ArrayType.of(DecimalV3Type.WILDCARD)) + FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT).args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) + ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayUnion.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayUnion.java index 1872c04e88..93e1ca862f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayUnion.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayUnion.java @@ -19,26 +19,13 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; 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.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -48,42 +35,12 @@ import java.util.List; /** * ScalarFunction 'array_union'. This class is generated by GenerateFunction. */ -public class ArrayUnion extends CompatibleTypeArrayFunction - implements BinaryExpression, PropagateNullable { +public class ArrayUnion extends ScalarFunction implements ExplicitlyCastableSignature, + BinaryExpression, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) - .args(ArrayType.of(BooleanType.INSTANCE), ArrayType.of(BooleanType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) - .args(ArrayType.of(TinyIntType.INSTANCE), ArrayType.of(TinyIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) - .args(ArrayType.of(SmallIntType.INSTANCE), ArrayType.of(SmallIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) - .args(ArrayType.of(IntegerType.INSTANCE), ArrayType.of(IntegerType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) - .args(ArrayType.of(BigIntType.INSTANCE), ArrayType.of(BigIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) - .args(ArrayType.of(LargeIntType.INSTANCE), ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) - .args(ArrayType.of(FloatType.INSTANCE), ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) - .args(ArrayType.of(DoubleType.INSTANCE), ArrayType.of(DoubleType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(ArrayType.of(DecimalV3Type.WILDCARD), ArrayType.of(DecimalV3Type.WILDCARD)), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)) - .args(ArrayType.of(DateTimeType.INSTANCE), ArrayType.of(DateTimeType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)) - .args(ArrayType.of(DateType.INSTANCE), ArrayType.of(DateType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT), ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE)) - .args(ArrayType.of(DateV2Type.INSTANCE), ArrayType.of(DateV2Type.INSTANCE)), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), ArrayType.of(VarcharType.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)) - .args(ArrayType.of(StringType.INSTANCE), ArrayType.of(StringType.INSTANCE)) + FunctionSignature.retArgType(0) + .args(ArrayType.of(new AnyDataType(0)), ArrayType.of(new FollowToAnyDataType(0))) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayWithConstant.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayWithConstant.java index f687e86c42..49485e7a0f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayWithConstant.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayWithConstant.java @@ -25,19 +25,7 @@ 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.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -51,23 +39,7 @@ public class ArrayWithConstant extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)).args(BigIntType.INSTANCE, BooleanType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)).args(BigIntType.INSTANCE, TinyIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)).args(BigIntType.INSTANCE, SmallIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)).args(BigIntType.INSTANCE, IntegerType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)).args(BigIntType.INSTANCE, LargeIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)).args(BigIntType.INSTANCE, DateTimeType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)).args(BigIntType.INSTANCE, DateType.INSTANCE), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)).args(BigIntType.INSTANCE, FloatType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).args(BigIntType.INSTANCE, DoubleType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) - .args(BigIntType.INSTANCE, DecimalV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(BigIntType.INSTANCE, DecimalV3Type.WILDCARD), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(BigIntType.INSTANCE, VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)).args(BigIntType.INSTANCE, StringType.INSTANCE) + FunctionSignature.ret(ArrayType.of(new AnyDataType(0))).args(BigIntType.INSTANCE, new AnyDataType(0)) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraysOverlap.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraysOverlap.java index a9ba1ab04e..9e40d73264 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraysOverlap.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraysOverlap.java @@ -20,25 +20,13 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar; import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; 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.BigIntType; import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -48,42 +36,12 @@ import java.util.List; /** * ScalarFunction 'arrays_overlap'. This class is generated by GenerateFunction. */ -public class ArraysOverlap extends CompatibleTypeArrayFunction - implements BinaryExpression, AlwaysNullable { +public class ArraysOverlap extends ScalarFunction implements ExplicitlyCastableSignature, + BinaryExpression, AlwaysNullable { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(BooleanType.INSTANCE), ArrayType.of(BooleanType.INSTANCE)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(TinyIntType.INSTANCE), ArrayType.of(TinyIntType.INSTANCE)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(SmallIntType.INSTANCE), ArrayType.of(SmallIntType.INSTANCE)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(IntegerType.INSTANCE), ArrayType.of(IntegerType.INSTANCE)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(BigIntType.INSTANCE), ArrayType.of(BigIntType.INSTANCE)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(LargeIntType.INSTANCE), ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(DateTimeType.INSTANCE), ArrayType.of(DateTimeType.INSTANCE)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(DateType.INSTANCE), ArrayType.of(DateType.INSTANCE)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT), ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(DateV2Type.INSTANCE), ArrayType.of(DateV2Type.INSTANCE)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(FloatType.INSTANCE), ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(DoubleType.INSTANCE), ArrayType.of(DoubleType.INSTANCE)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(DecimalV3Type.WILDCARD), ArrayType.of(DecimalV3Type.WILDCARD)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), ArrayType.of(VarcharType.SYSTEM_DEFAULT)), - FunctionSignature.ret(BooleanType.INSTANCE) - .args(ArrayType.of(StringType.INSTANCE), ArrayType.of(StringType.INSTANCE)) + .args(ArrayType.of(new AnyDataType(0)), ArrayType.of(new FollowToAnyDataType(0))) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Cardinality.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Cardinality.java index 49dbc44c63..90da3f3f1d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Cardinality.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Cardinality.java @@ -25,6 +25,7 @@ import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; import org.apache.doris.nereids.types.BigIntType; +import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -38,7 +39,7 @@ public class Cardinality extends ScalarFunction implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.SYSTEM_DEFAULT) + FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX)) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CompatibleTypeArrayFunction.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CompatibleTypeArrayFunction.java deleted file mode 100644 index 31168911d6..0000000000 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CompatibleTypeArrayFunction.java +++ /dev/null @@ -1,65 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package org.apache.doris.nereids.trees.expressions.functions.scalar; - -import org.apache.doris.catalog.FunctionSignature; -import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.exceptions.AnalysisException; -import org.apache.doris.nereids.trees.expressions.Expression; -import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.types.DataType; - -import com.google.common.base.Joiner; - -import java.util.List; - -/** CompatibleTypeArrayFunction */ -public abstract class CompatibleTypeArrayFunction extends ScalarFunction - implements ExplicitlyCastableSignature { - - public CompatibleTypeArrayFunction(String name, Expression... arguments) { - super(name, arguments); - } - - public CompatibleTypeArrayFunction(String name, List arguments) { - super(name, arguments); - } - - @Override - public FunctionSignature computeSignature(FunctionSignature signature) { - Type compatibleType = getArgumentType(0).toCatalogDataType(); - for (int i = 1; i < arity(); ++i) { - compatibleType = Type.getAssignmentCompatibleType( - compatibleType, getArgumentType(i).toCatalogDataType(), true); - if (compatibleType == Type.INVALID) { - throw new AnalysisException(String.format( - "No matching function with signature: %s(%s).", - getName(), Joiner.on(", ").join(getArguments()))); - } - } - // Make sure BE doesn't see any TYPE_NULL exprs - if (compatibleType.isNull()) { - compatibleType = Type.BOOLEAN; - } - - // do implicit type cast - DataType compatibleDataType = DataType.fromCatalogType(compatibleType); - signature = signature.withArgumentTypes(getArguments(), (sigType, argument) -> compatibleDataType); - return super.computeSignature(signature); - } -} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CountEqual.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CountEqual.java index 937f782d0e..95b5b5b29e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CountEqual.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CountEqual.java @@ -25,21 +25,8 @@ 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.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -53,26 +40,8 @@ public class CountEqual extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE), BooleanType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(TinyIntType.INSTANCE), TinyIntType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(SmallIntType.INSTANCE), SmallIntType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(IntegerType.INSTANCE), IntegerType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BigIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(LargeIntType.INSTANCE), LargeIntType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(DateTimeType.INSTANCE), DateTimeType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(DateType.INSTANCE), DateType.INSTANCE), FunctionSignature.ret(BigIntType.INSTANCE) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT), DateTimeV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(DateV2Type.INSTANCE), DateV2Type.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(FloatType.INSTANCE), FloatType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(DoubleType.INSTANCE), DoubleType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), DecimalV2Type.SYSTEM_DEFAULT), - FunctionSignature.ret(BigIntType.INSTANCE) - .args(ArrayType.of(DecimalV3Type.WILDCARD), DecimalV3Type.WILDCARD), - FunctionSignature.ret(BigIntType.INSTANCE) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(StringType.INSTANCE), StringType.INSTANCE) + .args(ArrayType.of(new AnyDataType(0)), new FollowToAnyDataType(0)) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementAt.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementAt.java index aaddd849d3..1d47e9f368 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementAt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementAt.java @@ -25,21 +25,9 @@ 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.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.MapType; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -53,26 +41,10 @@ public class ElementAt extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BooleanType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(TinyIntType.INSTANCE).args(ArrayType.of(TinyIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(SmallIntType.INSTANCE).args(ArrayType.of(SmallIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(IntegerType.INSTANCE).args(ArrayType.of(IntegerType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BigIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(LargeIntType.INSTANCE).args(ArrayType.of(LargeIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(DateTimeType.INSTANCE).args(ArrayType.of(DateTimeType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(DateType.INSTANCE).args(ArrayType.of(DateType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT), BigIntType.INSTANCE), - FunctionSignature.ret(DateV2Type.INSTANCE).args(ArrayType.of(DateV2Type.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(FloatType.INSTANCE).args(ArrayType.of(FloatType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(DoubleType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), BigIntType.INSTANCE), - FunctionSignature.ret(DecimalV3Type.WILDCARD) - .args(ArrayType.of(DecimalV3Type.WILDCARD), BigIntType.INSTANCE), - FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), BigIntType.INSTANCE), - FunctionSignature.ret(StringType.INSTANCE).args(ArrayType.of(StringType.INSTANCE), BigIntType.INSTANCE) + FunctionSignature.ret(new FollowToAnyDataType(0)) + .args(ArrayType.of(new AnyDataType(0)), BigIntType.INSTANCE), + FunctionSignature.ret(new FollowToAnyDataType(1)) + .args(MapType.of(new AnyDataType(0), new AnyDataType(1)), new FollowToAnyDataType(0)) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementExtract.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementExtract.java deleted file mode 100644 index 395747aa06..0000000000 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementExtract.java +++ /dev/null @@ -1,103 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package org.apache.doris.nereids.trees.expressions.functions.scalar; - -import org.apache.doris.catalog.FunctionSignature; -import org.apache.doris.nereids.trees.expressions.Expression; -import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; -import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -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.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateTimeV2Type; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DateV2Type; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; - -import java.util.List; - -/** - * ScalarFunction '%element_extract%'. This class is generated by GenerateFunction. - */ -public class ElementExtract extends ScalarFunction - implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { - - public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(BooleanType.INSTANCE).args(ArrayType.of(BooleanType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(TinyIntType.INSTANCE).args(ArrayType.of(TinyIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(SmallIntType.INSTANCE).args(ArrayType.of(SmallIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(IntegerType.INSTANCE).args(ArrayType.of(IntegerType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(BigIntType.INSTANCE).args(ArrayType.of(BigIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(LargeIntType.INSTANCE).args(ArrayType.of(LargeIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(DateTimeType.INSTANCE).args(ArrayType.of(DateTimeType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(DateType.INSTANCE).args(ArrayType.of(DateType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) - .args(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT), BigIntType.INSTANCE), - FunctionSignature.ret(DateV2Type.INSTANCE).args(ArrayType.of(DateV2Type.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(FloatType.INSTANCE).args(ArrayType.of(FloatType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(DoubleType.INSTANCE).args(ArrayType.of(DoubleType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(DecimalV2Type.SYSTEM_DEFAULT) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), BigIntType.INSTANCE), - FunctionSignature.ret(DecimalV3Type.WILDCARD) - .args(ArrayType.of(DecimalV3Type.WILDCARD), BigIntType.INSTANCE), - FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), BigIntType.INSTANCE), - FunctionSignature.ret(StringType.INSTANCE).args(ArrayType.of(StringType.INSTANCE), BigIntType.INSTANCE) - ); - - /** - * constructor with 2 arguments. - */ - public ElementExtract(Expression arg0, Expression arg1) { - super("%element_extract%", arg0, arg1); - } - - /** - * withChildren. - */ - @Override - public ElementExtract withChildren(List children) { - Preconditions.checkArgument(children.size() == 2); - return new ElementExtract(children.get(0), children.get(1)); - } - - @Override - public R accept(ExpressionVisitor visitor, C context) { - return visitor.visitElementExtract(this, context); - } - - @Override - public List getSignatures() { - return SIGNATURES; - } -} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementSlice.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementSlice.java deleted file mode 100644 index af9ecb43a3..0000000000 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ElementSlice.java +++ /dev/null @@ -1,148 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package org.apache.doris.nereids.trees.expressions.functions.scalar; - -import org.apache.doris.catalog.FunctionSignature; -import org.apache.doris.nereids.trees.expressions.Expression; -import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; -import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; -import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; -import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; -import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; -import org.apache.doris.nereids.types.VarcharType; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; - -import java.util.List; - -/** - * ScalarFunction '%element_slice%'. This class is generated by GenerateFunction. - */ -public class ElementSlice extends ScalarFunction - implements ExplicitlyCastableSignature, PropagateNullable { - - public static final List SIGNATURES = ImmutableList.of( - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) - .args(ArrayType.of(BooleanType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) - .args(ArrayType.of(TinyIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) - .args(ArrayType.of(SmallIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) - .args(ArrayType.of(IntegerType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) - .args(ArrayType.of(BigIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) - .args(ArrayType.of(LargeIntType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)) - .args(ArrayType.of(DateTimeType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)) - .args(ArrayType.of(DateType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) - .args(ArrayType.of(FloatType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) - .args(ArrayType.of(DoubleType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(ArrayType.of(DecimalV3Type.WILDCARD), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)) - .args(ArrayType.of(StringType.INSTANCE), BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) - .args(ArrayType.of(BooleanType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) - .args(ArrayType.of(TinyIntType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)) - .args(ArrayType.of(SmallIntType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) - .args(ArrayType.of(IntegerType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) - .args(ArrayType.of(BigIntType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)) - .args(ArrayType.of(LargeIntType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)) - .args(ArrayType.of(DateTimeType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)) - .args(ArrayType.of(DateType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) - .args(ArrayType.of(FloatType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) - .args(ArrayType.of(DoubleType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(ArrayType.of(DecimalV3Type.WILDCARD), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT), BigIntType.INSTANCE, BigIntType.INSTANCE), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)) - .args(ArrayType.of(StringType.INSTANCE), BigIntType.INSTANCE, BigIntType.INSTANCE) - ); - - /** - * constructor with 2 arguments. - */ - public ElementSlice(Expression arg0, Expression arg1) { - super("%element_slice%", arg0, arg1); - } - - /** - * constructor with 3 arguments. - */ - public ElementSlice(Expression arg0, Expression arg1, Expression arg2) { - super("%element_slice%", arg0, arg1, arg2); - } - - /** - * withChildren. - */ - @Override - public ElementSlice withChildren(List children) { - Preconditions.checkArgument(children.size() == 2 - || children.size() == 3); - if (children.size() == 2) { - return new ElementSlice(children.get(0), children.get(1)); - } else { - return new ElementSlice(children.get(0), children.get(1), children.get(2)); - } - } - - @Override - public R accept(ExpressionVisitor visitor, C context) { - return visitor.visitElementSlice(this, context); - } - - @Override - public List getSignatures() { - return SIGNATURES; - } -} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/If.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/If.java index df8bc78a27..0d695515a8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/If.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/If.java @@ -18,8 +18,6 @@ package org.apache.doris.nereids.trees.expressions.functions.scalar; import org.apache.doris.catalog.FunctionSignature; -import org.apache.doris.catalog.ScalarType; -import org.apache.doris.catalog.Type; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.shape.TernaryExpression; @@ -28,7 +26,6 @@ import org.apache.doris.nereids.types.ArrayType; import org.apache.doris.nereids.types.BigIntType; import org.apache.doris.nereids.types.BitmapType; import org.apache.doris.nereids.types.BooleanType; -import org.apache.doris.nereids.types.DataType; import org.apache.doris.nereids.types.DateTimeType; import org.apache.doris.nereids.types.DateTimeV2Type; import org.apache.doris.nereids.types.DateType; @@ -44,13 +41,12 @@ import org.apache.doris.nereids.types.SmallIntType; import org.apache.doris.nereids.types.StringType; import org.apache.doris.nereids.types.TinyIntType; import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; -import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; import java.util.List; -import java.util.function.Supplier; /** * ScalarFunction 'if'. This class is generated by GenerateFunction. @@ -59,6 +55,9 @@ public class If extends ScalarFunction implements TernaryExpression, ExplicitlyCastableSignature { public static final List SIGNATURES = ImmutableList.of( + FunctionSignature.retArgType(1) + .args(BooleanType.INSTANCE, ArrayType.of(new AnyDataType(0)), + ArrayType.of(new AnyDataType(0))), FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT) .args(BooleanType.INSTANCE, DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT), FunctionSignature.ret(DateV2Type.INSTANCE) @@ -92,63 +91,9 @@ public class If extends ScalarFunction FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) .args(BooleanType.INSTANCE, VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT), FunctionSignature.ret(StringType.INSTANCE) - .args(BooleanType.INSTANCE, StringType.INSTANCE, StringType.INSTANCE), - FunctionSignature.ret(ArrayType.of(BooleanType.INSTANCE)) - .args(BooleanType.INSTANCE, ArrayType.of(BooleanType.INSTANCE), ArrayType.of(BooleanType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)) - .args(BooleanType.INSTANCE, ArrayType.of(TinyIntType.INSTANCE), ArrayType.of(TinyIntType.INSTANCE)), - FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .args(BooleanType.INSTANCE, - ArrayType.of(SmallIntType.INSTANCE), - ArrayType.of(SmallIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) - .args(BooleanType.INSTANCE, ArrayType.of(IntegerType.INSTANCE), ArrayType.of(IntegerType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)) - .args(BooleanType.INSTANCE, ArrayType.of(BigIntType.INSTANCE), ArrayType.of(BigIntType.INSTANCE)), - FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .args(BooleanType.INSTANCE, - ArrayType.of(LargeIntType.INSTANCE), - ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)) - .args(BooleanType.INSTANCE, ArrayType.of(FloatType.INSTANCE), ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)) - .args(BooleanType.INSTANCE, ArrayType.of(DoubleType.INSTANCE), ArrayType.of(DoubleType.INSTANCE)), - FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .args(BooleanType.INSTANCE, - ArrayType.of(DateTimeType.INSTANCE), - ArrayType.of(DateTimeType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)) - .args(BooleanType.INSTANCE, ArrayType.of(DateType.INSTANCE), ArrayType.of(DateType.INSTANCE)), - FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .args(BooleanType.INSTANCE, - ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT), - ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DateV2Type.INSTANCE)) - .args(BooleanType.INSTANCE, ArrayType.of(DateV2Type.INSTANCE), ArrayType.of(DateV2Type.INSTANCE)), - FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .args(BooleanType.INSTANCE, - ArrayType.of(DecimalV3Type.WILDCARD), - ArrayType.of(DecimalV3Type.WILDCARD)), - FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .args(BooleanType.INSTANCE, - ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT), - ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT) - .args(BooleanType.INSTANCE, - ArrayType.of(VarcharType.SYSTEM_DEFAULT), - ArrayType.of(VarcharType.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)) - .args(BooleanType.INSTANCE, ArrayType.of(StringType.INSTANCE), ArrayType.of(StringType.INSTANCE)) + .args(BooleanType.INSTANCE, StringType.INSTANCE, StringType.INSTANCE) ); - private final Supplier widerType = Suppliers.memoize(() -> { - Type assignmentCompatibleType = ScalarType.getAssignmentCompatibleType( - getArgumentType(1).toCatalogDataType(), - getArgumentType(2).toCatalogDataType(), - true); - return DataType.fromCatalogType(assignmentCompatibleType); - }); - /** * constructor with 3 arguments. */ diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Reverse.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Reverse.java index 5954e1feef..87682e0d42 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Reverse.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Reverse.java @@ -24,19 +24,9 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.BigIntType; -import org.apache.doris.nereids.types.DateTimeType; -import org.apache.doris.nereids.types.DateType; -import org.apache.doris.nereids.types.DecimalV2Type; -import org.apache.doris.nereids.types.DecimalV3Type; -import org.apache.doris.nereids.types.DoubleType; -import org.apache.doris.nereids.types.FloatType; -import org.apache.doris.nereids.types.IntegerType; -import org.apache.doris.nereids.types.LargeIntType; -import org.apache.doris.nereids.types.SmallIntType; import org.apache.doris.nereids.types.StringType; -import org.apache.doris.nereids.types.TinyIntType; import org.apache.doris.nereids.types.VarcharType; +import org.apache.doris.nereids.types.coercion.AnyDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -50,24 +40,9 @@ public class Reverse extends ScalarFunction implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { public static final List SIGNATURES = ImmutableList.of( + FunctionSignature.retArgType(0).args(ArrayType.of(AnyDataType.INSTANCE_WITHOUT_INDEX)), FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).args(VarcharType.SYSTEM_DEFAULT), - FunctionSignature.ret(StringType.INSTANCE).args(StringType.INSTANCE), - FunctionSignature.ret(ArrayType.of(TinyIntType.INSTANCE)).args(ArrayType.of(TinyIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(SmallIntType.INSTANCE)).args(ArrayType.of(SmallIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)).args(ArrayType.of(IntegerType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(BigIntType.INSTANCE)).args(ArrayType.of(BigIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(LargeIntType.INSTANCE)).args(ArrayType.of(LargeIntType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateTimeType.INSTANCE)).args(ArrayType.of(DateTimeType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DateType.INSTANCE)).args(ArrayType.of(DateType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(FloatType.INSTANCE)).args(ArrayType.of(FloatType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DoubleType.INSTANCE)).args(ArrayType.of(DoubleType.INSTANCE)), - FunctionSignature.ret(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)) - .args(ArrayType.of(DecimalV2Type.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(DecimalV3Type.WILDCARD)) - .args(ArrayType.of(DecimalV3Type.WILDCARD)), - FunctionSignature.ret(ArrayType.of(VarcharType.SYSTEM_DEFAULT)) - .args(ArrayType.of(VarcharType.SYSTEM_DEFAULT)), - FunctionSignature.ret(ArrayType.of(StringType.INSTANCE)).args(ArrayType.of(StringType.INSTANCE)) + FunctionSignature.ret(StringType.INSTANCE).args(StringType.INSTANCE) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/TimeDiff.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/TimeDiff.java index 2cff7c8886..da83d5453f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/TimeDiff.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/TimeDiff.java @@ -24,12 +24,12 @@ import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnD 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.DataType; import org.apache.doris.nereids.types.DateTimeType; import org.apache.doris.nereids.types.DateTimeV2Type; import org.apache.doris.nereids.types.DateV2Type; import org.apache.doris.nereids.types.TimeType; import org.apache.doris.nereids.types.TimeV2Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -98,7 +98,7 @@ public class TimeDiff extends ScalarFunction } @Override - public List expectedInputTypes() { + public List expectedInputTypes() { FunctionSignature signature = getSignature(); if (getArgument(0) instanceof StringLikeLiteral) { StringLikeLiteral str = (StringLikeLiteral) getArgument(0); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/table/Hdfs.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/table/Hdfs.java index 2054a9ac8b..29abbcee22 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/table/Hdfs.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/table/Hdfs.java @@ -39,7 +39,7 @@ public class Hdfs extends TableValuedFunction { @Override public FunctionSignature customSignature() { - return FunctionSignature.of(AnyDataType.INSTANCE, (List) getArgumentsTypes()); + return FunctionSignature.of(AnyDataType.INSTANCE_WITHOUT_INDEX, (List) getArgumentsTypes()); } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/table/S3.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/table/S3.java index c2fc81489a..90e72f89f7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/table/S3.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/table/S3.java @@ -39,7 +39,7 @@ public class S3 extends TableValuedFunction { @Override public FunctionSignature customSignature() { - return FunctionSignature.of(AnyDataType.INSTANCE, (List) getArgumentsTypes()); + return FunctionSignature.of(AnyDataType.INSTANCE_WITHOUT_INDEX, (List) getArgumentsTypes()); } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/JavaUdaf.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/JavaUdaf.java index 96be9dbcb0..58c497a352 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/JavaUdaf.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/JavaUdaf.java @@ -32,7 +32,6 @@ import org.apache.doris.nereids.trees.expressions.functions.Udf; import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.thrift.TFunctionBinaryType; import com.google.common.base.Preconditions; @@ -50,7 +49,7 @@ public class JavaUdaf extends AggregateFunction implements ExplicitlyCastableSig private final String dbName; private final TFunctionBinaryType binaryType; private final FunctionSignature signature; - private final AbstractDataType intermediateType; + private final DataType intermediateType; private final NullableMode nullableMode; private final String objectFile; private final String symbol; @@ -67,7 +66,7 @@ public class JavaUdaf extends AggregateFunction implements ExplicitlyCastableSig * Constructor of UDAF */ public JavaUdaf(String name, String dbName, TFunctionBinaryType binaryType, FunctionSignature signature, - AbstractDataType intermediateType, NullableMode nullableMode, + DataType intermediateType, NullableMode nullableMode, String objectFile, String symbol, String initFn, String updateFn, String mergeFn, String serializeFn, String finalizeFn, String getValueFn, String removeFn, @@ -176,7 +175,7 @@ public class JavaUdaf extends AggregateFunction implements ExplicitlyCastableSig try { org.apache.doris.catalog.AggregateFunction expr = new org.apache.doris.catalog.AggregateFunction( new FunctionName(dbName, getName()), - signature.argumentsTypes.stream().map(AbstractDataType::toCatalogDataType).toArray(Type[]::new), + signature.argumentsTypes.stream().map(DataType::toCatalogDataType).toArray(Type[]::new), signature.returnType.toCatalogDataType(), signature.hasVarArgs, intermediateType.toCatalogDataType(), diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/JavaUdf.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/JavaUdf.java index 431937af10..84c21e0f76 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/JavaUdf.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/JavaUdf.java @@ -32,7 +32,6 @@ import org.apache.doris.nereids.trees.expressions.functions.Udf; import org.apache.doris.nereids.trees.expressions.functions.scalar.ScalarFunction; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.thrift.TFunctionBinaryType; import com.google.common.base.Preconditions; @@ -149,7 +148,7 @@ public class JavaUdf extends ScalarFunction implements ExplicitlyCastableSignatu org.apache.doris.catalog.ScalarFunction expr = org.apache.doris.catalog.ScalarFunction.createUdf( binaryType, new FunctionName(dbName, getName()), - signature.argumentsTypes.stream().map(AbstractDataType::toCatalogDataType).toArray(Type[]::new), + signature.argumentsTypes.stream().map(DataType::toCatalogDataType).toArray(Type[]::new), signature.returnType.toCatalogDataType(), signature.hasVarArgs, URI.create(objectFile), diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/JavaUdfBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/JavaUdfBuilder.java index c11b07665a..efbcbf9f48 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/JavaUdfBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/udf/JavaUdfBuilder.java @@ -21,7 +21,6 @@ import org.apache.doris.common.util.ReflectionUtils; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.BoundFunction; import org.apache.doris.nereids.types.DataType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.util.TypeCoercionUtils; import com.google.common.base.Suppliers; @@ -71,7 +70,7 @@ public class JavaUdfBuilder extends UdfBuilder { @Override public BoundFunction build(String name, List arguments) { List exprs = arguments.stream().map(Expression.class::cast).collect(Collectors.toList()); - List argTypes = udf.getSignatures().get(0).argumentsTypes; + List argTypes = udf.getSignatures().get(0).argumentsTypes; List processedExprs = Lists.newArrayList(); for (int i = 0; i < exprs.size(); ++i) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/ArrayLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/ArrayLiteral.java index 9d13bbc3ea..a669385b79 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/ArrayLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/ArrayLiteral.java @@ -53,30 +53,13 @@ public class ArrayLiteral extends Literal { .map(Literal::toLegacyLiteral) .toArray(LiteralExpr[]::new); try { - return new org.apache.doris.analysis.ArrayLiteral(itemExprs); + return new org.apache.doris.analysis.ArrayLiteral(getDataType().toCatalogDataType(), itemExprs); } catch (Throwable t) { throw new AnalysisException(t.getMessage(), t); } } } - @Override - protected Expression uncheckedCastTo(DataType targetType) { - if (targetType instanceof ArrayType) { - return new Array(items.stream().toArray(Expression[]::new)).castTo(targetType); - } - return super.uncheckedCastTo(targetType); - } - - @Override - public Expression checkedCastTo(DataType targetType) { - if (targetType instanceof ArrayType) { - return new Array( - items.stream().toArray(Expression[]::new)).checkedCastTo(targetType); - } - return super.checkedCastTo(targetType); - } - @Override public String toString() { String items = this.items.stream() diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/typecoercion/ExpectsInputTypes.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/typecoercion/ExpectsInputTypes.java index 337b3590ba..7d0bb118c2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/typecoercion/ExpectsInputTypes.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/typecoercion/ExpectsInputTypes.java @@ -18,7 +18,7 @@ package org.apache.doris.nereids.trees.expressions.typecoercion; import org.apache.doris.nereids.trees.expressions.functions.scalar.Substring; -import org.apache.doris.nereids.types.coercion.AbstractDataType; +import org.apache.doris.nereids.types.DataType; import java.util.List; @@ -34,5 +34,5 @@ import java.util.List; */ public interface ExpectsInputTypes { - List expectedInputTypes(); + List expectedInputTypes(); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java index d8bc04026a..10dd651a22 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java @@ -32,6 +32,7 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.Array; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayAvg; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayCompact; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayContains; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayCumSum; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayDifference; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayDistinct; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayEnumerate; @@ -40,12 +41,13 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayIntersec import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayJoin; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayMax; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayMin; -import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayPopback; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayPopBack; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayPopFront; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayPosition; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayProduct; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRange; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRemove; -import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySize; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayReverseSort; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySlice; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySort; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySum; @@ -127,8 +129,6 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.Dround; import org.apache.doris.nereids.trees.expressions.functions.scalar.Dsqrt; import org.apache.doris.nereids.trees.expressions.functions.scalar.E; import org.apache.doris.nereids.trees.expressions.functions.scalar.ElementAt; -import org.apache.doris.nereids.trees.expressions.functions.scalar.ElementExtract; -import org.apache.doris.nereids.trees.expressions.functions.scalar.ElementSlice; import org.apache.doris.nereids.trees.expressions.functions.scalar.Elt; import org.apache.doris.nereids.trees.expressions.functions.scalar.EndsWith; import org.apache.doris.nereids.trees.expressions.functions.scalar.EsQuery; @@ -261,7 +261,6 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.SecondsDiff; import org.apache.doris.nereids.trees.expressions.functions.scalar.SecondsSub; import org.apache.doris.nereids.trees.expressions.functions.scalar.Sign; import org.apache.doris.nereids.trees.expressions.functions.scalar.Sin; -import org.apache.doris.nereids.trees.expressions.functions.scalar.Size; import org.apache.doris.nereids.trees.expressions.functions.scalar.Sleep; import org.apache.doris.nereids.trees.expressions.functions.scalar.Sm3; import org.apache.doris.nereids.trees.expressions.functions.scalar.Sm3sum; @@ -394,6 +393,10 @@ public interface ScalarFunctionVisitor { return visitScalarFunction(arrayContains, context); } + default R visitArrayCumSum(ArrayCumSum arrayCumSum, C context) { + return visitScalarFunction(arrayCumSum, context); + } + default R visitArrayDifference(ArrayDifference arrayDifference, C context) { return visitScalarFunction(arrayDifference, context); } @@ -426,8 +429,12 @@ public interface ScalarFunctionVisitor { return visitScalarFunction(arrayMin, context); } - default R visitArrayPopback(ArrayPopback arrayPopback, C context) { - return visitScalarFunction(arrayPopback, context); + default R visitArrayPopBack(ArrayPopBack arrayPopBack, C context) { + return visitScalarFunction(arrayPopBack, context); + } + + default R visitArrayPopFront(ArrayPopFront arrayPopFront, C context) { + return visitScalarFunction(arrayPopFront, context); } default R visitArrayPosition(ArrayPosition arrayPosition, C context) { @@ -446,10 +453,6 @@ public interface ScalarFunctionVisitor { return visitScalarFunction(arrayRemove, context); } - default R visitArraySize(ArraySize arraySize, C context) { - return visitScalarFunction(arraySize, context); - } - default R visitArraySlice(ArraySlice arraySlice, C context) { return visitScalarFunction(arraySlice, context); } @@ -474,6 +477,10 @@ public interface ScalarFunctionVisitor { return visitScalarFunction(arraysOverlap, context); } + default R visitArrayReverseSort(ArrayReverseSort arrayReverseSort, C context) { + return visitScalarFunction(arrayReverseSort, context); + } + default R visitAscii(Ascii ascii, C context) { return visitScalarFunction(ascii, context); } @@ -818,14 +825,6 @@ public interface ScalarFunctionVisitor { return visitScalarFunction(elementAt, context); } - default R visitElementExtract(ElementExtract elementExtract, C context) { - return visitScalarFunction(elementExtract, context); - } - - default R visitElementSlice(ElementSlice elementSlice, C context) { - return visitScalarFunction(elementSlice, context); - } - default R visitElt(Elt elt, C context) { return visitScalarFunction(elt, context); } @@ -1326,10 +1325,6 @@ public interface ScalarFunctionVisitor { return visitScalarFunction(sin, context); } - default R visitSize(Size size, C context) { - return visitScalarFunction(size, context); - } - default R visitSleep(Sleep sleep, C context) { return visitScalarFunction(sleep, context); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/AggStateType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/AggStateType.java index a999512d1b..6acde37b74 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/AggStateType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/AggStateType.java @@ -21,7 +21,6 @@ import org.apache.doris.analysis.Expr; import org.apache.doris.catalog.Type; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.SlotReference; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -74,7 +73,7 @@ public class AggStateType extends DataType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof AggStateType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/ArrayType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/ArrayType.java index 8ec8fe69f5..c742d8f4a6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/ArrayType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/ArrayType.java @@ -33,7 +33,7 @@ public class ArrayType extends DataType { private final DataType itemType; private final boolean containsNull; - public ArrayType(DataType itemType, boolean containsNull) { + private ArrayType(DataType itemType, boolean containsNull) { this.itemType = Objects.requireNonNull(itemType, "itemType can not be null"); this.containsNull = containsNull; } @@ -67,11 +67,6 @@ public class ArrayType extends DataType { return "array"; } - @Override - public DataType defaultConcreteType() { - return SYSTEM_DEFAULT; - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/BigIntType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/BigIntType.java index cd07ea4d77..cce3fca3ae 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/BigIntType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/BigIntType.java @@ -18,7 +18,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.Int64OrLessType; import org.apache.doris.nereids.types.coercion.IntegralType; @@ -40,7 +39,7 @@ public class BigIntType extends IntegralType implements Int64OrLessType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof BigIntType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/BitmapType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/BitmapType.java index dae10fad65..adf7506c6f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/BitmapType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/BitmapType.java @@ -18,7 +18,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.PrimitiveType; /** @@ -39,7 +38,7 @@ public class BitmapType extends PrimitiveType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof BitmapType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/CharType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/CharType.java index 144e161cbe..f9ce7d2ea0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/CharType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/CharType.java @@ -19,7 +19,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.CharacterType; import java.util.Objects; @@ -53,7 +52,7 @@ public class CharType extends CharacterType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof CharType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java index f608292f9b..43d09b67b4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java @@ -19,7 +19,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; -import org.apache.doris.common.Config; import org.apache.doris.nereids.annotation.Developing; import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.parser.NereidsParser; @@ -29,7 +28,6 @@ import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral; import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral; import org.apache.doris.nereids.trees.expressions.literal.StringLiteral; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.CharacterType; import org.apache.doris.nereids.types.coercion.IntegralType; import org.apache.doris.nereids.types.coercion.NumericType; @@ -48,7 +46,7 @@ import java.util.stream.Collectors; /** * Abstract class for all data type in Nereids. */ -public abstract class DataType implements AbstractDataType { +public abstract class DataType { public static final int DEFAULT_SCALE = 0; public static final int DEFAULT_PRECISION = 9; @@ -111,7 +109,7 @@ public abstract class DataType implements AbstractDataType { * @param types data type in string representation * @return data type in Nereids */ - public static DataType convertPrimitiveFromStrings(List types, boolean tryConvert) { + public static DataType convertPrimitiveFromStrings(List types) { String type = types.get(0).toLowerCase().trim(); switch (type) { case "bool": @@ -133,37 +131,22 @@ public abstract class DataType implements AbstractDataType { case "double": return DoubleType.INSTANCE; case "decimal": - if (Config.enable_decimal_conversion && tryConvert) { - switch (types.size()) { - case 1: - return DecimalV3Type.SYSTEM_DEFAULT; - case 2: - return DecimalV3Type - .createDecimalV3Type(Integer.parseInt(types.get(1))); - case 3: - return DecimalV3Type.createDecimalV3Type(Integer.parseInt(types.get(1)), - Integer.parseInt(types.get(2))); - default: - throw new AnalysisException("Nereids do not support type: " + type); - } - } else { - switch (types.size()) { - case 1: - return DecimalV2Type.SYSTEM_DEFAULT; - case 2: - return DecimalV2Type.createDecimalV2Type(Integer.parseInt(types.get(1)), - 0); - case 3: - return DecimalV2Type.createDecimalV2Type(Integer.parseInt(types.get(1)), - Integer.parseInt(types.get(2))); - default: - throw new AnalysisException("Nereids do not support type: " + type); - } + switch (types.size()) { + case 1: + return DecimalV2Type.CATALOG_DEFAULT; + case 2: + return DecimalV2Type.createDecimalV2Type(Integer.parseInt(types.get(1)), + 0); + case 3: + return DecimalV2Type.createDecimalV2Type(Integer.parseInt(types.get(1)), + Integer.parseInt(types.get(2))); + default: + throw new AnalysisException("Nereids do not support type: " + type); } case "decimalv3": switch (types.size()) { case 1: - return DecimalV3Type.SYSTEM_DEFAULT; + return DecimalV3Type.CATALOG_DEFAULT; case 2: return DecimalV3Type.createDecimalV3Type(Integer.parseInt(types.get(1))); case 3: @@ -198,8 +181,7 @@ public abstract class DataType implements AbstractDataType { case "null_type": // ScalarType.NULL.toSql() return "null_type", so support it return NullType.INSTANCE; case "date": - return Config.enable_date_conversion && tryConvert ? DateV2Type.INSTANCE - : DateType.INSTANCE; + return DateType.INSTANCE; case "datev2": return DateV2Type.INSTANCE; case "time": @@ -207,9 +189,7 @@ public abstract class DataType implements AbstractDataType { case "datetime": switch (types.size()) { case 1: - return Config.enable_date_conversion && tryConvert - ? DateTimeV2Type.SYSTEM_DEFAULT - : DateTimeType.INSTANCE; + return DateTimeType.INSTANCE; case 2: return DateTimeV2Type.of(Integer.parseInt(types.get(1))); default: @@ -245,16 +225,7 @@ public abstract class DataType implements AbstractDataType { * @return data type in Nereids */ public static DataType convertFromString(String type) { - try { - List types = PARSER.parseDataType(type); - return DataType.convertPrimitiveFromStrings(types, false); - } catch (Exception e) { - // TODO: remove it when Nereids parser support array - if (type.startsWith("array")) { - return resolveArrayType(type); - } - throw e; - } + return PARSER.parseDataType(type); } /** @@ -325,18 +296,26 @@ public abstract class DataType implements AbstractDataType { // TODO: support map type really return MapType.INSTANCE; } else if (type.isArrayType()) { - // TODO: support array type really org.apache.doris.catalog.ArrayType arrayType = (org.apache.doris.catalog.ArrayType) type; return ArrayType.of(fromCatalogType(arrayType.getItemType()), arrayType.getContainsNull()); } else if (type.isAggStateType()) { org.apache.doris.catalog.AggStateType catalogType = ((org.apache.doris.catalog.AggStateType) type); - List types = catalogType.getSubTypes().stream().map(t -> fromCatalogType(t)) + List types = catalogType.getSubTypes().stream().map(DataType::fromCatalogType) .collect(Collectors.toList()); return new AggStateType(catalogType.getFunctionName(), types, catalogType.getSubTypeNullables()); } throw new AnalysisException("Nereids do not support type: " + type); } + /** + * convert nereids's data type to legacy catalog data type + * @return legacy catalog data type + */ + public abstract Type toCatalogDataType(); + + /** + * sql format of this type + */ public abstract String toSql(); @Override @@ -348,24 +327,21 @@ public abstract class DataType implements AbstractDataType { return this.getClass().getSimpleName().replace("Type", "").toLowerCase(Locale.ROOT); } - @Override public DataType defaultConcreteType() { return this; } - @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return sameType(other); } /** * this and other is same type. */ - private boolean sameType(AbstractDataType other) { + private boolean sameType(DataType other) { return this.equals(other); } - @Override public String simpleString() { return typeName(); } @@ -550,6 +526,10 @@ public abstract class DataType implements AbstractDataType { return isHllType() || isBitmapType() || isQuantileStateType(); } + public DataType conversion() { + return this; + } + public DataType promotion() { if (PROMOTION_MAP.containsKey(this.getClass())) { return PROMOTION_MAP.get(this.getClass()).get(); @@ -575,25 +555,6 @@ public abstract class DataType implements AbstractDataType { public abstract int width(); - private static ArrayType resolveArrayType(String type) { - if (!type.startsWith("array")) { - throw new AnalysisException("Not array type: " + type); - } - - type = type.substring("array".length()); - if (type.startsWith("<") && type.endsWith(">")) { - DataType itemType = convertFromString(type.substring(1, type.length() - 1)); - if (itemType.equals(NullType.INSTANCE)) { - return ArrayType.SYSTEM_DEFAULT; - } - return ArrayType.of(itemType); - } else if (type.isEmpty()) { - return ArrayType.SYSTEM_DEFAULT; - } else { - throw new AnalysisException("Illegal array type: " + type); - } - } - public static List trivialTypes() { return Type.getTrivialTypes() .stream() @@ -645,4 +606,20 @@ public abstract class DataType implements AbstractDataType { public double rangeLength(double high, double low) { return high - low; } + + /** + * whether the target dataType is assignable to this dataType + * @param targetDataType the target data type + * @return true if assignable + */ + @Developing + public boolean isAssignableFrom(DataType targetDataType) { + if (this.equals(targetDataType)) { + return true; + } + if (this instanceof CharacterType) { + return true; + } + return false; + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DateTimeType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DateTimeType.java index b59e47d3eb..d8a80f018c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DateTimeType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DateTimeType.java @@ -18,6 +18,7 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; +import org.apache.doris.common.Config; import org.apache.doris.nereids.types.coercion.DateLikeType; /** @@ -32,6 +33,14 @@ public class DateTimeType extends DateLikeType { private DateTimeType() { } + @Override + public DataType conversion() { + if (Config.enable_date_conversion) { + return DateTimeV2Type.SYSTEM_DEFAULT; + } + return this; + } + @Override public Type toCatalogDataType() { return Type.DATETIME; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DateTimeV2Type.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DateTimeV2Type.java index 6a57c7a218..114dcd580c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DateTimeV2Type.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DateTimeV2Type.java @@ -20,7 +20,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; import org.apache.doris.nereids.exceptions.AnalysisException; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.DateLikeType; import org.apache.doris.nereids.types.coercion.IntegralType; @@ -83,7 +82,7 @@ public class DateTimeV2Type extends DateLikeType { * may be we need to check for validity? */ public static DateTimeV2Type forTypeFromString(String s) { - if (!s.contains(String.valueOf("."))) { + if (!s.contains(".")) { return DateTimeV2Type.SYSTEM_DEFAULT; } return DateTimeV2Type.of(s.length() - s.lastIndexOf(".") - 1); @@ -115,7 +114,7 @@ public class DateTimeV2Type extends DateLikeType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof DateTimeV2Type; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DateType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DateType.java index a33fec9d1c..ddffb56fb0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DateType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DateType.java @@ -18,6 +18,7 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; +import org.apache.doris.common.Config; import org.apache.doris.nereids.types.coercion.DateLikeType; /** @@ -32,6 +33,14 @@ public class DateType extends DateLikeType { private DateType() { } + @Override + public DataType conversion() { + if (Config.enable_date_conversion) { + return DateV2Type.INSTANCE; + } + return this; + } + @Override public Type toCatalogDataType() { return Type.DATE; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DecimalV2Type.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DecimalV2Type.java index a48ea084c1..998f0e6411 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DecimalV2Type.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DecimalV2Type.java @@ -20,7 +20,7 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; +import org.apache.doris.common.Config; import org.apache.doris.nereids.types.coercion.FractionalType; import com.google.common.base.Preconditions; @@ -142,13 +142,21 @@ public class DecimalV2Type extends FractionalType { return scale; } + @Override + public DataType conversion() { + if (Config.enable_decimal_conversion) { + return DecimalV3Type.createDecimalV3Type(precision, scale); + } + return this; + } + @Override public DataType defaultConcreteType() { return this; } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof DecimalV2Type; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DecimalV3Type.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DecimalV3Type.java index b0fdd20580..7501d3b8db 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DecimalV3Type.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DecimalV3Type.java @@ -20,7 +20,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; import org.apache.doris.nereids.annotation.Developing; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.FractionalType; import com.google.common.base.Preconditions; @@ -41,6 +40,7 @@ public class DecimalV3Type extends FractionalType { public static final DecimalV3Type WILDCARD = new DecimalV3Type(-1, -1); public static final DecimalV3Type SYSTEM_DEFAULT = new DecimalV3Type(MAX_DECIMAL128_PRECISION, DEFAULT_SCALE); + public static final DecimalV3Type CATALOG_DEFAULT = new DecimalV3Type(MAX_DECIMAL32_PRECISION, DEFAULT_SCALE); private static final DecimalV3Type BOOLEAN_DECIMAL = new DecimalV3Type(1, 0); private static final DecimalV3Type TINYINT_DECIMAL = new DecimalV3Type(3, 0); @@ -153,7 +153,7 @@ public class DecimalV3Type extends FractionalType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other.equals(this); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DoubleType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DoubleType.java index 58959b8512..cbe52701c0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DoubleType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DoubleType.java @@ -18,7 +18,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.FractionalType; /** @@ -48,7 +47,7 @@ public class DoubleType extends FractionalType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof DoubleType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/FloatType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/FloatType.java index 3dbfda4e7e..394ba7be44 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/FloatType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/FloatType.java @@ -18,7 +18,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.FractionalType; /** @@ -43,7 +42,7 @@ public class FloatType extends FractionalType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof FloatType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/HllType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/HllType.java index 5c0c322505..aeab159c10 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/HllType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/HllType.java @@ -18,7 +18,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.PrimitiveType; /** @@ -39,7 +38,7 @@ public class HllType extends PrimitiveType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof HllType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/IntegerType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/IntegerType.java index febc4bf291..58838abbc8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/IntegerType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/IntegerType.java @@ -18,7 +18,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.Int32OrLessType; import org.apache.doris.nereids.types.coercion.IntegralType; @@ -49,7 +48,7 @@ public class IntegerType extends IntegralType implements Int32OrLessType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof IntegerType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/JsonType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/JsonType.java index 95a25e03c6..8455daaac2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/JsonType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/JsonType.java @@ -19,7 +19,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; import org.apache.doris.nereids.annotation.Developing; -import org.apache.doris.nereids.types.coercion.AbstractDataType; /** * Json type in Nereids. @@ -40,7 +39,7 @@ public class JsonType extends DataType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof JsonType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/LargeIntType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/LargeIntType.java index 874fe56460..6a1d2a4259 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/LargeIntType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/LargeIntType.java @@ -18,7 +18,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.IntegralType; import java.math.BigInteger; @@ -54,7 +53,7 @@ public class LargeIntType extends IntegralType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof LargeIntType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/MapType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/MapType.java index 40e0dae0fd..111c1c8292 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/MapType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/MapType.java @@ -19,7 +19,8 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; import org.apache.doris.nereids.annotation.Developing; -import org.apache.doris.nereids.types.coercion.AbstractDataType; + +import java.util.Objects; /** * Struct type in Nereids. @@ -27,20 +28,43 @@ import org.apache.doris.nereids.types.coercion.AbstractDataType; @Developing public class MapType extends DataType { + // TODO: remove it? public static final MapType INSTANCE = new MapType(); public static final int WIDTH = 24; + private final DataType keyType; + private final DataType valueType; + private MapType() { + keyType = NullType.INSTANCE; + valueType = NullType.INSTANCE; + } + + private MapType(DataType keyType, DataType valueType) { + this.keyType = Objects.requireNonNull(keyType, "key type should not be null"); + this.valueType = Objects.requireNonNull(valueType, "value type should not be null"); + } + + public static MapType of(DataType keyType, DataType valueType) { + return new MapType(keyType, valueType); + } + + public DataType getKeyType() { + return keyType; + } + + public DataType getValueType() { + return valueType; } @Override public Type toCatalogDataType() { - return Type.MAP; + return new org.apache.doris.catalog.MapType(keyType.toCatalogDataType(), valueType.toCatalogDataType()); } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof MapType; } @@ -50,13 +74,23 @@ public class MapType extends DataType { } @Override - public DataType defaultConcreteType() { - return INSTANCE; + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } + MapType mapType = (MapType) o; + return Objects.equals(keyType, mapType.keyType) && Objects.equals(valueType, mapType.valueType); } @Override - public boolean equals(Object o) { - return o instanceof MapType; + public int hashCode() { + return Objects.hash(super.hashCode(), keyType, valueType); } @Override @@ -66,6 +100,11 @@ public class MapType extends DataType { @Override public String toSql() { - return "MAP"; + return "MAP<" + keyType.toSql() + ", " + valueType.toSql() + ">"; + } + + @Override + public String toString() { + return toSql(); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/QuantileStateType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/QuantileStateType.java index 7c223e649a..079e11883f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/QuantileStateType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/QuantileStateType.java @@ -18,7 +18,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.PrimitiveType; /** @@ -39,7 +38,7 @@ public class QuantileStateType extends PrimitiveType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof QuantileStateType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/SmallIntType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/SmallIntType.java index f2be544cf3..176bf90ddc 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/SmallIntType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/SmallIntType.java @@ -18,7 +18,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.Int16OrLessType; import org.apache.doris.nereids.types.coercion.IntegralType; @@ -49,7 +48,7 @@ public class SmallIntType extends IntegralType implements Int16OrLessType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof SmallIntType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/StringType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/StringType.java index 8658278e07..5dad1f5dc5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/StringType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/StringType.java @@ -18,7 +18,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.CharacterType; /** @@ -43,7 +42,7 @@ public class StringType extends CharacterType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof StringType || other instanceof VarcharType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/StructType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/StructType.java index 147bffdf5e..9359df15f7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/StructType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/StructType.java @@ -19,7 +19,12 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; import org.apache.doris.nereids.annotation.Developing; -import org.apache.doris.nereids.types.coercion.AbstractDataType; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSortedMap; + +import java.util.Map; +import java.util.Objects; /** * Struct type in Nereids. @@ -31,7 +36,19 @@ public class StructType extends DataType { public static final int WIDTH = 24; + private final Map items; + private StructType() { + items = ImmutableMap.of(); + } + + public StructType(Map items) { + this.items = ImmutableSortedMap.copyOf(Objects.requireNonNull(items, "items should not be null"), + String.CASE_INSENSITIVE_ORDER); + } + + public Map getItems() { + return items; } @Override @@ -40,7 +57,7 @@ public class StructType extends DataType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof StructType; } @@ -49,11 +66,6 @@ public class StructType extends DataType { return "struct"; } - @Override - public DataType defaultConcreteType() { - return INSTANCE; - } - @Override public boolean equals(Object o) { return o instanceof StructType; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/TinyIntType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/TinyIntType.java index 95a9bc27f4..3c5a351bf0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/TinyIntType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/TinyIntType.java @@ -18,7 +18,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.Int16OrLessType; import org.apache.doris.nereids.types.coercion.IntegralType; @@ -49,7 +48,7 @@ public class TinyIntType extends IntegralType implements Int16OrLessType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof TinyIntType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VarcharType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VarcharType.java index 5f7d7708c2..cb9bfd6776 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VarcharType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VarcharType.java @@ -19,7 +19,6 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.CharacterType; import java.util.Objects; @@ -55,7 +54,7 @@ public class VarcharType extends CharacterType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof VarcharType || other instanceof StringType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/AbstractDataType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/AbstractDataType.java deleted file mode 100644 index 42cd1e9d07..0000000000 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/AbstractDataType.java +++ /dev/null @@ -1,65 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package org.apache.doris.nereids.types.coercion; - -import org.apache.doris.catalog.Type; -import org.apache.doris.nereids.annotation.Developing; -import org.apache.doris.nereids.types.DataType; - -/** - * Represent a set of equality concrete data type. - */ -public interface AbstractDataType { - - /** - * the default concrete type cast to when do implicit cast - */ - DataType defaultConcreteType(); - - /** - * This AbstractDataType could accept other without implicit cast - */ - boolean acceptsType(AbstractDataType other); - - /** - * convert nereids's data type to legacy catalog data type - * @return legacy catalog data type - */ - Type toCatalogDataType(); - - /** - * simple string used to print error message - */ - String simpleString(); - - /** - * whether the target dataType is assignable to this dataType - * @param targetDataType the target data type - * @return true if assignable - */ - @Developing - default boolean isAssignableFrom(AbstractDataType targetDataType) { - if (this.equals(targetDataType)) { - return true; - } - if (this instanceof CharacterType) { - return true; - } - return false; - } -} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/AnyDataType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/AnyDataType.java index be07a7ee7b..15ab995b79 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/AnyDataType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/AnyDataType.java @@ -21,12 +21,37 @@ import org.apache.doris.catalog.Type; import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.types.DataType; +import java.util.Locale; + /** * Represent any datatype in type coercion. */ -public class AnyDataType implements AbstractDataType { +public class AnyDataType extends DataType { - public static final AnyDataType INSTANCE = new AnyDataType(); + public static final AnyDataType INSTANCE_WITHOUT_INDEX = new AnyDataType(-1); + + private final int index; + + public AnyDataType(int index) { + if (index < 0) { + index = -1; + } + this.index = index; + } + + public int getIndex() { + return index; + } + + @Override + public String toSql() { + StringBuilder sb = new StringBuilder(); + sb.append(simpleString().toUpperCase(Locale.ROOT)); + if (index >= 0) { + sb.append("#").append(index); + } + return sb.toString(); + } @Override public DataType defaultConcreteType() { @@ -34,7 +59,7 @@ public class AnyDataType implements AbstractDataType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return true; } @@ -47,4 +72,9 @@ public class AnyDataType implements AbstractDataType { public String simpleString() { return "any"; } + + @Override + public int width() { + return -1; + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/CharacterType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/CharacterType.java index a25797c593..da56e71c7b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/CharacterType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/CharacterType.java @@ -44,7 +44,7 @@ public abstract class CharacterType extends PrimitiveType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof CharacterType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/FollowToAnyDataType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/FollowToAnyDataType.java new file mode 100644 index 0000000000..d6a7007808 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/FollowToAnyDataType.java @@ -0,0 +1,69 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.types.coercion; + +import org.apache.doris.catalog.Type; +import org.apache.doris.nereids.types.DataType; + +import java.util.Locale; + +/** + * FollowToAnyDataType is used to auto compute the return type by the AnyDataType in signature. + */ +public class FollowToAnyDataType extends DataType { + + public final int index; + + public FollowToAnyDataType(int index) { + this.index = index; + } + + public int getIndex() { + return index; + } + + @Override + public String toSql() { + return simpleString().toUpperCase(Locale.ROOT); + } + + @Override + public DataType defaultConcreteType() { + throw new RuntimeException("Unsupported operation."); + } + + @Override + public boolean acceptsType(DataType other) { + throw new RuntimeException("Unsupported operation."); + } + + @Override + public Type toCatalogDataType() { + throw new RuntimeException("Unsupported operation."); + } + + @Override + public String simpleString() { + return "followAnyDataType#" + index; + } + + @Override + public int width() { + return -1; + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/FollowToArgumentType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/FollowToArgumentType.java index f642cc23aa..0cbbb703ee 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/FollowToArgumentType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/FollowToArgumentType.java @@ -20,26 +20,33 @@ package org.apache.doris.nereids.types.coercion; import org.apache.doris.catalog.Type; import org.apache.doris.nereids.types.DataType; +import java.util.Locale; + /** * FollowArgumentType is used to auto compute the return type by the argument type. * * e.g. the FunctionSignature.retArg(0).args(AnyDataType.INSTANCE) * will return `IntegerType.INSTANCE` if the first argument type is `IntegerType.INSTANCE`. */ -public class FollowToArgumentType implements AbstractDataType { +public class FollowToArgumentType extends DataType { public final int argumentIndex; public FollowToArgumentType(int argumentIndex) { this.argumentIndex = argumentIndex; } + @Override + public String toSql() { + return simpleString().toUpperCase(Locale.ROOT); + } + @Override public DataType defaultConcreteType() { throw new RuntimeException("Unsupported operation."); } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { throw new RuntimeException("Unsupported operation."); } @@ -50,6 +57,11 @@ public class FollowToArgumentType implements AbstractDataType { @Override public String simpleString() { - return "argumentType#" + argumentIndex; + return "followArgumentType#" + argumentIndex; + } + + @Override + public int width() { + return -1; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/FractionalType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/FractionalType.java index abc8493d1d..bb3a30e228 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/FractionalType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/FractionalType.java @@ -32,7 +32,7 @@ public class FractionalType extends NumericType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof FractionalType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/IntegralType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/IntegralType.java index 542f9df993..656c6f660f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/IntegralType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/IntegralType.java @@ -33,7 +33,7 @@ public class IntegralType extends NumericType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof IntegralType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/NumericType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/NumericType.java index 18a41d3ffe..7bbf8303db 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/NumericType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/NumericType.java @@ -39,7 +39,7 @@ public class NumericType extends PrimitiveType { } @Override - public boolean acceptsType(AbstractDataType other) { + public boolean acceptsType(DataType other) { return other instanceof NumericType; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java index bc44e03f19..8934df108e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java @@ -65,6 +65,7 @@ import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral; import org.apache.doris.nereids.trees.expressions.literal.StringLiteral; import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral; import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral; +import org.apache.doris.nereids.types.ArrayType; import org.apache.doris.nereids.types.BigIntType; import org.apache.doris.nereids.types.BooleanType; import org.apache.doris.nereids.types.CharType; @@ -78,14 +79,15 @@ import org.apache.doris.nereids.types.DoubleType; import org.apache.doris.nereids.types.FloatType; import org.apache.doris.nereids.types.IntegerType; import org.apache.doris.nereids.types.LargeIntType; +import org.apache.doris.nereids.types.MapType; import org.apache.doris.nereids.types.NullType; import org.apache.doris.nereids.types.SmallIntType; import org.apache.doris.nereids.types.StringType; +import org.apache.doris.nereids.types.StructType; import org.apache.doris.nereids.types.TimeType; import org.apache.doris.nereids.types.TimeV2Type; import org.apache.doris.nereids.types.TinyIntType; import org.apache.doris.nereids.types.VarcharType; -import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.CharacterType; import org.apache.doris.nereids.types.coercion.FractionalType; import org.apache.doris.nereids.types.coercion.IntegralType; @@ -143,11 +145,53 @@ public class TypeCoercionUtils { private static final Logger LOG = LogManager.getLogger(TypeCoercionUtils.class); + /** + * Return Optional.empty() if we cannot do implicit cast. + */ + public static Optional implicitCast(DataType input, DataType expected) { + if (input instanceof ArrayType && expected instanceof ArrayType) { + Optional itemType = implicitCast( + ((ArrayType) input).getItemType(), ((ArrayType) expected).getItemType()); + return itemType.map(ArrayType::of); + } else if (input instanceof MapType && expected instanceof MapType) { + Optional keyType = implicitCast( + ((MapType) input).getKeyType(), ((MapType) expected).getKeyType()); + Optional valueType = implicitCast( + ((MapType) input).getValueType(), ((MapType) expected).getValueType()); + if (keyType.isPresent() && valueType.isPresent()) { + return Optional.of(MapType.of(keyType.get(), valueType.get())); + } + return Optional.empty(); + } else if (input instanceof StructType && expected instanceof StructType) { + throw new AnalysisException("not support struct type now."); + } else { + return implicitCastPrimitive(input, expected); + } + } + + /** + * Return Optional.empty() if we cannot do implicit cast. + */ + public static Optional implicitCastPrimitive(DataType input, DataType expected) { + Optional castType = implicitCastPrimitiveInternal(input, expected); + // TODO: complete the cast logic like FunctionCallExpr.analyzeImpl + boolean legacyCastCompatible = false; + try { + legacyCastCompatible = !input.toCatalogDataType().matchesType(expected.toCatalogDataType()); + } catch (Throwable t) { + // ignore. + } + if (!castType.isPresent() && legacyCastCompatible) { + castType = Optional.of(expected); + } + return castType; + } + /** * Return Optional.empty() if we cannot do implicit cast. */ @Developing - public static Optional implicitCast(DataType input, AbstractDataType expected) { + private static Optional implicitCastPrimitiveInternal(DataType input, DataType expected) { DataType returnType = null; if (expected.acceptsType(input)) { // If the expected type @@ -163,7 +207,7 @@ public class TypeCoercionUtils { // cast the input to decimal. returnType = DecimalV2Type.forType(input); } else if (expected instanceof DecimalV3Type) { - returnType = (DataType) expected; + returnType = expected; } else if (expected instanceof DateTimeType) { returnType = DateTimeType.INSTANCE; } else if (expected instanceof NumericType) { @@ -184,6 +228,13 @@ public class TypeCoercionUtils { if (expected instanceof DateTimeType) { returnType = expected.defaultConcreteType(); } + if (expected instanceof DateTimeV2Type) { + returnType = expected; + } + } else if (input.isDateTimeV2Type()) { + if (expected instanceof DateTimeV2Type) { + returnType = expected; + } } if (returnType == null && input instanceof PrimitiveType @@ -200,7 +251,14 @@ public class TypeCoercionUtils { */ @Developing public static boolean hasCharacterType(DataType dataType) { - // TODO: consider complex type + if (dataType instanceof ArrayType) { + return hasCharacterType(((ArrayType) dataType).getItemType()); + } else if (dataType instanceof MapType) { + return hasCharacterType(((MapType) dataType).getKeyType()) + || hasCharacterType(((MapType) dataType).getValueType()); + } else if (dataType instanceof StructType) { + throw new AnalysisException("do not support struct type now"); + } return dataType instanceof CharacterType; } @@ -230,13 +288,30 @@ public class TypeCoercionUtils { * cast input type if input's datatype is not match with dateType. */ public static Expression castIfNotMatchType(Expression input, DataType dataType) { - if (input.getDataType().toCatalogDataType().matchesType(dataType.toCatalogDataType())) { + if (matchesType(input.getDataType(), dataType)) { return input; } else { return castIfNotSameType(input, dataType); } } + private static boolean matchesType(DataType input, DataType target) { + // TODO use nereids matches type to instead catalog datatype matches type + if (input instanceof ArrayType && target instanceof ArrayType) { + return matchesType(((ArrayType) input).getItemType(), ((ArrayType) target).getItemType()); + } else if (input instanceof MapType && target instanceof MapType) { + return matchesType(((MapType) input).getKeyType(), ((MapType) target).getKeyType()) + && matchesType(((MapType) input).getValueType(), ((MapType) target).getValueType()); + } else if (input instanceof StructType && target instanceof StructType) { + throw new AnalysisException("do not support struct type now"); + } else { + if (input instanceof NullType) { + return false; + } + return input.toCatalogDataType().matchesType(target.toCatalogDataType()); + } + } + /** * cast input type if input's datatype is not same with dateType. */ @@ -391,29 +466,19 @@ public class TypeCoercionUtils { } - public static Expression implicitCastInputTypes(Expression expr, List expectedInputTypes) { + public static Expression implicitCastInputTypes(Expression expr, List expectedInputTypes) { List> inputImplicitCastTypes = getInputImplicitCastTypes(expr.children(), expectedInputTypes); return castInputs(expr, inputImplicitCastTypes); } private static List> getInputImplicitCastTypes( - List inputs, List expectedTypes) { + List inputs, List expectedTypes) { Builder> implicitCastTypes = ImmutableList.builder(); for (int i = 0; i < inputs.size(); i++) { DataType argType = inputs.get(i).getDataType(); - AbstractDataType expectedType = expectedTypes.get(i); + DataType expectedType = expectedTypes.get(i); Optional castType = TypeCoercionUtils.implicitCast(argType, expectedType); - // TODO: complete the cast logic like FunctionCallExpr.analyzeImpl - boolean legacyCastCompatible = expectedType instanceof DataType - && !(expectedType.getClass().equals(NumericType.class)) - && !(expectedType.getClass().equals(IntegralType.class)) - && !(expectedType.getClass().equals(FractionalType.class)) - && !(expectedType.getClass().equals(CharacterType.class)) - && !argType.toCatalogDataType().matchesType(expectedType.toCatalogDataType()); - if (!castType.isPresent() && legacyCastCompatible) { - castType = Optional.of((DataType) expectedType); - } implicitCastTypes.add(castType); } return implicitCastTypes.build(); @@ -452,7 +517,13 @@ public class TypeCoercionUtils { /** * process divide */ - public static Expression processDivide(Divide divide, Expression left, Expression right) { + public static Expression processDivide(Divide divide) { + // check + divide.checkLegalityBeforeTypeCoercion(); + + Expression left = divide.left(); + Expression right = divide.right(); + DataType t1 = TypeCoercionUtils.getNumResultType(left.getDataType()); DataType t2 = TypeCoercionUtils.getNumResultType(right.getDataType()); @@ -464,8 +535,7 @@ public class TypeCoercionUtils { } DataType commonType = DoubleType.INSTANCE; - if (t1.isDoubleType() || t1.isFloatType() - || t2.isDoubleType() || t2.isFloatType()) { + if (t1.isFloatLikeType() || t2.isFloatLikeType()) { // double type } else if (t1.isDecimalV3Type() || t2.isDecimalV3Type()) { // divide should cast to precision and target scale @@ -493,7 +563,13 @@ public class TypeCoercionUtils { /** * process divide */ - public static Expression processIntegralDivide(IntegralDivide divide, Expression left, Expression right) { + public static Expression processIntegralDivide(IntegralDivide divide) { + // check + divide.checkLegalityBeforeTypeCoercion(); + + Expression left = divide.left(); + Expression right = divide.right(); + DataType t1 = TypeCoercionUtils.getNumResultType(left.getDataType()); DataType t2 = TypeCoercionUtils.getNumResultType(right.getDataType()); left = castIfNotSameType(left, t1); @@ -521,8 +597,13 @@ public class TypeCoercionUtils { /** * binary arithmetic type coercion */ - public static Expression processBinaryArithmetic(BinaryArithmetic binaryArithmetic, - Expression left, Expression right) { + public static Expression processBinaryArithmetic(BinaryArithmetic binaryArithmetic) { + // check + binaryArithmetic.checkLegalityBeforeTypeCoercion(); + + Expression left = binaryArithmetic.left(); + Expression right = binaryArithmetic.right(); + // characterLiteralTypeCoercion // we do this because string is cast to double by default // but if string literal could be cast to small type, we could use smaller type than double. @@ -639,8 +720,12 @@ public class TypeCoercionUtils { /** * process timestamp arithmetic type coercion. */ - public static Expression processTimestampArithmetic(TimestampArithmetic timestampArithmetic, - Expression left, Expression right) { + public static Expression processTimestampArithmetic(TimestampArithmetic timestampArithmetic) { + // check + timestampArithmetic.checkLegalityBeforeTypeCoercion(); + + Expression left = timestampArithmetic.left(); + Expression right = timestampArithmetic.right(); // left DataType leftType = left.getDataType(); @@ -685,8 +770,13 @@ public class TypeCoercionUtils { /** * process comparison predicate type coercion. */ - public static Expression processComparisonPredicate(ComparisonPredicate comparisonPredicate, - Expression left, Expression right) { + public static Expression processComparisonPredicate(ComparisonPredicate comparisonPredicate) { + // check + comparisonPredicate.checkLegalityBeforeTypeCoercion(); + + Expression left = comparisonPredicate.left(); + Expression right = comparisonPredicate.right(); + // same type if (left.getDataType().equals(right.getDataType())) { return comparisonPredicate.withChildren(left, right); @@ -711,6 +801,9 @@ public class TypeCoercionUtils { * process in predicate type coercion. */ public static Expression processInPredicate(InPredicate inPredicate) { + // check + inPredicate.checkLegalityBeforeTypeCoercion(); + if (inPredicate.getOptions().stream().map(Expression::getDataType) .allMatch(dt -> dt.equals(inPredicate.getCompareExpr().getDataType()))) { return inPredicate; @@ -735,6 +828,9 @@ public class TypeCoercionUtils { * process case when type coercion. */ public static Expression processCaseWhen(CaseWhen caseWhen) { + // check + caseWhen.checkLegalityBeforeTypeCoercion(); + // type coercion List dataTypesForCoercion = caseWhen.dataTypesForCoercion(); if (dataTypesForCoercion.size() <= 1) { @@ -772,13 +868,16 @@ public class TypeCoercionUtils { .ifPresent(newChildren::add); return caseWhen.withChildren(newChildren); }) - .orElse(caseWhen); + .orElseThrow(() -> new AnalysisException("Cannot find common type for case when " + caseWhen)); } /** * process compound predicate type coercion. */ public static Expression processCompoundPredicate(CompoundPredicate compoundPredicate) { + // check + compoundPredicate.checkLegalityBeforeTypeCoercion(); + compoundPredicate.children().forEach(e -> { if (!e.getDataType().isBooleanType() && !e.getDataType().isNullType() && !(e instanceof SubqueryExpr)) { @@ -799,6 +898,9 @@ public class TypeCoercionUtils { * process between type coercion. */ public static Expression processBetween(Between between) { + // check + between.checkLegalityBeforeTypeCoercion(); + if (between.getLowerBound().getDataType().equals(between.getCompareExpr().getDataType()) && between.getUpperBound().getDataType().equals(between.getCompareExpr().getDataType())) { return between; @@ -807,8 +909,7 @@ public class TypeCoercionUtils { between.children() .stream() .map(Expression::getDataType) - .collect(Collectors.toList()), - false); + .collect(Collectors.toList())); return optionalCommonType .map(commonType -> { @@ -839,10 +940,13 @@ public class TypeCoercionUtils { || t.isHllType() || t.isBitmapType() || t.isQuantileStateType() || t.isAggStateType(); } + public static Optional findWiderCommonTypeForComparison(List dataTypes) { + return findWiderCommonTypeForComparison(dataTypes, false); + } + @Developing private static Optional findWiderCommonTypeForComparison( List dataTypes, boolean intStringToString) { - // TODO: do not consider complex type Map> partitioned = dataTypes.stream() .collect(Collectors.partitioningBy(TypeCoercionUtils::hasCharacterType)); List needTypeCoercion = Lists.newArrayList(Sets.newHashSet(partitioned.get(true))); @@ -866,8 +970,8 @@ public class TypeCoercionUtils { // TODO: need to rethink how to handle char and varchar to return char or varchar as much as possible. return Stream .>>of( - () -> findCommonPrimitiveTypeForComparison(left, right, intStringToString), - () -> findCommonComplexTypeForComparison(left, right)) + () -> findCommonComplexTypeForComparison(left, right, intStringToString), + () -> findCommonPrimitiveTypeForComparison(left, right, intStringToString)) .map(Supplier::get) .filter(Optional::isPresent) .map(Optional::get) @@ -878,8 +982,23 @@ public class TypeCoercionUtils { * find common type for complex type. */ @Developing - private static Optional findCommonComplexTypeForComparison(DataType left, DataType right) { - // TODO: we need to add real logical here, if we add array type in Nereids + private static Optional findCommonComplexTypeForComparison( + DataType left, DataType right, boolean intStringToString) { + if (left instanceof ArrayType && right instanceof ArrayType) { + Optional itemType = findWiderTypeForTwoForComparison( + ((ArrayType) left).getItemType(), ((ArrayType) right).getItemType(), intStringToString); + return itemType.map(ArrayType::of); + } else if (left instanceof MapType && right instanceof MapType) { + Optional keyType = findWiderTypeForTwoForComparison( + ((MapType) left).getKeyType(), ((MapType) right).getKeyType(), intStringToString); + Optional valueType = findWiderTypeForTwoForComparison( + ((MapType) left).getValueType(), ((MapType) right).getValueType(), intStringToString); + if (keyType.isPresent() && valueType.isPresent()) { + return Optional.of(MapType.of(keyType.get(), valueType.get())); + } + } else if (left instanceof StructType && right instanceof StructType) { + throw new AnalysisException("do not support struct type now"); + } return Optional.empty(); } @@ -1019,7 +1138,6 @@ public class TypeCoercionUtils { */ @Developing private static Optional findWiderCommonTypeForCaseWhen(List dataTypes) { - // TODO: do not consider complex type Map> partitioned = dataTypes.stream() .collect(Collectors.partitioningBy(TypeCoercionUtils::hasCharacterType)); List needTypeCoercion = Lists.newArrayList(Sets.newHashSet(partitioned.get(true))); @@ -1042,8 +1160,8 @@ public class TypeCoercionUtils { // TODO: need to rethink how to handle char and varchar to return char or varchar as much as possible. return Stream .>>of( - () -> findCommonPrimitiveTypeForCaseWhen(left, right), - () -> findCommonComplexTypeForCaseWhen(left, right)) + () -> findCommonComplexTypeForCaseWhen(left, right), + () -> findCommonPrimitiveTypeForCaseWhen(left, right)) .map(Supplier::get) .filter(Optional::isPresent) .map(Optional::get) @@ -1055,7 +1173,30 @@ public class TypeCoercionUtils { */ @Developing private static Optional findCommonComplexTypeForCaseWhen(DataType left, DataType right) { - // TODO: we need to add real logical here, if we add array type in Nereids + if (left.isNullType()) { + return Optional.of(right); + } + if (right.isNullType()) { + return Optional.of(left); + } + if (left.equals(right)) { + return Optional.of(left); + } + if (left instanceof ArrayType && right instanceof ArrayType) { + Optional itemType = findWiderTypeForTwoForCaseWhen( + ((ArrayType) left).getItemType(), ((ArrayType) right).getItemType()); + return itemType.map(ArrayType::of); + } else if (left instanceof MapType && right instanceof MapType) { + Optional keyType = findWiderTypeForTwoForCaseWhen( + ((MapType) left).getKeyType(), ((MapType) right).getKeyType()); + Optional valueType = findWiderTypeForTwoForCaseWhen( + ((MapType) left).getValueType(), ((MapType) right).getValueType()); + if (keyType.isPresent() && valueType.isPresent()) { + return Optional.of(MapType.of(keyType.get(), valueType.get())); + } + } else if (left instanceof StructType && right instanceof StructType) { + throw new AnalysisException("do not support struct type now"); + } return Optional.empty(); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java index cdc81a5d10..3eb60f54b7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java @@ -527,19 +527,22 @@ public class StmtExecutor { try { ((Command) logicalPlan).run(context, this); } catch (QueryStateException e) { - LOG.debug("DDL statement(" + originStmt.originStmt + ") process failed.", e); + LOG.debug("Command(" + originStmt.originStmt + ") process failed.", e); context.setState(e.getQueryState()); - throw new NereidsException("DDL statement(" + originStmt.originStmt + ") process failed", e); + throw new NereidsException("Command(" + originStmt.originStmt + ") process failed", + new AnalysisException(e.getMessage(), e)); } catch (UserException e) { // Return message to info client what happened. - LOG.debug("DDL statement(" + originStmt.originStmt + ") process failed.", e); + LOG.debug("Command(" + originStmt.originStmt + ") process failed.", e); context.getState().setError(e.getMysqlErrorCode(), e.getMessage()); - throw new NereidsException("DDL statement(" + originStmt.originStmt + ") process failed", e); + throw new NereidsException("Command (" + originStmt.originStmt + ") process failed", + new AnalysisException(e.getMessage(), e)); } catch (Exception e) { // Maybe our bug - LOG.debug("DDL statement(" + originStmt.originStmt + ") process failed.", e); - context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR, "Unexpected exception: " + e.getMessage()); - throw new NereidsException("DDL statement(" + originStmt.originStmt + ") process failed.", e); + LOG.debug("Command (" + originStmt.originStmt + ") process failed.", e); + context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR, e.getMessage()); + throw new NereidsException("Command (" + originStmt.originStmt + ") process failed.", + new AnalysisException(e.getMessage(), e)); } } else { context.getState().setIsQuery(true); @@ -552,7 +555,7 @@ public class StmtExecutor { planner.plan(parsedStmt, context.getSessionVariable().toThrift()); } catch (Exception e) { LOG.debug("Nereids plan query failed:\n{}", originStmt.originStmt); - throw new NereidsException(new AnalysisException("Unexpected exception: " + e.getMessage(), e)); + throw new NereidsException(new AnalysisException(e.getMessage(), e)); } profile.getSummaryProfile().setQueryPlanFinishTime(); handleQueryWithRetry(queryId); diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/UnsupportedTypeTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/UnsupportedTypeTest.java index 0fc632f226..f7a18fda35 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/UnsupportedTypeTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/UnsupportedTypeTest.java @@ -60,24 +60,26 @@ public class UnsupportedTypeTest extends TestWithFeService { public void testUnsupportedTypeThrowException() { String[] sqls = { "select id from type_tb", - "select jsonb_parse('{\"k1\":\"v31\",\"k2\":300}')", "select karr from type_tb", "select array_range(10)", + "select jsonb_parse('{\"k1\":\"v31\",\"k2\":300}')", "select kmap from type_tb1", "select * from type_tb", "select * from type_tb1", }; Class[] exceptions = { null, - AnalysisException.class, - AnalysisException.class, + null, + null, AnalysisException.class, AnalysisException.class, AnalysisException.class, AnalysisException.class }; - runPlanner(sqls[0]); - for (int i = 1; i < sqls.length; ++i) { + for (int i = 0; i < 3; ++i) { + runPlanner(sqls[i]); + } + for (int i = 3; i < sqls.length; ++i) { int iCopy = i; Assertions.assertThrows(exceptions[i], () -> runPlanner(sqls[iCopy])); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/GenerateFunction.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/GenerateFunction.java index 9ec2f82c2c..038efc76e9 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/GenerateFunction.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/GenerateFunction.java @@ -1409,7 +1409,7 @@ public class GenerateFunction { return " @Override\n" + " public FunctionSignature computeSignature(FunctionSignature signature) {\n" + " DataType widerType = this.widerType.get();\n" - + " List newArgumentsTypes = new ImmutableList.Builder()\n" + + " List newArgumentsTypes = new ImmutableList.Builder()\n" + " .add(signature.argumentsTypes.get(0))\n" + " .add(widerType)\n" + " .add(widerType)\n" diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/types/AbstractDataTypeTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/types/AbstractDataTypeTest.java deleted file mode 100644 index 776b80ec47..0000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/types/AbstractDataTypeTest.java +++ /dev/null @@ -1,492 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package org.apache.doris.nereids.types; - -import org.apache.doris.nereids.types.coercion.AnyDataType; -import org.apache.doris.nereids.types.coercion.FractionalType; -import org.apache.doris.nereids.types.coercion.IntegralType; -import org.apache.doris.nereids.types.coercion.NumericType; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.Random; - -public class AbstractDataTypeTest { - @Test - public void testAnyAccept() { - AnyDataType dateType = AnyDataType.INSTANCE; - Assertions.assertTrue(dateType.acceptsType(NullType.INSTANCE)); - Assertions.assertTrue(dateType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertTrue(dateType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertTrue(dateType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertTrue(dateType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertTrue(dateType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertTrue(dateType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertTrue(dateType.acceptsType(FloatType.INSTANCE)); - Assertions.assertTrue(dateType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertTrue(dateType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertTrue(dateType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertTrue(dateType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertTrue(dateType.acceptsType(StringType.INSTANCE)); - Assertions.assertTrue(dateType.acceptsType(DateType.INSTANCE)); - Assertions.assertTrue(dateType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testNullTypeAccept() { - NullType dateType = NullType.INSTANCE; - Assertions.assertTrue(dateType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dateType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dateType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dateType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dateType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testBooleanAccept() { - BooleanType dateType = BooleanType.INSTANCE; - Assertions.assertFalse(dateType.acceptsType(NullType.INSTANCE)); - Assertions.assertTrue(dateType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dateType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dateType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dateType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dateType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dateType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testNumericAccept() { - NumericType dataType = NumericType.INSTANCE; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertTrue(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testIntegralAccept() { - IntegralType dataType = IntegralType.INSTANCE; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testTinyIntAccept() { - TinyIntType dataType = TinyIntType.INSTANCE; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testSmallIntAccept() { - SmallIntType dataType = SmallIntType.INSTANCE; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testIntAccept() { - IntegerType dataType = IntegerType.INSTANCE; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testBigIntAccept() { - BigIntType dataType = BigIntType.INSTANCE; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testLargeIntAccept() { - LargeIntType dataType = LargeIntType.INSTANCE; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testFractionalAccept() { - FractionalType dataType = FractionalType.INSTANCE; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertTrue(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testFloatAccept() { - FloatType dataType = FloatType.INSTANCE; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testDoubleAccept() { - DoubleType dataType = DoubleType.INSTANCE; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testDecimalAccept() { - DecimalV2Type dataType = DecimalV2Type.SYSTEM_DEFAULT; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertTrue(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testCharAccept() { - CharType dataType = CharType.createCharType(10); - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertTrue(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testVarcharAccept() { - VarcharType dataType = VarcharType.SYSTEM_DEFAULT; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertTrue(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertTrue(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testStringAccept() { - StringType dataType = StringType.INSTANCE; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertTrue(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertTrue(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testDateAccept() { - DateType dataType = DateType.INSTANCE; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testDateTimeAccept() { - DateTimeType dataType = DateTimeType.INSTANCE; - Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); - int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; - int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); - Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); - Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); - Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); - Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); - Assertions.assertTrue(dataType.acceptsType(DateTimeType.INSTANCE)); - } - - @Test - public void testSimpleName() { - Assertions.assertEquals("null", NullType.INSTANCE.simpleString()); - Assertions.assertEquals("boolean", BooleanType.INSTANCE.simpleString()); - Assertions.assertEquals("numeric", NumericType.INSTANCE.simpleString()); - Assertions.assertEquals("integral", IntegralType.INSTANCE.simpleString()); - Assertions.assertEquals("tinyint", TinyIntType.INSTANCE.simpleString()); - Assertions.assertEquals("smallint", SmallIntType.INSTANCE.simpleString()); - Assertions.assertEquals("int", IntegerType.INSTANCE.simpleString()); - Assertions.assertEquals("bigint", BigIntType.INSTANCE.simpleString()); - Assertions.assertEquals("largeint", LargeIntType.INSTANCE.simpleString()); - Assertions.assertEquals("fractional", FractionalType.INSTANCE.simpleString()); - Assertions.assertEquals("float", FloatType.INSTANCE.simpleString()); - Assertions.assertEquals("double", DoubleType.INSTANCE.simpleString()); - Assertions.assertEquals("decimal", DecimalV2Type.SYSTEM_DEFAULT.simpleString()); - Assertions.assertEquals("char", new CharType(10).simpleString()); - Assertions.assertEquals("varchar", VarcharType.SYSTEM_DEFAULT.simpleString()); - Assertions.assertEquals("string", StringType.INSTANCE.simpleString()); - Assertions.assertEquals("date", DateType.INSTANCE.simpleString()); - Assertions.assertEquals("datetime", DateTimeType.INSTANCE.simpleString()); - } - - @Test - public void testDefaultConcreteType() { - Assertions.assertEquals(NullType.INSTANCE, NullType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(BooleanType.INSTANCE, BooleanType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(DoubleType.INSTANCE, NumericType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(BigIntType.INSTANCE, IntegralType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(TinyIntType.INSTANCE, TinyIntType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(SmallIntType.INSTANCE, SmallIntType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(IntegerType.INSTANCE, IntegerType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(BigIntType.INSTANCE, BigIntType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(LargeIntType.INSTANCE, LargeIntType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(DoubleType.INSTANCE, FractionalType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(FloatType.INSTANCE, FloatType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(DoubleType.INSTANCE, DoubleType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(DecimalV2Type.SYSTEM_DEFAULT, DecimalV2Type.SYSTEM_DEFAULT.defaultConcreteType()); - Assertions.assertEquals(new CharType(10), new CharType(10).defaultConcreteType()); - Assertions.assertEquals(VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT.defaultConcreteType()); - Assertions.assertEquals(StringType.INSTANCE, StringType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(DateType.INSTANCE, DateType.INSTANCE.defaultConcreteType()); - Assertions.assertEquals(DateTimeType.INSTANCE, DateTimeType.INSTANCE.defaultConcreteType()); - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/types/DataTypeTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/types/DataTypeTest.java index c0c14bcb4a..9633db6249 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/types/DataTypeTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/types/DataTypeTest.java @@ -18,10 +18,16 @@ package org.apache.doris.nereids.types; import org.apache.doris.catalog.Type; +import org.apache.doris.nereids.types.coercion.AnyDataType; +import org.apache.doris.nereids.types.coercion.FractionalType; +import org.apache.doris.nereids.types.coercion.IntegralType; +import org.apache.doris.nereids.types.coercion.NumericType; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.Random; + public class DataTypeTest { @Test public void testDataTypeEquals() { @@ -119,4 +125,466 @@ public class DataTypeTest { // array Assertions.assertEquals(ArrayType.of(IntegerType.INSTANCE), DataType.convertFromString("array")); } + + @Test + public void testAnyAccept() { + AnyDataType dateType = AnyDataType.INSTANCE_WITHOUT_INDEX; + Assertions.assertTrue(dateType.acceptsType(NullType.INSTANCE)); + Assertions.assertTrue(dateType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertTrue(dateType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertTrue(dateType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertTrue(dateType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertTrue(dateType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertTrue(dateType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertTrue(dateType.acceptsType(FloatType.INSTANCE)); + Assertions.assertTrue(dateType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertTrue(dateType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertTrue(dateType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertTrue(dateType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertTrue(dateType.acceptsType(StringType.INSTANCE)); + Assertions.assertTrue(dateType.acceptsType(DateType.INSTANCE)); + Assertions.assertTrue(dateType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testNullTypeAccept() { + NullType dateType = NullType.INSTANCE; + Assertions.assertTrue(dateType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dateType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dateType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dateType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dateType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testBooleanAccept() { + BooleanType dateType = BooleanType.INSTANCE; + Assertions.assertFalse(dateType.acceptsType(NullType.INSTANCE)); + Assertions.assertTrue(dateType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dateType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dateType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dateType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dateType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dateType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testNumericAccept() { + NumericType dataType = NumericType.INSTANCE; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertTrue(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testIntegralAccept() { + IntegralType dataType = IntegralType.INSTANCE; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testTinyIntAccept() { + TinyIntType dataType = TinyIntType.INSTANCE; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testSmallIntAccept() { + SmallIntType dataType = SmallIntType.INSTANCE; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testIntAccept() { + IntegerType dataType = IntegerType.INSTANCE; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testBigIntAccept() { + BigIntType dataType = BigIntType.INSTANCE; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testLargeIntAccept() { + LargeIntType dataType = LargeIntType.INSTANCE; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testFractionalAccept() { + FractionalType dataType = FractionalType.INSTANCE; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertTrue(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testFloatAccept() { + FloatType dataType = FloatType.INSTANCE; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testDoubleAccept() { + DoubleType dataType = DoubleType.INSTANCE; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testDecimalAccept() { + DecimalV2Type dataType = DecimalV2Type.SYSTEM_DEFAULT; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertTrue(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testCharAccept() { + CharType dataType = CharType.createCharType(10); + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertTrue(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testVarcharAccept() { + VarcharType dataType = VarcharType.SYSTEM_DEFAULT; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertTrue(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertTrue(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testStringAccept() { + StringType dataType = StringType.INSTANCE; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertTrue(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertTrue(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testDateAccept() { + DateType dataType = DateType.INSTANCE; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testDateTimeAccept() { + DateTimeType dataType = DateTimeType.INSTANCE; + Assertions.assertFalse(dataType.acceptsType(NullType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BooleanType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(TinyIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(SmallIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(IntegerType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(BigIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(LargeIntType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(FloatType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DoubleType.INSTANCE)); + int precision = Math.abs(new Random().nextInt() % (DecimalV2Type.MAX_PRECISION - 1)) + 1; + int scale = Math.min(precision, Math.abs(new Random().nextInt() % DecimalV2Type.MAX_SCALE)); + Assertions.assertFalse(dataType.acceptsType(new DecimalV2Type(precision, scale))); + Assertions.assertFalse(dataType.acceptsType(new CharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(new VarcharType(new Random().nextInt()))); + Assertions.assertFalse(dataType.acceptsType(StringType.INSTANCE)); + Assertions.assertFalse(dataType.acceptsType(DateType.INSTANCE)); + Assertions.assertTrue(dataType.acceptsType(DateTimeType.INSTANCE)); + } + + @Test + public void testSimpleName() { + Assertions.assertEquals("null", NullType.INSTANCE.simpleString()); + Assertions.assertEquals("boolean", BooleanType.INSTANCE.simpleString()); + Assertions.assertEquals("numeric", NumericType.INSTANCE.simpleString()); + Assertions.assertEquals("integral", IntegralType.INSTANCE.simpleString()); + Assertions.assertEquals("tinyint", TinyIntType.INSTANCE.simpleString()); + Assertions.assertEquals("smallint", SmallIntType.INSTANCE.simpleString()); + Assertions.assertEquals("int", IntegerType.INSTANCE.simpleString()); + Assertions.assertEquals("bigint", BigIntType.INSTANCE.simpleString()); + Assertions.assertEquals("largeint", LargeIntType.INSTANCE.simpleString()); + Assertions.assertEquals("fractional", FractionalType.INSTANCE.simpleString()); + Assertions.assertEquals("float", FloatType.INSTANCE.simpleString()); + Assertions.assertEquals("double", DoubleType.INSTANCE.simpleString()); + Assertions.assertEquals("decimal", DecimalV2Type.SYSTEM_DEFAULT.simpleString()); + Assertions.assertEquals("char", new CharType(10).simpleString()); + Assertions.assertEquals("varchar", VarcharType.SYSTEM_DEFAULT.simpleString()); + Assertions.assertEquals("string", StringType.INSTANCE.simpleString()); + Assertions.assertEquals("date", DateType.INSTANCE.simpleString()); + Assertions.assertEquals("datetime", DateTimeType.INSTANCE.simpleString()); + } + + @Test + public void testDefaultConcreteType() { + Assertions.assertEquals(NullType.INSTANCE, NullType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(BooleanType.INSTANCE, BooleanType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(DoubleType.INSTANCE, NumericType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(BigIntType.INSTANCE, IntegralType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(TinyIntType.INSTANCE, TinyIntType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(SmallIntType.INSTANCE, SmallIntType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(IntegerType.INSTANCE, IntegerType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(BigIntType.INSTANCE, BigIntType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(LargeIntType.INSTANCE, LargeIntType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(DoubleType.INSTANCE, FractionalType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(FloatType.INSTANCE, FloatType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(DoubleType.INSTANCE, DoubleType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(DecimalV2Type.SYSTEM_DEFAULT, DecimalV2Type.SYSTEM_DEFAULT.defaultConcreteType()); + Assertions.assertEquals(new CharType(10), new CharType(10).defaultConcreteType()); + Assertions.assertEquals(VarcharType.SYSTEM_DEFAULT, VarcharType.SYSTEM_DEFAULT.defaultConcreteType()); + Assertions.assertEquals(StringType.INSTANCE, StringType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(DateType.INSTANCE, DateType.INSTANCE.defaultConcreteType()); + Assertions.assertEquals(DateTimeType.INSTANCE, DateTimeType.INSTANCE.defaultConcreteType()); + } } diff --git a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out index 69ac30a140..79a8da76a2 100644 --- a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out +++ b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out @@ -1655,5 +1655,5 @@ [2023-01-19 18:22:22.222, 2023-01-19 18:33:33.333, 2023-01-19 18:44:44.444] -- !select_array_datetimev2_4 -- -[2023-01-19 18:11:11.111, 2023-01-19 18:22:22.222, 2023-01-19 18:33:33.333] +[2023-01-19 18:11:11.111111, 2023-01-19 18:22:22.222222, 2023-01-19 18:33:33.333333] diff --git a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out index 8e69544962..5d7965b29d 100644 --- a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out +++ b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out @@ -9,7 +9,7 @@ ["a", "2.0", NULL, NULL, "2.0"] -- !sql_1 -- -[1, 2, NULL, NULL, 2] +[1.0, 2.0, NULL, NULL, 2.0] -- !sql_2 -- [NULL, NULL, 1.0, 2.0, 2.0] diff --git a/regression-test/suites/nereids_arith_p0/bitmap.groovy b/regression-test/suites/nereids_arith_p0/bitmap.groovy index d4df60f8dd..8e7f6cbf54 100644 --- a/regression-test/suites/nereids_arith_p0/bitmap.groovy +++ b/regression-test/suites/nereids_arith_p0/bitmap.groovy @@ -21,8 +21,8 @@ suite('bitmap') { sql 'set enable_fallback_to_original_planner=false' test { sql "select id from (select BITMAP_EMPTY() as c0 from expr_test) as ref0 where c0 = 1 order by id" - exception "errCode = 2, detailMessage = Unexpected exception: can not cast from origin type BITMAP to target type=DOUBLE" + exception "can not cast from origin type BITMAP to target type=DOUBLE" sql "select id from expr_test group by id having ktint in (select BITMAP_EMPTY() from expr_test) order by id" - exception "errCode = 2, detailMessage = Unexpected exception: Doris hll, bitmap, array, map, struct, jsonb column must use with specific function," + exception "Doris hll, bitmap, array, map, struct, jsonb column must use with specific function," } } diff --git a/regression-test/suites/nereids_p0/except/test_analyzer_exception.groovy b/regression-test/suites/nereids_p0/except/test_analyzer_exception.groovy index 17a79afcd4..989331e917 100644 --- a/regression-test/suites/nereids_p0/except/test_analyzer_exception.groovy +++ b/regression-test/suites/nereids_p0/except/test_analyzer_exception.groovy @@ -25,6 +25,6 @@ suite("test_analyzer_exception") { test { sql "SELECT id FROM ${tbName}" - exception "errCode = 2, detailMessage = Unexpected exception: Table [test_analyzer_exception] does not exist in database [default_cluster:test_analyzer_db]." + exception "Table [test_analyzer_exception] does not exist in database [default_cluster:test_analyzer_db]." } } diff --git a/regression-test/suites/nereids_p0/except/test_bound_exception.groovy b/regression-test/suites/nereids_p0/except/test_bound_exception.groovy index 02b29b6517..9fcd2c2667 100644 --- a/regression-test/suites/nereids_p0/except/test_bound_exception.groovy +++ b/regression-test/suites/nereids_p0/except/test_bound_exception.groovy @@ -30,26 +30,26 @@ suite("test_bound_exception") { """ test { sql "SELECT id FROM ${tbName} GROUP BY id ORDER BY id123" - exception "errCode = 2, detailMessage = Unexpected exception: unbounded object id123 in SORT clause." + exception "unbounded object id123 in SORT clause." } test { sql "SELECT id123 FROM ${tbName} ORDER BY id" - exception "errCode = 2, detailMessage = Unexpected exception: unbounded object id123 in PROJECT clause." + exception "unbounded object id123 in PROJECT clause." } test { sql "SELECT id123 FROM ${tbName} GROUP BY id ORDER BY id" - exception "errCode = 2, detailMessage = Unexpected exception: unbounded object id123 in AGGREGATE clause." + exception "unbounded object id123 in AGGREGATE clause." } test { sql "SELECT id FROM ${tbName} GROUP BY id123 ORDER BY id" - exception "errCode = 2, detailMessage = Unexpected exception: cannot bind GROUP BY KEY: id123" + exception "cannot bind GROUP BY KEY: id123" } test { sql "SELECT id FROM ${tbName} WHERE id = (SELECT id from ${tbName} ORDER BY id123 LIMIT 1) ORDER BY id" - exception "errCode = 2, detailMessage = Unexpected exception: unbounded object id123 in SORT clause." + exception "unbounded object id123 in SORT clause." } test { sql "SELECT id FROM ${tbName} WHERE id123 = 123 ORDER BY id" - exception "errCode = 2, detailMessage = Unexpected exception: Invalid call to id123.getDataType() on unbound object" + exception "Invalid call to id123.getDataType() on unbound object" } } diff --git a/regression-test/suites/nereids_p0/insert_into_table/aggregate.groovy b/regression-test/suites/nereids_p0/insert_into_table/aggregate.groovy index 93479561e3..360acaaa54 100644 --- a/regression-test/suites/nereids_p0/insert_into_table/aggregate.groovy +++ b/regression-test/suites/nereids_p0/insert_into_table/aggregate.groovy @@ -25,65 +25,65 @@ suite("nereids_insert_aggregate") { sql 'set enable_strict_consistency_dml=true' sql '''insert into nereids_insert_into_table_test.agg_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_11 'select * from agg_t order by id, kint' sql '''insert into nereids_insert_into_table_test.agg_t with label label_agg_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_12 'select * from agg_t order by id, kint' sql '''insert into nereids_insert_into_table_test.agg_t partition (p1, p2) with label label_agg - select * except(kaint) from src where id < 4''' + select * except(kaint, kmintint) from src where id < 4''' sql 'sync' qt_13 'select * from agg_t order by id, kint' sql '''insert into nereids_insert_into_table_test.agg_light_sc_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_21 'select * from agg_light_sc_t order by id, kint' sql '''insert into nereids_insert_into_table_test.agg_light_sc_t with label label_agg_light_sc_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' qt_22 'select * from agg_light_sc_t order by id, kint' sql '''insert into nereids_insert_into_table_test.agg_light_sc_t partition (p1, p2) with label label_agg_light_sc - select * except(kaint) from src where id < 4''' + select * except(kaint, kmintint) from src where id < 4''' sql 'sync' qt_23 'select * from agg_light_sc_t order by id, kint' sql '''insert into nereids_insert_into_table_test.agg_not_null_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_31 'select * from agg_not_null_t order by id, kint' sql '''insert into nereids_insert_into_table_test.agg_not_null_t with label label_agg_not_null_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_32 'select * from agg_not_null_t order by id, kint' sql '''insert into nereids_insert_into_table_test.agg_not_null_t partition (p1, p2) with label label_agg_not_null - select * except(kaint) from src where id < 4 and id is not null''' + select * except(kaint, kmintint) from src where id < 4 and id is not null''' sql 'sync' qt_33 'select * from agg_not_null_t order by id, kint' sql '''insert into nereids_insert_into_table_test.agg_light_sc_not_null_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_41 'select * from agg_light_sc_not_null_t order by id, kint' sql '''insert into nereids_insert_into_table_test.agg_light_sc_not_null_t with label label_agg_light_sc_not_null_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_42 'select * from agg_light_sc_not_null_t order by id, kint' sql '''insert into nereids_insert_into_table_test.agg_light_sc_not_null_t partition (p1, p2) with label label_agg_light_sc_not_null - select * except(kaint) from src where id < 4 and id is not null''' + select * except(kaint, kmintint) from src where id < 4 and id is not null''' sql 'sync' qt_43 'select * from agg_light_sc_not_null_t order by id, kint' @@ -92,12 +92,12 @@ suite("nereids_insert_aggregate") { sql 'alter table agg_light_sc_not_null_t rename column ktint ktinyint' sql '''insert into nereids_insert_into_table_test.agg_light_sc_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_lsc1 'select * from agg_light_sc_t order by id, kint' sql '''insert into nereids_insert_into_table_test.agg_light_sc_not_null_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_lsc2 'select * from agg_light_sc_not_null_t order by id, kint' diff --git a/regression-test/suites/nereids_p0/insert_into_table/ddl/arr_t.sql b/regression-test/suites/nereids_p0/insert_into_table/ddl/map_t.sql similarity index 68% rename from regression-test/suites/nereids_p0/insert_into_table/ddl/arr_t.sql rename to regression-test/suites/nereids_p0/insert_into_table/ddl/map_t.sql index 17ed0de562..146268ded9 100644 --- a/regression-test/suites/nereids_p0/insert_into_table/ddl/arr_t.sql +++ b/regression-test/suites/nereids_p0/insert_into_table/ddl/map_t.sql @@ -1,6 +1,6 @@ -create table arr_t ( +create table map_t ( `id` int null, - `kaint` array null + `km_int_int` map null ) engine=OLAP duplicate key(id) diff --git a/regression-test/suites/nereids_p0/insert_into_table/duplicate.groovy b/regression-test/suites/nereids_p0/insert_into_table/duplicate.groovy index 8b655cc9d8..546f16e216 100644 --- a/regression-test/suites/nereids_p0/insert_into_table/duplicate.groovy +++ b/regression-test/suites/nereids_p0/insert_into_table/duplicate.groovy @@ -25,66 +25,66 @@ suite("nereids_insert_duplicate") { sql 'set enable_strict_consistency_dml=true' sql '''insert into dup_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_11 'select * from dup_t order by id, kint' sql '''insert into dup_t with label label_dup_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_12 'select * from dup_t order by id, kint' sql '''insert into dup_t partition (p1, p2) with label label_dup - select * except(kaint) from src where id < 4''' + select * except(kaint, kmintint) from src where id < 4''' sql 'sync' qt_13 'select * from dup_t order by id, kint' sql '''insert into dup_light_sc_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_21 'select * from dup_light_sc_t order by id, kint' sql '''insert into dup_light_sc_t with label label_dup_light_sc_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_22 'select * from dup_light_sc_t order by id, kint' sql '''insert into dup_light_sc_t partition (p1, p2) with label label_dup_light_sc - select * except(kaint) from src where id < 4''' + select * except(kaint, kmintint) from src where id < 4''' sql 'sync' qt_23 'select * from dup_light_sc_t order by id, kint' sql '''insert into dup_not_null_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_31 'select * from dup_not_null_t order by id, kint' sql '''insert into dup_not_null_t with label label_dup_not_null_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_32 'select * from dup_not_null_t order by id, kint' sql '''insert into dup_not_null_t partition (p1, p2) with label label_dup_not_null - select * except(kaint) from src where id < 4 and id is not null''' + select * except(kaint, kmintint) from src where id < 4 and id is not null''' sql 'sync' qt_33 'select * from dup_not_null_t order by id, kint' sql '''insert into dup_light_sc_not_null_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_41 'select * from dup_light_sc_not_null_t order by id, kint' sql '''insert into dup_light_sc_not_null_t with label label_dup_light_sc_not_null_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_42 'select * from dup_light_sc_not_null_t order by id, kint' sql '''insert into dup_light_sc_not_null_t partition (p1, p2) with label label_dup_light_sc_not_null - select * except(kaint) from src where id < 4 and id is not null''' + select * except(kaint, kmintint) from src where id < 4 and id is not null''' sql 'sync' qt_43 'select * from dup_light_sc_not_null_t order by id, kint' @@ -93,12 +93,12 @@ suite("nereids_insert_duplicate") { sql 'alter table dup_light_sc_not_null_t rename column ktint ktinyint' sql '''insert into dup_light_sc_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_lsc1 'select * from dup_light_sc_t order by id, kint' sql '''insert into dup_light_sc_not_null_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_lsc2 'select * from dup_light_sc_not_null_t order by id, kint' diff --git a/regression-test/suites/nereids_p0/insert_into_table/load.groovy b/regression-test/suites/nereids_p0/insert_into_table/load.groovy index c32433a182..0b2f6fc213 100644 --- a/regression-test/suites/nereids_p0/insert_into_table/load.groovy +++ b/regression-test/suites/nereids_p0/insert_into_table/load.groovy @@ -42,7 +42,8 @@ suite("load") { `kdcml32v3` decimalv3(7, 3) null, `kdcml64v3` decimalv3(10, 5) null, `kdcml128v3` decimalv3(20, 8) null, - `kaint` array null + `kaint` array null, + `kmintint` map null ) engine=OLAP duplicate key(id) distributed by hash(id) buckets 4 @@ -66,7 +67,7 @@ suite("load") { 'agg_nop_t', 'agg_t', 'agg_type_cast', 'dup_nop_t', 'dup_t', 'dup_type_cast', 'uni_nop_t', 'uni_t', 'uni_type_cast', - 'arr_t', 'random_t' + 'map_t', 'random_t' ] for (String file in files) { diff --git a/regression-test/suites/nereids_p0/insert_into_table/no_partition.groovy b/regression-test/suites/nereids_p0/insert_into_table/no_partition.groovy index d5f39b76b8..666188d618 100644 --- a/regression-test/suites/nereids_p0/insert_into_table/no_partition.groovy +++ b/regression-test/suites/nereids_p0/insert_into_table/no_partition.groovy @@ -28,7 +28,7 @@ suite('nereids_insert_no_partition') { // TODO: test turn off pipeline when dml, remove it if pipeline sink is ok sql ''' insert into uni_light_sc_mow_not_null_nop_t with t as( - select * except(kaint) from src where id is not null) + select * except(kaint, kmintint) from src where id is not null) select * from t left semi join t t2 on t.id = t2.id; ''' @@ -36,176 +36,176 @@ suite('nereids_insert_no_partition') { } sql '''insert into agg_nop_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_11 'select * from agg_nop_t order by id, kint' sql '''insert into agg_nop_t with label label_agg_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_12 'select * from agg_nop_t order by id, kint' sql '''insert into agg_light_sc_nop_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_21 'select * from agg_light_sc_nop_t order by id, kint' sql '''insert into agg_light_sc_nop_t with label label_agg_light_sc_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_22 'select * from agg_light_sc_nop_t order by id, kint' sql '''insert into agg_not_null_nop_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_31 'select * from agg_not_null_nop_t order by id, kint' sql '''insert into agg_not_null_nop_t with label label_agg_not_null_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_32 'select * from agg_not_null_nop_t order by id, kint' sql '''insert into agg_light_sc_not_null_nop_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_41 'select * from agg_light_sc_not_null_nop_t order by id, kint' sql '''insert into agg_light_sc_not_null_nop_t with label label_agg_light_sc_not_null_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_42 'select * from agg_light_sc_not_null_nop_t order by id, kint' sql '''insert into dup_nop_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_11 'select * from dup_nop_t order by id, kint' sql '''insert into dup_nop_t with label label_dup_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_12 'select * from dup_nop_t order by id, kint' sql '''insert into dup_light_sc_nop_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_21 'select * from dup_light_sc_nop_t order by id, kint' sql '''insert into dup_light_sc_nop_t with label label_dup_light_sc_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_22 'select * from dup_light_sc_nop_t order by id, kint' sql '''insert into dup_not_null_nop_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_31 'select * from dup_not_null_nop_t order by id, kint' sql '''insert into dup_not_null_nop_t with label label_dup_not_null_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_32 'select * from dup_not_null_nop_t order by id, kint' sql '''insert into dup_light_sc_not_null_nop_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_41 'select * from dup_light_sc_not_null_nop_t order by id, kint' sql '''insert into dup_light_sc_not_null_nop_t with label label_dup_light_sc_not_null_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_42 'select * from dup_light_sc_not_null_nop_t order by id, kint' sql '''insert into uni_nop_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_11 'select * from uni_nop_t order by id, kint' sql '''insert into uni_nop_t with label label_uni_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_12 'select * from uni_nop_t order by id, kint' sql '''insert into uni_light_sc_nop_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' qt_21 'select * from uni_light_sc_nop_t order by id, kint' sql '''insert into uni_light_sc_nop_t with label label_uni_light_sc_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_22 'select * from uni_light_sc_nop_t order by id, kint' sql '''insert into uni_mow_nop_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_31 'select * from uni_mow_nop_t order by id, kint' sql '''insert into uni_mow_nop_t with label label_uni_mow_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_32 'select * from uni_mow_nop_t order by id, kint' sql '''insert into uni_light_sc_mow_nop_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_41 'select * from uni_light_sc_mow_nop_t order by id, kint' sql '''insert into uni_light_sc_mow_nop_t with label label_uni_light_sc_mow_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_42 'select * from uni_light_sc_mow_nop_t order by id, kint' sql '''insert into uni_mow_not_null_nop_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_51 'select * from uni_mow_not_null_nop_t order by id, kint' sql '''insert into uni_mow_not_null_nop_t with label label_uni_not_null_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_52 'select * from uni_mow_not_null_nop_t order by id, kint' sql '''insert into uni_light_sc_mow_not_null_nop_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_61 'select * from uni_light_sc_mow_not_null_nop_t order by id, kint' sql '''insert into uni_light_sc_mow_not_null_nop_t with label label_uni_light_sc_not_null_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_62 'select * from uni_light_sc_mow_not_null_nop_t order by id, kint' sql '''insert into uni_mow_not_null_nop_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_71 'select * from uni_mow_not_null_nop_t order by id, kint' sql '''insert into uni_mow_not_null_nop_t with label label_uni_mow_not_null_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_72 'select * from uni_mow_not_null_nop_t order by id, kint' sql '''insert into uni_light_sc_mow_not_null_nop_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_81 'select * from uni_light_sc_mow_not_null_nop_t order by id, kint' sql '''insert into uni_light_sc_mow_not_null_nop_t with label label_uni_light_sc_mow_not_null_cte_nop - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_82 'select * from uni_light_sc_mow_not_null_nop_t order by id, kint' @@ -215,12 +215,12 @@ suite('nereids_insert_no_partition') { sql 'alter table agg_light_sc_not_null_nop_t rename column ktint ktinyint' sql '''insert into agg_light_sc_nop_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_lsc1 'select * from agg_light_sc_nop_t order by id, kint' sql '''insert into agg_light_sc_not_null_nop_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_lsc2 'select * from agg_light_sc_not_null_nop_t order by id, kint' @@ -229,12 +229,12 @@ suite('nereids_insert_no_partition') { sql 'alter table dup_light_sc_not_null_nop_t rename column ktint ktinyint' sql '''insert into dup_light_sc_nop_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_lsc1 'select * from dup_light_sc_nop_t order by id, kint' sql '''insert into dup_light_sc_not_null_nop_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_lsc2 'select * from dup_light_sc_not_null_nop_t order by id, kint' @@ -245,22 +245,22 @@ suite('nereids_insert_no_partition') { sql 'alter table uni_light_sc_mow_not_null_nop_t rename column ktint ktinyint' sql '''insert into uni_light_sc_nop_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_lsc1 'select * from uni_light_sc_nop_t order by id, kint' sql '''insert into uni_light_sc_not_null_nop_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_lsc2 'select * from uni_light_sc_not_null_nop_t order by id, kint' sql '''insert into uni_light_sc_mow_nop_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_lsc3 'select * from uni_light_sc_mow_nop_t order by id, kint' sql '''insert into uni_light_sc_mow_not_null_nop_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_lsc4 'select * from uni_light_sc_mow_not_null_nop_t order by id, kint' diff --git a/regression-test/suites/nereids_p0/insert_into_table/unique.groovy b/regression-test/suites/nereids_p0/insert_into_table/unique.groovy index 685883ef6e..bdad2aa902 100644 --- a/regression-test/suites/nereids_p0/insert_into_table/unique.groovy +++ b/regression-test/suites/nereids_p0/insert_into_table/unique.groovy @@ -25,130 +25,130 @@ suite("nereids_insert_unique") { sql 'set enable_strict_consistency_dml=true' sql '''insert into uni_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_11 'select * from uni_t order by id, kint' sql '''insert into uni_t with label label_uni_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_12 'select * from uni_t order by id, kint' sql '''insert into uni_t partition (p1, p2) with label label_uni - select * except(kaint) from src where id < 4''' + select * except(kaint, kmintint) from src where id < 4''' sql 'sync' qt_13 'select * from uni_t order by id, kint' sql '''insert into uni_light_sc_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_21 'select * from uni_light_sc_t order by id, kint' sql '''insert into uni_light_sc_t with label label_uni_light_sc_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_22 'select * from uni_light_sc_t order by id, kint' sql '''insert into uni_light_sc_t partition (p1, p2) with label label_uni_light_sc - select * except(kaint) from src where id < 4''' + select * except(kaint, kmintint) from src where id < 4''' sql 'sync' qt_23 'select * from uni_light_sc_t order by id, kint' sql '''insert into uni_mow_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_31 'select * from uni_mow_t order by id, kint' sql '''insert into uni_mow_t with label label_uni_mow_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_32 'select * from uni_mow_t order by id, kint' sql '''insert into uni_mow_t partition (p1, p2) with label label_uni_mow - select * except(kaint) from src where id < 4''' + select * except(kaint, kmintint) from src where id < 4''' sql 'sync' qt_33 'select * from uni_mow_t order by id, kint' sql '''insert into uni_light_sc_mow_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_41 'select * from uni_light_sc_mow_t order by id, kint' sql '''insert into uni_light_sc_mow_t with label label_uni_light_sc_mow_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte''' sql 'sync' qt_42 'select * from uni_light_sc_mow_t order by id, kint' sql '''insert into uni_light_sc_mow_t partition (p1, p2) with label label_uni_light_sc_mow - select * except(kaint) from src where id < 4''' + select * except(kaint, kmintint) from src where id < 4''' sql 'sync' qt_43 'select * from uni_light_sc_mow_t order by id, kint' sql '''insert into uni_mow_not_null_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_51 'select * from uni_mow_not_null_t order by id, kint' sql '''insert into uni_mow_not_null_t with label label_uni_not_null_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_52 'select * from uni_mow_not_null_t order by id, kint' sql '''insert into uni_mow_not_null_t partition (p1, p2) with label label_uni_not_null - select * except(kaint) from src where id < 4 and id is not null''' + select * except(kaint, kmintint) from src where id < 4 and id is not null''' sql 'sync' qt_53 'select * from uni_mow_not_null_t order by id, kint' sql '''insert into uni_light_sc_mow_not_null_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_61 'select * from uni_light_sc_mow_not_null_t order by id, kint' sql '''insert into uni_light_sc_mow_not_null_t with label label_uni_light_sc_not_null_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_62 'select * from uni_light_sc_mow_not_null_t order by id, kint' sql '''insert into uni_light_sc_mow_not_null_t partition (p1, p2) with label label_uni_light_sc_not_null - select * except(kaint) from src where id < 4 and id is not null''' + select * except(kaint, kmintint) from src where id < 4 and id is not null''' sql 'sync' qt_63 'select * from uni_light_sc_mow_not_null_t order by id, kint' sql '''insert into uni_mow_not_null_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_71 'select * from uni_mow_not_null_t order by id, kint' sql '''insert into uni_mow_not_null_t with label label_uni_mow_not_null_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_72 'select * from uni_mow_not_null_t order by id, kint' sql '''insert into uni_mow_not_null_t partition (p1, p2) with label label_uni_mow_not_null - select * except(kaint) from src where id < 4 and id is not null''' + select * except(kaint, kmintint) from src where id < 4 and id is not null''' sql 'sync' qt_73 'select * from uni_mow_not_null_t order by id, kint' sql '''insert into uni_light_sc_mow_not_null_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_81 'select * from uni_light_sc_mow_not_null_t order by id, kint' sql '''insert into uni_light_sc_mow_not_null_t with label label_uni_light_sc_mow_not_null_cte - with cte as (select * except(kaint) from src) + with cte as (select * except(kaint, kmintint) from src) select * from cte where id is not null''' sql 'sync' qt_82 'select * from uni_light_sc_mow_not_null_t order by id, kint' sql '''insert into uni_light_sc_mow_not_null_t partition (p1, p2) with label label_uni_light_sc_mow_not_null - select * except(kaint) from src where id < 4 and id is not null''' + select * except(kaint, kmintint) from src where id < 4 and id is not null''' sql 'sync' qt_83 'select * from uni_light_sc_mow_not_null_t order by id, kint' @@ -159,22 +159,22 @@ suite("nereids_insert_unique") { sql 'alter table uni_light_sc_mow_not_null_t rename column ktint ktinyint' sql '''insert into uni_light_sc_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_lsc1 'select * from uni_light_sc_t order by id, kint' sql '''insert into uni_light_sc_not_null_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_lsc2 'select * from uni_light_sc_not_null_t order by id, kint' sql '''insert into uni_light_sc_mow_t - select * except(kaint) from src''' + select * except(kaint, kmintint) from src''' sql 'sync' qt_lsc3 'select * from uni_light_sc_mow_t order by id, kint' sql '''insert into uni_light_sc_mow_not_null_t - select * except(kaint) from src where id is not null''' + select * except(kaint, kmintint) from src where id is not null''' sql 'sync' qt_lsc4 'select * from uni_light_sc_mow_not_null_t order by id, kint' diff --git a/regression-test/suites/nereids_p0/insert_into_table/unsupport_type.groovy b/regression-test/suites/nereids_p0/insert_into_table/unsupport_type.groovy index 08d691982a..6edff4132d 100644 --- a/regression-test/suites/nereids_p0/insert_into_table/unsupport_type.groovy +++ b/regression-test/suites/nereids_p0/insert_into_table/unsupport_type.groovy @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -suite("nereids_insert_array_type") { +suite("nereids_insert_unsupport_type") { sql 'use nereids_insert_into_table_test' sql 'set enable_nereids_planner=true' @@ -24,13 +24,13 @@ suite("nereids_insert_array_type") { sql 'set enable_strict_consistency_dml=true' test { - sql 'insert into arr_t select id, kaint from src' - exception 'type ARRAY is unsupported for Nereids' + sql 'insert into map_t select id, kmintint from src' + exception 'unsupported for Nereids' } sql 'set enable_fallback_to_original_planner=true' - sql 'insert into arr_t select id, kaint from src' + sql 'insert into map_t select id, kmintint from src' sql 'sync' - sql 'select * from arr_t' + sql 'select * from map_t' } \ No newline at end of file diff --git a/regression-test/suites/nereids_p0/subquery/test_duplicate_name_in_view.groovy b/regression-test/suites/nereids_p0/subquery/test_duplicate_name_in_view.groovy index fd5f093a3e..0f9842dc25 100644 --- a/regression-test/suites/nereids_p0/subquery/test_duplicate_name_in_view.groovy +++ b/regression-test/suites/nereids_p0/subquery/test_duplicate_name_in_view.groovy @@ -54,7 +54,7 @@ suite("inlineview_with_project") { select * from issue_19611_t0, issue_19611_t1 where issue_19611_t1.c0 != 0 union select * from issue_19611_t0, issue_19611_t1 where issue_19611_t1.c0 = 0) tmp; """ - exception "errCode = 2, detailMessage = Unexpected exception: Duplicated inline view column alias: 'c0' in inline view: 'tmp'" + exception "Duplicated inline view column alias: 'c0' in inline view: 'tmp'" } diff --git a/regression-test/suites/nereids_syntax_p0/advance_mv.groovy b/regression-test/suites/nereids_syntax_p0/advance_mv.groovy index ea5693dc06..5bc87822de 100644 --- a/regression-test/suites/nereids_syntax_p0/advance_mv.groovy +++ b/regression-test/suites/nereids_syntax_p0/advance_mv.groovy @@ -99,10 +99,10 @@ suite("advance_mv") { createMV("CREATE materialized VIEW mv2 AS SELECT abs(k1)+k2+1 tmp, sum(abs(k2+2)+k3+3) FROM ${tbName2} GROUP BY tmp;") explain { - sql("SELECT abs(k1)+k2+1 tmp, sum(abs(k2+2)+k3+3) from FROM ${tbName2} GROUP BY tmp;") + sql("SELECT abs(k1)+k2+1 tmp, sum(abs(k2+2)+k3+3) FROM ${tbName2} GROUP BY tmp;") contains "(mv2)" } - order_qt_select_star "SELECT abs(k1)+k2+1 tmp, sum(abs(k2+2)+k3+3) from FROM ${tbName2} GROUP BY tmp;" + order_qt_select_star "SELECT abs(k1)+k2+1 tmp, sum(abs(k2+2)+k3+3) FROM ${tbName2} GROUP BY tmp;" sql "CREATE materialized VIEW mv3 AS SELECT abs(k1)+k2+1 tmp, abs(k2+2)+k3+3 FROM ${tbName2};" int max_try_secs2 = 60 diff --git a/regression-test/suites/nereids_syntax_p0/bind_priority.groovy b/regression-test/suites/nereids_syntax_p0/bind_priority.groovy index 01a08892cd..ad9e3fad3c 100644 --- a/regression-test/suites/nereids_syntax_p0/bind_priority.groovy +++ b/regression-test/suites/nereids_syntax_p0/bind_priority.groovy @@ -53,7 +53,7 @@ suite("bind_priority") { sql """ select sum(a) as v from bind_priority_tbl group by v; """ - exception "Unexpected exception: cannot bind GROUP BY KEY: v" + exception "cannot bind GROUP BY KEY: v" } sql "drop table if exists bind_priority_tbl" @@ -116,7 +116,7 @@ suite("bind_priority") { test{ sql "SELECT a,2 as a FROM (SELECT '1' as a) b HAVING a=1" - exception "Unexpected exception: a is ambiguous: a#0, a#1." + exception "a is ambiguous: a#0, a#1." } sql "drop table if exists duplicate_slot"; diff --git a/regression-test/suites/nereids_syntax_p0/forbid_unexpected_type.groovy b/regression-test/suites/nereids_syntax_p0/forbid_unexpected_type.groovy index 6492500889..8f7fef423d 100644 --- a/regression-test/suites/nereids_syntax_p0/forbid_unexpected_type.groovy +++ b/regression-test/suites/nereids_syntax_p0/forbid_unexpected_type.groovy @@ -40,7 +40,7 @@ suite("forbid_unexpected_type") { sql """ select * from forbid_unexpected_types where bitmap_union_count(bitmap_empty()) is NULL; """ - exception "Unexpected exception: LOGICAL_FILTER can not contains AggregateFunction" + exception "LOGICAL_FILTER can not contains AggregateFunction" } // window function's partition by could not have bitmap @@ -48,7 +48,7 @@ suite("forbid_unexpected_type") { sql """ select min(version()) over (partition by bitmap_union(bitmap_empty())) as c0 from forbid_unexpected_types """ - exception "Unexpected exception: Doris hll, bitmap, array, map, struct, jsonb column" + exception "Doris hll, bitmap, array, map, struct, jsonb column" } // window function's order by could not have bitmap @@ -56,7 +56,7 @@ suite("forbid_unexpected_type") { sql """ select min(version()) over (partition by 1 order by bitmap_union(bitmap_empty())) as c0 from forbid_unexpected_types """ - exception "Unexpected exception: Doris hll, bitmap, array, map, struct, jsonb column" + exception "Doris hll, bitmap, array, map, struct, jsonb column" } } diff --git a/regression-test/suites/nereids_syntax_p0/grouping_sets.groovy b/regression-test/suites/nereids_syntax_p0/grouping_sets.groovy index d5298d154e..0845d705e8 100644 --- a/regression-test/suites/nereids_syntax_p0/grouping_sets.groovy +++ b/regression-test/suites/nereids_syntax_p0/grouping_sets.groovy @@ -143,7 +143,7 @@ suite("test_nereids_grouping_sets") { SELECT k1, k2, SUM(k3) FROM groupingSetsTable GROUP BY GROUPING SETS ((k1, k2), (k1), (k2), ( ), (k3) ) order by k1, k2 """ - exception "java.sql.SQLException: errCode = 2, detailMessage = Unexpected exception: column: k3 cannot both in select list and aggregate functions when using GROUPING SETS/CUBE/ROLLUP, please use union instead." + exception "java.sql.SQLException: errCode = 2, detailMessage = column: k3 cannot both in select list and aggregate functions when using GROUPING SETS/CUBE/ROLLUP, please use union instead." } test { @@ -151,7 +151,7 @@ suite("test_nereids_grouping_sets") { SELECT k1, k2, SUM(k3)/(SUM(k3)+1) FROM groupingSetsTable GROUP BY GROUPING SETS ((k1, k2), (k1), (k2), ( ), (k3) ) order by k1, k2 """ - exception "java.sql.SQLException: errCode = 2, detailMessage = Unexpected exception: column: k3 cannot both in select list and aggregate functions when using GROUPING SETS/CUBE/ROLLUP, please use union instead." + exception "java.sql.SQLException: errCode = 2, detailMessage = column: k3 cannot both in select list and aggregate functions when using GROUPING SETS/CUBE/ROLLUP, please use union instead." } order_qt_select """ diff --git a/regression-test/suites/nereids_syntax_p0/sub_query_diff_old_optimize.groovy b/regression-test/suites/nereids_syntax_p0/sub_query_diff_old_optimize.groovy index 6327b6c8aa..7a3bc41948 100644 --- a/regression-test/suites/nereids_syntax_p0/sub_query_diff_old_optimize.groovy +++ b/regression-test/suites/nereids_syntax_p0/sub_query_diff_old_optimize.groovy @@ -92,21 +92,21 @@ suite ("sub_query_diff_old_optimize") { sql """ select * from sub_query_diff_old_optimize_subquery1 where sub_query_diff_old_optimize_subquery1.k1 < (select sum(sub_query_diff_old_optimize_subquery3.k3) from sub_query_diff_old_optimize_subquery3 where sub_query_diff_old_optimize_subquery3.v2 < sub_query_diff_old_optimize_subquery1.k2) order by k1, k2 """ - exception "java.sql.SQLException: errCode = 2, detailMessage = Unexpected exception: scalar subquery's correlatedPredicates's operator must be EQ" + exception "java.sql.SQLException: errCode = 2, detailMessage = scalar subquery's correlatedPredicates's operator must be EQ" } test { sql """ select * from sub_query_diff_old_optimize_subquery1 where sub_query_diff_old_optimize_subquery1.k1 != (select sum(sub_query_diff_old_optimize_subquery3.k3) from sub_query_diff_old_optimize_subquery3 where sub_query_diff_old_optimize_subquery3.v2 != sub_query_diff_old_optimize_subquery1.k2) order by k1, k2 """ - exception "java.sql.SQLException: errCode = 2, detailMessage = Unexpected exception: scalar subquery's correlatedPredicates's operator must be EQ" + exception "java.sql.SQLException: errCode = 2, detailMessage = scalar subquery's correlatedPredicates's operator must be EQ" } test { sql """ select * from sub_query_diff_old_optimize_subquery1 where sub_query_diff_old_optimize_subquery1.k1 = (select sum(sub_query_diff_old_optimize_subquery3.k3) from sub_query_diff_old_optimize_subquery3 where sub_query_diff_old_optimize_subquery3.v2 > sub_query_diff_old_optimize_subquery1.k2) order by k1, k2 """ - exception "java.sql.SQLException: errCode = 2, detailMessage = Unexpected exception: scalar subquery's correlatedPredicates's operator must be EQ" + exception "java.sql.SQLException: errCode = 2, detailMessage = scalar subquery's correlatedPredicates's operator must be EQ" } test { @@ -115,7 +115,7 @@ suite ("sub_query_diff_old_optimize") { where k1 = (select sum(k1) from sub_query_diff_old_optimize_subquery3 where sub_query_diff_old_optimize_subquery1.k1 != sub_query_diff_old_optimize_subquery3.v1 and sub_query_diff_old_optimize_subquery3.v2 = 2) order by k1, k2 """ - exception "java.sql.SQLException: errCode = 2, detailMessage = Unexpected exception: scalar subquery's correlatedPredicates's operator must be EQ" + exception "java.sql.SQLException: errCode = 2, detailMessage = scalar subquery's correlatedPredicates's operator must be EQ" } //----------with subquery alias---------- @@ -159,7 +159,7 @@ suite ("sub_query_diff_old_optimize") { sql """ select * from sub_query_diff_old_optimize_subquery1 where sub_query_diff_old_optimize_subquery1.k1 not in (select sub_query_diff_old_optimize_subquery3.k3 from sub_query_diff_old_optimize_subquery3 where sub_query_diff_old_optimize_subquery3.v2 = sub_query_diff_old_optimize_subquery1.k2 limit 1); """ - exception "java.sql.SQLException: errCode = 2, detailMessage = Unexpected exception: Unsupported correlated subquery with a LIMIT clause LogicalLimit ( limit=1, offset=0, phase=ORIGIN )" + exception "Unsupported correlated subquery with a LIMIT clause LogicalLimit ( limit=1, offset=0, phase=ORIGIN )" } @@ -173,7 +173,7 @@ suite ("sub_query_diff_old_optimize") { sql """ SELECT DISTINCT k1 FROM sub_query_diff_old_optimize_subquery1 i1 WHERE ((SELECT count(*) FROM sub_query_diff_old_optimize_subquery1 WHERE ((k1 = i1.k1) AND (k2 = 2)) or ((k2 = i1.k1) AND (k2 = 1)) ) > 0); """ - exception "java.sql.SQLException: errCode = 2, detailMessage = Unexpected exception: scalar subquery's correlatedPredicates's operator must be EQ" + exception "scalar subquery's correlatedPredicates's operator must be EQ" } } diff --git a/regression-test/suites/nereids_syntax_p0/system_var.groovy b/regression-test/suites/nereids_syntax_p0/system_var.groovy index 3a3714e8c8..a2ab3bfa9e 100644 --- a/regression-test/suites/nereids_syntax_p0/system_var.groovy +++ b/regression-test/suites/nereids_syntax_p0/system_var.groovy @@ -38,7 +38,7 @@ suite("nereids_sys_var") { // set an invalid parameter, and throw an exception test { sql "select /*+SET_VAR(runtime_filter_type=10000)*/ * from supplier limit 10" - exception "Unexpected exception: Can not set session variable" + exception "Can not set session variable" } sql "select @@session.time_zone" diff --git a/regression-test/suites/nereids_syntax_p0/test_timestamp_arithmetic.groovy b/regression-test/suites/nereids_syntax_p0/test_timestamp_arithmetic.groovy index 46bb27fe42..e52ad51727 100644 --- a/regression-test/suites/nereids_syntax_p0/test_timestamp_arithmetic.groovy +++ b/regression-test/suites/nereids_syntax_p0/test_timestamp_arithmetic.groovy @@ -22,12 +22,12 @@ suite("nereids_timestamp_arithmetic") { test { sql = "select bitmap_empty() + interval 1 year;" - exception = "Unexpected exception: Operand 'bitmap_empty()' of timestamp arithmetic expression 'years_add(bitmap_empty(), INTERVAL 1 YEAR)' returns type 'BITMAP'. Expected type 'TIMESTAMP/DATE/DATETIME'" + exception = "timestamp arithmetic could not contains object type" } test { sql = "select date '20200808' + interval array() day;" - exception = "the second argument must be a scalar type. but it is array()" + exception = "timestamp arithmetic could not contains complex type" } sql """ diff --git a/regression-test/suites/point_query_p0/load.groovy b/regression-test/suites/point_query_p0/load.groovy index 6bc9d6c134..ead83cdf57 100644 --- a/regression-test/suites/point_query_p0/load.groovy +++ b/regression-test/suites/point_query_p0/load.groovy @@ -19,6 +19,9 @@ import org.codehaus.groovy.runtime.IOGroovyMethods suite("test_point_query_load", "p0") { + // nereids do not support point query now + sql """set enable_nereids_planner=false""" + def dataFile = """${getS3Url()}/regression/datatypes/test_scalar_types_10w.csv""" // define dup key table1 diff --git a/regression-test/suites/point_query_p0/test_point_query.groovy b/regression-test/suites/point_query_p0/test_point_query.groovy index 48cea40718..b8a463a05c 100644 --- a/regression-test/suites/point_query_p0/test_point_query.groovy +++ b/regression-test/suites/point_query_p0/test_point_query.groovy @@ -18,6 +18,10 @@ import java.math.BigDecimal; suite("test_point_query") { + + // nereids do not support point query now + sql """set enable_nereids_planner=false""" + def user = context.config.jdbcUser def password = context.config.jdbcPassword def realDb = "regression_test_serving_p0" @@ -108,7 +112,7 @@ suite("test_point_query") { } // def url = context.config.jdbcUrl def result1 = connect(user=user, password=password, url=url) { - def stmt = prepareStatement "select * from ${tableName} where k1 = ? and k2 = ? and k3 = ?" + def stmt = prepareStatement "select /*+ SET_VAR(enable_nereids_planner=false) */ * from ${tableName} where k1 = ? and k2 = ? and k3 = ?" assertEquals(stmt.class, com.mysql.cj.jdbc.ServerPreparedStatement); stmt.setInt(1, 1231) stmt.setBigDecimal(2, new BigDecimal("119291.11")) @@ -144,13 +148,13 @@ suite("test_point_query") { qe_point_select stmt stmt.close() - stmt = prepareStatement "select * from ${tableName} where k1 = 1235 and k2 = ? and k3 = ?" + stmt = prepareStatement "select /*+ SET_VAR(enable_nereids_planner=false) */ * from ${tableName} where k1 = 1235 and k2 = ? and k3 = ?" assertEquals(stmt.class, com.mysql.cj.jdbc.ServerPreparedStatement); stmt.setBigDecimal(1, new BigDecimal("991129292901.11138")) stmt.setString(2, "dd") qe_point_select stmt - def stmt_fn = prepareStatement "select hex(k3), hex(k4) from ${tableName} where k1 = ? and k2 =? and k3 = ?" + def stmt_fn = prepareStatement "select /*+ SET_VAR(enable_nereids_planner=false) */ hex(k3), hex(k4) from ${tableName} where k1 = ? and k2 =? and k3 = ?" assertEquals(stmt_fn.class, com.mysql.cj.jdbc.ServerPreparedStatement); stmt_fn.setInt(1, 1231) stmt_fn.setBigDecimal(2, new BigDecimal("119291.11")) @@ -192,9 +196,9 @@ suite("test_point_query") { // disable useServerPrepStmts url = context.config.jdbcUrl def result2 = connect(user=user, password=password, url=url) { - qt_sql """select * from ${tableName} where k1 = 1231 and k2 = 119291.11 and k3 = 'ddd'""" - qt_sql """select * from ${tableName} where k1 = 1237 and k2 = 120939.11130 and k3 = 'a ddd'""" - qt_sql """select hex(k3), hex(k4), k7 + 10.1 from ${tableName} where k1 = 1237 and k2 = 120939.11130 and k3 = 'a ddd'""" + qt_sql """select /*+ SET_VAR(enable_nereids_planner=false) */ * from ${tableName} where k1 = 1231 and k2 = 119291.11 and k3 = 'ddd'""" + qt_sql """select /*+ SET_VAR(enable_nereids_planner=false) */ * from ${tableName} where k1 = 1237 and k2 = 120939.11130 and k3 = 'a ddd'""" + qt_sql """select /*+ SET_VAR(enable_nereids_planner=false) */ hex(k3), hex(k4), k7 + 10.1 from ${tableName} where k1 = 1237 and k2 = 120939.11130 and k3 = 'a ddd'""" // prepared text sql """ prepare stmt1 from select * from ${tableName} where k1 = % and k2 = % and k3 = % """ qt_sql """execute stmt1 using (1231, 119291.11, 'ddd')""" @@ -223,6 +227,6 @@ suite("test_point_query") { "disable_auto_compaction" = "false" );""" sql """insert into ${tableName} values (0, "1", "2", "3")""" - qt_sql "select * from test_query where customer_key = 0" + qt_sql "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test_query where customer_key = 0" } } diff --git a/regression-test/suites/query_p0/join/test_bitmap_filter_nereids.groovy b/regression-test/suites/query_p0/join/test_bitmap_filter_nereids.groovy index aba15f1009..d0cf4b2384 100644 --- a/regression-test/suites/query_p0/join/test_bitmap_filter_nereids.groovy +++ b/regression-test/suites/query_p0/join/test_bitmap_filter_nereids.groovy @@ -78,7 +78,7 @@ suite("test_bitmap_filter_nereids") { test { sql "select k1, count(*) from ${tbl1} b1 group by k1 having k1 in (select k2 from ${tbl2} b2) order by k1;" - exception "errCode = 2, detailMessage = Unexpected exception: Doris hll, bitmap, array, map, struct, jsonb column must use with specific function, and don't support filter" + exception "Doris hll, bitmap, array, map, struct, jsonb column must use with specific function, and don't support filter" } explain{ diff --git a/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.groovy b/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.groovy index ec6c6304e9..aa1500bdcb 100644 --- a/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.groovy +++ b/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_collect.groovy @@ -611,7 +611,7 @@ suite("test_aggregate_collect") { sql "DROP TABLE IF EXISTS ${tableName_12}" sql """ - CREATE TABLE IF NOT EXISTS ${tableName_12} ( + CREATE TABLE IF NOT EXISTS topn_array ( id int, level int, dt datev2, @@ -622,7 +622,7 @@ suite("test_aggregate_collect") { "replication_num" = "1" ) """ - sql "INSERT INTO ${tableName_12} values(1,10,'2022-11-1',6.8754576), (2,8,'2022-11-3',0.576), (2,10,'2022-11-2',1.234) ,(3,10,'2022-11-2',0.576) ,(5,29,'2022-11-2',6.8754576) ,(6,8,'2022-11-1',6.8754576)" + sql "INSERT INTO topn_array values(1,10,'2022-11-1',6.8754576), (2,8,'2022-11-3',0.576), (2,10,'2022-11-2',1.234) ,(3,10,'2022-11-2',0.576) ,(5,29,'2022-11-2',6.8754576) ,(6,8,'2022-11-1',6.8754576)" order_qt_select43 "select topn_array(level,2) from ${tableName_12}" order_qt_select44 "select topn_array(level,2,100) from ${tableName_12}" diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy index d541d24470..4e1adafac4 100644 --- a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy +++ b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy @@ -310,10 +310,11 @@ suite("test_array_functions_by_literal") { qt_sql "select array_concat(array(cast ('2023-03-05 12:23:24.999' as datetimev2(3)),cast ('2023-03-05 15:23:23.997' as datetimev2(3))))" // array_shuffle - qt_select_array_shuffle1 "SELECT array_sum(array_shuffle([1, 2, 3, 3, null, null, 4, 4])), array_shuffle([1, 2, 3, 3, null, null, 4, 4], 0), shuffle([1, 2, 3, 3, null, null, 4, 4], 0)" - qt_select_array_shuffle2 "SELECT array_sum(array_shuffle([1.111, 2.222, 3.333])), array_shuffle([1.111, 2.222, 3.333], 0), shuffle([1.111, 2.222, 3.333], 0)" - qt_select_array_shuffle3 "SELECT array_size(array_shuffle(['aaa', null, 'bbb', 'fff'])), array_shuffle(['aaa', null, 'bbb', 'fff'], 0), shuffle(['aaa', null, 'bbb', 'fff'], 0)" - qt_select_array_shuffle4 """select array_size(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17")), array_shuffle(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17"), 0), shuffle(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17"), 0)""" + // do not check result, since shuffle result is random + sql "SELECT array_sum(array_shuffle([1, 2, 3, 3, null, null, 4, 4])), array_shuffle([1, 2, 3, 3, null, null, 4, 4], 0), shuffle([1, 2, 3, 3, null, null, 4, 4], 0)" + sql "SELECT array_sum(array_shuffle([1.111, 2.222, 3.333])), array_shuffle([1.111, 2.222, 3.333], 0), shuffle([1.111, 2.222, 3.333], 0)" + sql "SELECT array_size(array_shuffle(['aaa', null, 'bbb', 'fff'])), array_shuffle(['aaa', null, 'bbb', 'fff'], 0), shuffle(['aaa', null, 'bbb', 'fff'], 0)" + sql """select array_size(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17")), array_shuffle(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17"), 0), shuffle(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17"), 0)""" // array_zip qt_sql "select array_zip(['a', 'b', 'c'], ['d', 'e', 'f'])"