diff --git a/be/src/vec/functions/array/function_array_range.cpp b/be/src/vec/functions/array/function_array_range.cpp index 2431e76c88..a84b94d8cf 100644 --- a/be/src/vec/functions/array/function_array_range.cpp +++ b/be/src/vec/functions/array/function_array_range.cpp @@ -38,10 +38,13 @@ #include "vec/core/types.h" #include "vec/data_types/data_type.h" #include "vec/data_types/data_type_array.h" +#include "vec/data_types/data_type_date_time.h" #include "vec/data_types/data_type_nullable.h" #include "vec/data_types/data_type_number.h" #include "vec/functions/function.h" +#include "vec/functions/function_date_or_datetime_computation.h" #include "vec/functions/simple_function_factory.h" +#include "vec/runtime/vdatetime_value.h" #include "vec/utils/util.hpp" namespace doris { @@ -53,7 +56,7 @@ namespace doris::vectorized { template class FunctionArrayRange : public IFunction { public: - static constexpr auto name = "array_range"; + static constexpr auto name = Impl::name; static FunctionPtr create() { return std::make_shared(); } @@ -73,7 +76,7 @@ public: } DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { - auto nested_type = make_nullable(std::make_shared()); + auto nested_type = make_nullable(Impl::get_data_type()); auto res = std::make_shared(nested_type); return make_nullable(res); } @@ -84,11 +87,52 @@ public: } }; +template struct RangeImplUtil { + using DataType = std::conditional_t, DataTypeInt32, + DataTypeDateTimeV2>; + + static DataTypePtr get_data_type() { return std::make_shared(); } + + static constexpr const char* get_function_name() { + if constexpr (std::is_same_v && + !std::is_same_v) { + if constexpr (std::is_same_v>) { + return "array_range_year_unit"; + } else if constexpr (std::is_same_v< + TimeUnitOrVoid, + std::integral_constant>) { + return "array_range_month_unit"; + } else if constexpr (std::is_same_v>) { + return "array_range_week_unit"; + } else if constexpr (std::is_same_v>) { + return "array_range_day_unit"; + } else if constexpr (std::is_same_v>) { + return "array_range_hour_unit"; + } else if constexpr (std::is_same_v< + TimeUnitOrVoid, + std::integral_constant>) { + return "array_range_minute_unit"; + } else if constexpr (std::is_same_v< + TimeUnitOrVoid, + std::integral_constant>) { + return "array_range_second_unit"; + } + } else { + return "array_range"; + } + } + + static constexpr auto name = get_function_name(); + static Status range_execute(Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) { DCHECK_EQ(arguments.size(), 3); - auto return_nested_type = make_nullable(std::make_shared()); + auto return_nested_type = make_nullable(std::make_shared()); auto dest_array_column_ptr = ColumnArray::create(return_nested_type->create_column(), ColumnArray::ColumnOffsets::create()); IColumn* dest_nested_column = &dest_array_column_ptr->get_data(); @@ -111,13 +155,15 @@ struct RangeImplUtil { argument_columns[i] = nullable->get_nested_column_ptr(); } } - auto start_column = assert_cast*>(argument_columns[0].get()); - auto end_column = assert_cast*>(argument_columns[1].get()); + auto start_column = + assert_cast*>(argument_columns[0].get()); + auto end_column = + assert_cast*>(argument_columns[1].get()); auto step_column = assert_cast*>(argument_columns[2].get()); DCHECK(dest_nested_column != nullptr); auto& dest_offsets = dest_array_column_ptr->get_offsets(); - auto nested_column = reinterpret_cast*>(dest_nested_column); + auto nested_column = reinterpret_cast*>(dest_nested_column); dest_offsets.reserve(input_rows_count); dest_nested_column->reserve(input_rows_count); dest_nested_null_map.reserve(input_rows_count); @@ -132,49 +178,92 @@ struct RangeImplUtil { } private: - static void vector(const PaddedPODArray& start, const PaddedPODArray& end, - const PaddedPODArray& step, NullMap& args_null_map, - PaddedPODArray& nested_column, + static void vector(const PaddedPODArray& start, + const PaddedPODArray& end, const PaddedPODArray& step, + NullMap& args_null_map, PaddedPODArray& nested_column, PaddedPODArray& dest_nested_null_map, ColumnArray::Offsets64& dest_offsets) { int rows = start.size(); for (auto row = 0; row < rows; ++row) { - if (args_null_map[row] || start[row] < 0 || end[row] < 0 || step[row] < 0) { - nested_column.push_back(0); - dest_offsets.push_back(dest_offsets.back() + 1); - dest_nested_null_map.push_back(1); - args_null_map[row] = 1; - } else { - int offset = dest_offsets.back(); - for (auto idx = start[row]; idx < end[row]; idx = idx + step[row]) { - nested_column.push_back(idx); - dest_nested_null_map.push_back(0); - offset++; + auto idx = start[row]; + auto end_row = end[row]; + auto step_row = step[row]; + auto args_null_map_row = args_null_map[row]; + if constexpr (std::is_same_v) { + if (args_null_map_row || idx < 0 || end_row < 0 || step_row <= 0) { + args_null_map[row] = 1; + dest_offsets.push_back(dest_offsets.back()); + continue; + } else { + int offset = dest_offsets.back(); + while (idx < end[row]) { + nested_column.push_back(idx); + dest_nested_null_map.push_back(0); + offset++; + idx = idx + step_row; + } + dest_offsets.push_back(offset); + } + } else { + const auto& idx_0 = reinterpret_cast&>(idx); + const auto& end_row_cast = + reinterpret_cast&>(end_row); + bool is_null = !idx_0.is_valid_date(); + bool is_end_row_invalid = !end_row_cast.is_valid_date(); + if (args_null_map_row || step_row <= 0 || is_null || is_end_row_invalid) { + args_null_map[row] = 1; + dest_offsets.push_back(dest_offsets.back()); + continue; + } else { + int offset = dest_offsets.back(); + using UNIT = std::conditional_t, + std::integral_constant, + TimeUnitOrVoid>; + while (doris::datetime_diff(idx, end_row) > 0) { + nested_column.push_back(idx); + dest_nested_null_map.push_back(0); + offset++; + idx = doris::vectorized::date_time_add< + UNIT::value, DateV2Value, + DateV2Value, DateTimeV2>(idx, step_row, + is_null); + } + dest_offsets.push_back(offset); } - dest_offsets.push_back(offset); } } } }; -struct RangeOneImpl { - static DataTypes get_variadic_argument_types() { return {std::make_shared()}; } +template +struct RangeOneImpl : public RangeImplUtil { + static DataTypes get_variadic_argument_types() { + return {std::make_shared::DataType>()}; + } static Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) { - auto start_column = ColumnInt32::create(input_rows_count, 0); + using ColumnType = std::conditional_t, ColumnInt32, + ColumnDateTimeV2>; + auto start_column = ColumnType::create(input_rows_count, 0); auto step_column = ColumnInt32::create(input_rows_count, 1); - block.insert({std::move(start_column), std::make_shared(), "start_column"}); + block.insert({std::move(start_column), + std::make_shared::DataType>(), + "start_column"}); block.insert({std::move(step_column), std::make_shared(), "step_column"}); ColumnNumbers temp_arguments = {block.columns() - 2, arguments[0], block.columns() - 1}; - return RangeImplUtil::range_execute(block, temp_arguments, result, input_rows_count); + return (RangeImplUtil::range_execute)( + block, temp_arguments, result, input_rows_count); } }; -struct RangeTwoImpl { +template +struct RangeTwoImpl : public RangeImplUtil { static DataTypes get_variadic_argument_types() { - return {std::make_shared(), std::make_shared()}; + return {std::make_shared::DataType>(), + std::make_shared::DataType>()}; } static Status execute_impl(FunctionContext* context, Block& block, @@ -183,27 +272,54 @@ struct RangeTwoImpl { auto step_column = ColumnInt32::create(input_rows_count, 1); block.insert({std::move(step_column), std::make_shared(), "step_column"}); ColumnNumbers temp_arguments = {arguments[0], arguments[1], block.columns() - 1}; - return RangeImplUtil::range_execute(block, temp_arguments, result, input_rows_count); + return (RangeImplUtil::range_execute)( + block, temp_arguments, result, input_rows_count); } }; -struct RangeThreeImpl { +template +struct RangeThreeImpl : public RangeImplUtil { static DataTypes get_variadic_argument_types() { - return {std::make_shared(), std::make_shared(), + return {std::make_shared::DataType>(), + std::make_shared::DataType>(), std::make_shared()}; } static Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) { - return RangeImplUtil::range_execute(block, arguments, result, input_rows_count); + return (RangeImplUtil::range_execute)( + block, arguments, result, input_rows_count); } }; void register_function_array_range(SimpleFunctionFactory& factory) { - factory.register_function>(); - factory.register_function>(); - factory.register_function>(); + /// One argument, just for Int32 + factory.register_function>>(); + + /// Two arguments, for Int32 and DateTimeV2 without Interval + factory.register_function>>(); + factory.register_function>>(); + + /// Three arguments, for Int32 and DateTimeV2 with YEAR to SECOND Interval + factory.register_function>>(); + factory.register_function>>>(); + factory.register_function>>>(); + factory.register_function>>>(); + factory.register_function>>>(); + factory.register_function>>>(); + factory.register_function>>>(); + factory.register_function>>>(); + + // alias + factory.register_alias("array_range", "sequence"); } } // namespace doris::vectorized diff --git a/docs/en/docs/sql-manual/sql-functions/array-functions/array-range.md b/docs/en/docs/sql-manual/sql-functions/array-functions/array-range.md index 0ccbc63729..c8119a9def 100644 --- a/docs/en/docs/sql-manual/sql-functions/array-functions/array-range.md +++ b/docs/en/docs/sql-manual/sql-functions/array-functions/array-range.md @@ -40,21 +40,28 @@ array_range ARRAY array_range(Int end) ARRAY array_range(Int start, Int end) ARRAY array_range(Int start, Int end, Int step) +ARRAY array_range(Datetime start_datetime, Datetime end_datetime) +ARRAY array_range(Datetime start_datetime, Datetime end_datetime, INTERVAL Int interval_step UNIT) ``` +1. To generate array of int: The parameters are all positive integers. start default value is 0, and step default value is 1. Return the array which numbers from start to end - 1 by step. +2. To generate array of datetime: +At least taking two parameters. +The first two parameters are all datetimev2, the third is positive integer. +If the third part is missing, `INTERVAL 1 DAY` will be default value. +UNIT supports YEAR/MONTH/WEEK/DAY/HOUR/MINUTE/SECOND. +Return the array of datetimev2 between start_datetime and closest to end_datetime by interval_step UNIT. ### notice -`Only supported in vectorized engine` +`if the 3rd parameter step/interval_step is negative or zero, the function will return NULL` ### example ``` -mysql> set enable_vectorized_engine=true; - mysql> select array_range(10); +--------------------------------+ | array_range(10) | @@ -75,6 +82,20 @@ mysql> select array_range(0,20,2); +-------------------------------------+ | [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] | +-------------------------------------+ + +mysql> select array_range(cast('2022-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0))) AS array_range_default; ++------------------------------------------------+ +| array_range_default | ++------------------------------------------------+ +| ["2022-05-15 12:00:00", "2022-05-16 12:00:00"] | ++------------------------------------------------+ + +mysql> select array_range(cast('2019-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0)), interval 2 year) as array_range_2_year; ++------------------------------------------------+ +| array_range_2_year | ++------------------------------------------------+ +| ["2019-05-15 12:00:00", "2021-05-15 12:00:00"] | ++------------------------------------------------+ ``` ### keywords diff --git a/docs/en/docs/sql-manual/sql-functions/array-functions/sequence.md b/docs/en/docs/sql-manual/sql-functions/array-functions/sequence.md new file mode 100644 index 0000000000..b5e45413fa --- /dev/null +++ b/docs/en/docs/sql-manual/sql-functions/array-functions/sequence.md @@ -0,0 +1,104 @@ +--- +{ + "title": "SEQUENCE", + "language": "en" +} +--- + + + +## sequence + + + +sequence + + + +### description +alias of array_range function + +#### Syntax + +```sql +ARRAY sequence(Int end) +ARRAY sequence(Int start, Int end) +ARRAY sequence(Int start, Int end, Int step) +ARRAY sequence(Datetime start_datetime, Datetime end_datetime) +ARRAY sequence(Datetime start_datetime, Datetime end_datetime, INTERVAL Int interval_step UNIT) +``` +1. To generate array of int: +The parameters are all positive integers. +start default value is 0, and step default value is 1. +Return the array which numbers from start to end - 1 by step. + +2. To generate array of datetime: +At least taking two parameters. +The first two parameters are all datetimev2, the third is positive integer. +If the third part is missing, `INTERVAL 1 DAY` will be default value. +UNIT supports YEAR/MONTH/WEEK/DAY/HOUR/MINUTE/SECOND. +Return the array of datetimev2 between start_datetime and closest to end_datetime by interval_step UNIT. + +### notice + +`if the 3rd parameter step/interval_step is negative or zero, the function will return NULL` + +### example + +``` +mysql> select sequence(10); ++--------------------------------+ +| sequence(10) | ++--------------------------------+ +| [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | ++--------------------------------+ + +mysql> select sequence(10,20); ++------------------------------------------+ +| sequence(10, 20) | ++------------------------------------------+ +| [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] | ++------------------------------------------+ + +mysql> select sequence(0,20,2); ++-------------------------------------+ +| sequence(0, 20, 2) | ++-------------------------------------+ +| [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] | ++-------------------------------------+ + +mysql> select sequence(cast('2022-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0))) AS sequence_default; ++------------------------------------------------+ +| sequence_default | ++------------------------------------------------+ +| ["2022-05-15 12:00:00", "2022-05-16 12:00:00"] | ++------------------------------------------------+ + +mysql> select sequence(cast('2019-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0)), interval 2 year) as sequence_2_year; ++------------------------------------------------+ +| sequence_2_year | ++------------------------------------------------+ +| ["2019-05-15 12:00:00", "2021-05-15 12:00:00"] | ++------------------------------------------------+ +``` + +### keywords + +ARRAY, RANGE, SEQUENCE diff --git a/docs/sidebars.json b/docs/sidebars.json index a01cb7e40d..e21344bca3 100644 --- a/docs/sidebars.json +++ b/docs/sidebars.json @@ -354,7 +354,8 @@ "sql-manual/sql-functions/array-functions/arrays-overlap", "sql-manual/sql-functions/array-functions/array-count", "sql-manual/sql-functions/array-functions/countequal", - "sql-manual/sql-functions/array-functions/element-at" + "sql-manual/sql-functions/array-functions/element-at", + "sql-manual/sql-functions/array-functions/sequence" ] }, { diff --git a/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array-range.md b/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array-range.md index cc68bf093d..8e4b914875 100644 --- a/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array-range.md +++ b/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array-range.md @@ -40,19 +40,26 @@ array_range ARRAY array_range(Int end) ARRAY array_range(Int start, Int end) ARRAY array_range(Int start, Int end, Int step) +ARRAY array_range(Datetime start_datetime, Datetime end_datetime) +ARRAY array_range(Datetime start_datetime, Datetime end_datetime, INTERVAL Int interval_step UNIT) ``` +1. 生成int数组: 参数均为正整数 start 默认为 0, step 默认为 1。 最终返回一个数组,从start 到 end - 1, 步长为 step。 +2. 生成日期时间数组: +至少取两个参数。 +前两个参数都是datetimev2,第三个是正整数。 +如果缺少第三部分,则`INTERVAL 1 DAY`将为默认值。 +UNIT 支持年/月/周/日/小时/分钟/秒。 +返回 start_datetime 和最接近 end_datetime 之间的 datetimev2 数组(按 Interval_step UNIT 计算)。 ### notice -`仅支持向量化引擎中使用` +`如果第三个参数 step/interval_step 为负数或者零, 函数结果将为NULL` ### example ``` -mysql> set enable_vectorized_engine=true; - mysql> select array_range(10); +--------------------------------+ | array_range(10) | @@ -73,6 +80,20 @@ mysql> select array_range(0,20,2); +-------------------------------------+ | [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] | +-------------------------------------+ + +mysql> select array_range(cast('2022-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0))) AS array_range_default; ++------------------------------------------------+ +| array_range_default | ++------------------------------------------------+ +| ["2022-05-15 12:00:00", "2022-05-16 12:00:00"] | ++------------------------------------------------+ + +mysql> select array_range(cast('2019-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0)), interval 2 year) as array_range_2_year; ++------------------------------------------------+ +| array_range_2_year | ++------------------------------------------------+ +| ["2019-05-15 12:00:00", "2021-05-15 12:00:00"] | ++------------------------------------------------+ ``` ### keywords diff --git a/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/sequence.md b/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/sequence.md new file mode 100644 index 0000000000..69a5744b75 --- /dev/null +++ b/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/sequence.md @@ -0,0 +1,102 @@ +--- +{ + "title": "SEQUENCE", + "language": "zh-CN" +} +--- + + + +## sequence + + + +sequence + + + +### description +函数array_range的别称 + +#### Syntax + +```sql +ARRAY sequence(Int end) +ARRAY sequence(Int start, Int end) +ARRAY sequence(Int start, Int end, Int step) +ARRAY sequence(Datetime start_datetime, Datetime end_datetime) +ARRAY sequence(Datetime start_datetime, Datetime end_datetime, INTERVAL Int interval_step UNIT) +``` +1. 生成int数组: +参数均为正整数 start 默认为 0, step 默认为 1。 +最终返回一个数组,从start 到 end - 1, 步长为 step。 +2. 生成日期时间数组: +至少取两个参数。 +前两个参数都是datetimev2,第三个是正整数。 +如果缺少第三部分,则`INTERVAL 1 DAY`将为默认值。 +UNIT 支持年/月/周/日/小时/分钟/秒。 +返回 start_datetime 和最接近 end_datetime 之间的 datetimev2 数组(按 Interval_step UNIT 计算)。 + +### notice + +`如果第三个参数 step/interval_step 为负数或者零, 函数结果将为NULL` + +### example + +``` +mysql> select sequence(10); ++--------------------------------+ +| sequence(10) | ++--------------------------------+ +| [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | ++--------------------------------+ + +mysql> select sequence(10,20); ++------------------------------------------+ +| sequence(10, 20) | ++------------------------------------------+ +| [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] | ++------------------------------------------+ + +mysql> select sequence(0,20,2); ++-------------------------------------+ +| sequence(0, 20, 2) | ++-------------------------------------+ +| [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] | ++-------------------------------------+ + +mysql> select sequence(cast('2022-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0))) AS sequence_default; ++------------------------------------------------+ +| sequence_default | ++------------------------------------------------+ +| ["2022-05-15 12:00:00", "2022-05-16 12:00:00"] | ++------------------------------------------------+ + +mysql> select sequence(cast('2019-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0)), interval 2 year) as sequence_2_year; ++------------------------------------------------+ +| sequence_2_year | ++------------------------------------------------+ +| ["2019-05-15 12:00:00", "2021-05-15 12:00:00"] | ++------------------------------------------------+ +``` + +### keywords + +ARRAY, RANGE, SEQUENCE 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 7897232a95..2485f11eab 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 @@ -108,6 +108,7 @@ AND: 'AND'; ANTI: 'ANTI'; APPEND: 'APPEND'; ARRAY: 'ARRAY'; +ARRAY_RANGE: 'ARRAY_RANGE'; AS: 'AS'; ASC: 'ASC'; AT: 'AT'; @@ -469,6 +470,7 @@ SCHEMAS: 'SCHEMAS'; SECOND: 'SECOND'; SELECT: 'SELECT'; SEMI: 'SEMI'; +SEQUENCE: 'SEQUENCE'; SERIALIZABLE: 'SERIALIZABLE'; SESSION: 'SESSION'; SET: 'SET'; 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 cb34af20e6..dd63849372 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 @@ -674,6 +674,13 @@ primaryExpression (INTERVAL unitsAmount=valueExpression unit=datetimeUnit | unitsAmount=valueExpression) RIGHT_PAREN #dateCeil + | name =(ARRAY_RANGE | SEQUENCE) + LEFT_PAREN + start=valueExpression COMMA + end=valueExpression COMMA + (INTERVAL unitsAmount=valueExpression unit=datetimeUnit + | unitsAmount=valueExpression) + RIGHT_PAREN #arrayRange | name=CURRENT_DATE #currentDate | name=CURRENT_TIME #currentTime | name=CURRENT_TIMESTAMP #currentTimestamp @@ -918,6 +925,7 @@ nonReserved | ALIAS | ANALYZED | ARRAY + | ARRAY_RANGE | AT | AUTHORS | AUTO_INCREMENT @@ -1144,6 +1152,7 @@ nonReserved | SCHEMA | SECOND | SERIALIZABLE + | SEQUENCE | SESSION | SHAPE | SKEW diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index 1460adaf04..8d27ea06ea 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -1776,6 +1776,13 @@ public class FunctionCallExpr extends Expr { + "year|quarter|month|week|day|hour|minute|second"); } } + if (fnName.getFunction().equalsIgnoreCase("array_range") + || fnName.getFunction().equalsIgnoreCase("sequence")) { + if (getChild(0) instanceof DateLiteral && !(getChild(2) instanceof StringLiteral)) { + throw new AnalysisException("To generate datetime array, please use interval literal like: " + + "interval 1 day."); + } + } if (fnName.getFunction().equalsIgnoreCase("char")) { if (!getChild(0).isConstant()) { throw new AnalysisException( 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 f5928650ef..33f353503a 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 @@ -485,7 +485,7 @@ public class BuiltinScalarFunctions implements FunctionHelper { scalar(ArrayProduct.class, "array_product"), scalar(ArrayPushBack.class, "Array_pushback"), scalar(ArrayPushFront.class, "Array_pushfront"), - scalar(ArrayRange.class, "array_range"), + scalar(ArrayRange.class, "array_range", "sequence"), scalar(ArrayRemove.class, "array_remove"), scalar(ArrayRepeat.class, "array_repeat"), scalar(ArrayReverseSort.class, "array_reverse_sort"), 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 9fd280c7f6..bbec47aaee 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 @@ -48,6 +48,7 @@ import org.apache.doris.nereids.DorisParser.AlterMTMVContext; import org.apache.doris.nereids.DorisParser.ArithmeticBinaryContext; import org.apache.doris.nereids.DorisParser.ArithmeticUnaryContext; import org.apache.doris.nereids.DorisParser.ArrayLiteralContext; +import org.apache.doris.nereids.DorisParser.ArrayRangeContext; import org.apache.doris.nereids.DorisParser.ArraySliceContext; import org.apache.doris.nereids.DorisParser.BitOperationContext; import org.apache.doris.nereids.DorisParser.BooleanExpressionContext; @@ -261,6 +262,14 @@ 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.Array; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRange; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeDayUnit; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeHourUnit; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeMinuteUnit; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeMonthUnit; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeSecondUnit; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeWeekUnit; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeYearUnit; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArraySlice; import org.apache.doris.nereids.trees.expressions.functions.scalar.Char; import org.apache.doris.nereids.trees.expressions.functions.scalar.ConvertTo; @@ -1682,6 +1691,40 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor { + ", supported time unit: YEAR/MONTH/DAY/HOUR/MINUTE/SECOND", ctx); } + @Override + public Expression visitArrayRange(ArrayRangeContext ctx) { + Expression start = (Expression) visit(ctx.start); + Expression end = (Expression) visit(ctx.end); + Expression step = (Expression) visit(ctx.unitsAmount); + + String unit = ctx.unit.getText(); + if (unit != null && !unit.isEmpty()) { + if ("Year".equalsIgnoreCase(unit)) { + return new ArrayRangeYearUnit(start, end, step); + } else if ("Month".equalsIgnoreCase(unit)) { + return new ArrayRangeMonthUnit(start, end, step); + } else if ("Week".equalsIgnoreCase(unit)) { + return new ArrayRangeWeekUnit(start, end, step); + } else if ("Day".equalsIgnoreCase(unit)) { + return new ArrayRangeDayUnit(start, end, step); + } else if ("Hour".equalsIgnoreCase(unit)) { + return new ArrayRangeHourUnit(start, end, step); + } else if ("Minute".equalsIgnoreCase(unit)) { + return new ArrayRangeMinuteUnit(start, end, step); + } else if ("Second".equalsIgnoreCase(unit)) { + return new ArrayRangeSecondUnit(start, end, step); + } + throw new ParseException("Unsupported time unit: " + ctx.unit + + ", supported time unit: YEAR/MONTH/DAY/HOUR/MINUTE/SECOND", ctx); + } else if (ctx.unitsAmount != null) { + return new ArrayRange(start, end, step); + } else if (ctx.end != null) { + return new ArrayRange(start, end); + } else { + return new ArrayRange(start); + } + } + @Override public Expression visitDate_sub(Date_subContext ctx) { Expression timeStamp = (Expression) visit(ctx.timestamp); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRange.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRange.java index 70d0d4a0ef..44da3b09b8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRange.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRange.java @@ -23,6 +23,7 @@ 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.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; +import org.apache.doris.nereids.types.DateTimeV2Type; import org.apache.doris.nereids.types.IntegerType; import com.google.common.base.Preconditions; @@ -40,7 +41,11 @@ public class ArrayRange extends ScalarFunction FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)).args(IntegerType.INSTANCE), FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)).args(IntegerType.INSTANCE, IntegerType.INSTANCE), FunctionSignature.ret(ArrayType.of(IntegerType.INSTANCE)) - .args(IntegerType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE) + .args(IntegerType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE), + FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) + .args(DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT), + FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) + .args(DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE) ); /** diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeDayUnit.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeDayUnit.java new file mode 100644 index 0000000000..c353ed06c8 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeDayUnit.java @@ -0,0 +1,70 @@ +// 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.DateTimeV2Type; +import org.apache.doris.nereids.types.IntegerType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'array_range_day_unit'. + */ +public class ArrayRangeDayUnit extends ScalarFunction + implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { + private static final List SIGNATURES = ImmutableList.of( + FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) + .args(DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE) + ); + + /** + * constructor with 3 arguments. + */ + public ArrayRangeDayUnit(Expression arg0, Expression arg1, Expression arg2) { + super("array_range_day_unit", arg0, arg1, arg2); + } + + /** + * withChildren. + */ + @Override + public ArrayRangeDayUnit withChildren(List children) { + Preconditions.checkArgument(children.size() == 3); + return new ArrayRangeDayUnit(children.get(0), children.get(1), children.get(2)); + } + + @Override + public List getSignatures() { + return SIGNATURES; + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitArrayRangeDayUnit(this, context); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeHourUnit.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeHourUnit.java new file mode 100644 index 0000000000..320f7d76be --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeHourUnit.java @@ -0,0 +1,70 @@ +// 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.DateTimeV2Type; +import org.apache.doris.nereids.types.IntegerType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'array_range_hour_unit'. + */ +public class ArrayRangeHourUnit extends ScalarFunction + implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { + private static final List SIGNATURES = ImmutableList.of( + FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) + .args(DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE) + ); + + /** + * constructor with 3 arguments. + */ + public ArrayRangeHourUnit(Expression arg0, Expression arg1, Expression arg2) { + super("array_range_hour_unit", arg0, arg1, arg2); + } + + /** + * withChildren. + */ + @Override + public ArrayRangeHourUnit withChildren(List children) { + Preconditions.checkArgument(children.size() == 3); + return new ArrayRangeHourUnit(children.get(0), children.get(1), children.get(2)); + } + + @Override + public List getSignatures() { + return SIGNATURES; + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitArrayRangeHourUnit(this, context); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeMinuteUnit.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeMinuteUnit.java new file mode 100644 index 0000000000..0a8f946f28 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeMinuteUnit.java @@ -0,0 +1,70 @@ +// 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.DateTimeV2Type; +import org.apache.doris.nereids.types.IntegerType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'array_range_minute_unit'. + */ +public class ArrayRangeMinuteUnit extends ScalarFunction + implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { + private static final List SIGNATURES = ImmutableList.of( + FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) + .args(DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE) + ); + + /** + * constructor with 3 arguments. + */ + public ArrayRangeMinuteUnit(Expression arg0, Expression arg1, Expression arg2) { + super("array_range_minute_unit", arg0, arg1, arg2); + } + + /** + * withChildren. + */ + @Override + public ArrayRangeMinuteUnit withChildren(List children) { + Preconditions.checkArgument(children.size() == 3); + return new ArrayRangeMinuteUnit(children.get(0), children.get(1), children.get(2)); + } + + @Override + public List getSignatures() { + return SIGNATURES; + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitArrayRangeMinuteUnit(this, context); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeMonthUnit.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeMonthUnit.java new file mode 100644 index 0000000000..b3f4da2da8 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeMonthUnit.java @@ -0,0 +1,70 @@ +// 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.DateTimeV2Type; +import org.apache.doris.nereids.types.IntegerType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'array_range_month_unit'. + */ +public class ArrayRangeMonthUnit extends ScalarFunction + implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { + private static final List SIGNATURES = ImmutableList.of( + FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) + .args(DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE) + ); + + /** + * constructor with 3 arguments. + */ + public ArrayRangeMonthUnit(Expression arg0, Expression arg1, Expression arg2) { + super("array_range_month_unit", arg0, arg1, arg2); + } + + /** + * withChildren. + */ + @Override + public ArrayRangeMonthUnit withChildren(List children) { + Preconditions.checkArgument(children.size() == 3); + return new ArrayRangeMonthUnit(children.get(0), children.get(1), children.get(2)); + } + + @Override + public List getSignatures() { + return SIGNATURES; + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitArrayRangeMonthUnit(this, context); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeSecondUnit.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeSecondUnit.java new file mode 100644 index 0000000000..7543be64df --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeSecondUnit.java @@ -0,0 +1,70 @@ +// 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.DateTimeV2Type; +import org.apache.doris.nereids.types.IntegerType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'array_range_second_unit'. + */ +public class ArrayRangeSecondUnit extends ScalarFunction + implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { + private static final List SIGNATURES = ImmutableList.of( + FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) + .args(DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE) + ); + + /** + * constructor with 3 arguments. + */ + public ArrayRangeSecondUnit(Expression arg0, Expression arg1, Expression arg2) { + super("array_range_second_unit", arg0, arg1, arg2); + } + + /** + * withChildren. + */ + @Override + public ArrayRangeSecondUnit withChildren(List children) { + Preconditions.checkArgument(children.size() == 3); + return new ArrayRangeSecondUnit(children.get(0), children.get(1), children.get(2)); + } + + @Override + public List getSignatures() { + return SIGNATURES; + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitArrayRangeSecondUnit(this, context); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeWeekUnit.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeWeekUnit.java new file mode 100644 index 0000000000..de7c27bf72 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeWeekUnit.java @@ -0,0 +1,70 @@ +// 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.DateTimeV2Type; +import org.apache.doris.nereids.types.IntegerType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'array_range_week_unit'. + */ +public class ArrayRangeWeekUnit extends ScalarFunction + implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { + private static final List SIGNATURES = ImmutableList.of( + FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) + .args(DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE) + ); + + /** + * constructor with 3 arguments. + */ + public ArrayRangeWeekUnit(Expression arg0, Expression arg1, Expression arg2) { + super("array_range_week_unit", arg0, arg1, arg2); + } + + /** + * withChildren. + */ + @Override + public ArrayRangeWeekUnit withChildren(List children) { + Preconditions.checkArgument(children.size() == 3); + return new ArrayRangeWeekUnit(children.get(0), children.get(1), children.get(2)); + } + + @Override + public List getSignatures() { + return SIGNATURES; + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitArrayRangeWeekUnit(this, context); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeYearUnit.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeYearUnit.java new file mode 100644 index 0000000000..9cda8585b0 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRangeYearUnit.java @@ -0,0 +1,70 @@ +// 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.DateTimeV2Type; +import org.apache.doris.nereids.types.IntegerType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'array_range_year_unit'. + */ +public class ArrayRangeYearUnit extends ScalarFunction + implements BinaryExpression, ExplicitlyCastableSignature, AlwaysNullable { + private static final List SIGNATURES = ImmutableList.of( + FunctionSignature.ret(ArrayType.of(DateTimeV2Type.SYSTEM_DEFAULT)) + .args(DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT, IntegerType.INSTANCE) + ); + + /** + * constructor with 3 arguments. + */ + public ArrayRangeYearUnit(Expression arg0, Expression arg1, Expression arg2) { + super("array_range_year_unit", arg0, arg1, arg2); + } + + /** + * withChildren. + */ + @Override + public ArrayRangeYearUnit withChildren(List children) { + Preconditions.checkArgument(children.size() == 3); + return new ArrayRangeYearUnit(children.get(0), children.get(1), children.get(2)); + } + + @Override + public List getSignatures() { + return SIGNATURES; + } + + @Override + public R accept(ExpressionVisitor visitor, C context) { + return visitor.visitArrayRangeYearUnit(this, context); + } +} 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 183b4a73da..7bf020ad84 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 @@ -57,6 +57,13 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayProduct; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayPushBack; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayPushFront; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRange; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeDayUnit; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeHourUnit; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeMinuteUnit; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeMonthUnit; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeSecondUnit; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeWeekUnit; +import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRangeYearUnit; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRemove; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayRepeat; import org.apache.doris.nereids.trees.expressions.functions.scalar.ArrayReverseSort; @@ -573,6 +580,34 @@ public interface ScalarFunctionVisitor { return visitScalarFunction(arrayRange, context); } + default R visitArrayRangeDayUnit(ArrayRangeDayUnit arrayRangeDayUnit, C context) { + return visitScalarFunction(arrayRangeDayUnit, context); + } + + default R visitArrayRangeHourUnit(ArrayRangeHourUnit arrayRangeHourUnit, C context) { + return visitScalarFunction(arrayRangeHourUnit, context); + } + + default R visitArrayRangeMinuteUnit(ArrayRangeMinuteUnit arrayRangeMinuteUnit, C context) { + return visitScalarFunction(arrayRangeMinuteUnit, context); + } + + default R visitArrayRangeMonthUnit(ArrayRangeMonthUnit arrayRangeMonthUnit, C context) { + return visitScalarFunction(arrayRangeMonthUnit, context); + } + + default R visitArrayRangeSecondUnit(ArrayRangeSecondUnit arrayRangeSecondUnit, C context) { + return visitScalarFunction(arrayRangeSecondUnit, context); + } + + default R visitArrayRangeWeekUnit(ArrayRangeWeekUnit arrayRangeWeekUnit, C context) { + return visitScalarFunction(arrayRangeWeekUnit, context); + } + + default R visitArrayRangeYearUnit(ArrayRangeYearUnit arrayRangeYearUnit, C context) { + return visitScalarFunction(arrayRangeYearUnit, context); + } + default R visitArrayRemove(ArrayRemove arrayRemove, C context) { return visitScalarFunction(arrayRemove, context); } diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py index 0ecb05612a..0e96d3fa75 100644 --- a/gensrc/script/doris_builtins_functions.py +++ b/gensrc/script/doris_builtins_functions.py @@ -827,9 +827,11 @@ visible_functions = { [['array_repeat'], 'ARRAY_VARCHAR', ['VARCHAR', 'BIGINT'], 'ALWAYS_NOT_NULLABLE'], [['array_repeat'], 'ARRAY_STRING', ['STRING', 'BIGINT'], 'ALWAYS_NOT_NULLABLE'], - [['array_range'], 'ARRAY_INT', ['INT'], 'ALWAYS_NULLABLE'], - [['array_range'], 'ARRAY_INT', ['INT', 'INT'], 'ALWAYS_NULLABLE'], - [['array_range'], 'ARRAY_INT', ['INT', 'INT', 'INT'], 'ALWAYS_NULLABLE'], + [['array_range', 'sequence'], 'ARRAY_INT', ['INT'], 'ALWAYS_NULLABLE'], + [['array_range', 'sequence'], 'ARRAY_INT', ['INT', 'INT'], 'ALWAYS_NULLABLE'], + [['array_range', 'sequence'], 'ARRAY_INT', ['INT', 'INT', 'INT'], 'ALWAYS_NULLABLE'], + [['array_range', 'sequence'], 'ARRAY_DATETIMEV2', ['DATETIMEV2', 'DATETIMEV2'], 'ALWAYS_NULLABLE'], + [['array_range', 'sequence'], 'ARRAY_DATETIMEV2', ['DATETIMEV2', 'DATETIMEV2', 'INT'], 'ALWAYS_NULLABLE'], [['array_zip'], 'ARRAY', ['ARRAY', '...'], '', ['T']], diff --git a/regression-test/data/nereids_function_p0/scalar_function/Array.out b/regression-test/data/nereids_function_p0/scalar_function/Array.out index 92cb7a24e6..0ac1f22144 100644 --- a/regression-test/data/nereids_function_p0/scalar_function/Array.out +++ b/regression-test/data/nereids_function_p0/scalar_function/Array.out @@ -14235,3 +14235,197 @@ true -- !array_repeat4 -- [] +-- !array_range_datetime1 -- +\N +["2012-03-01 01:00:01", "2012-03-02 01:00:01"] +["2012-03-02 02:01:02", "2012-03-04 02:01:02"] +["2012-03-03 03:02:03", "2012-03-06 03:02:03"] +["2012-03-04 04:03:04", "2012-03-08 04:03:04"] +["2012-03-05 05:04:05", "2012-03-10 05:04:05"] +["2012-03-06 06:05:06", "2012-03-12 06:05:06"] +["2012-03-07 07:06:07", "2012-03-14 07:06:07"] +["2012-03-08 08:07:08", "2012-03-16 08:07:08"] +["2012-03-09 09:08:09", "2012-03-18 09:08:09"] +["2012-03-10 10:09:10", "2012-03-20 10:09:10"] +["2012-03-11 11:10:11", "2012-03-22 11:10:11"] +["2012-03-12 12:11:12", "2012-03-24 12:11:12"] + +-- !array_range_datetime2 -- +\N +["2012-03-01 01:00:01", "2012-03-08 01:00:01", "2012-03-15 01:00:01"] +["2012-03-02 02:01:02", "2012-03-16 02:01:02"] +["2012-03-03 03:02:03", "2012-03-24 03:02:03"] +["2012-03-04 04:03:04", "2012-04-01 04:03:04"] +["2012-03-05 05:04:05", "2012-04-09 05:04:05"] +["2012-03-06 06:05:06", "2012-04-17 06:05:06"] +["2012-03-07 07:06:07", "2012-04-25 07:06:07"] +["2012-03-08 08:07:08", "2012-05-03 08:07:08"] +["2012-03-09 09:08:09", "2012-05-11 09:08:09"] +["2012-03-10 10:09:10", "2012-05-19 10:09:10"] +["2012-03-11 11:10:11", "2012-05-27 11:10:11"] +["2012-03-12 12:11:12", "2012-06-04 12:11:12"] + +-- !sequence_int_one_para -- +\N +[0] +[0, 1] +[0, 1, 2] +[0, 1, 2, 3] +[0, 1, 2, 3, 4] +[0, 1, 2, 3, 4, 5] +[0, 1, 2, 3, 4, 5, 6] +[0, 1, 2, 3, 4, 5, 6, 7] +[0, 1, 2, 3, 4, 5, 6, 7, 8] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] + +-- !sequence_int_two_para -- +\N +[1, 2] +[2, 3] +[3, 4] +[4, 5] +[5, 6] +[6, 7] +[7, 8] +[8, 9] +[9, 10] +[10, 11] +[11, 12] +[12, 13] + +-- !sequence_int_three_para -- +\N +[0, 1, 2] +[1, 2, 3] +[2, 3, 4] +[3, 4, 5] +[4, 5, 6] +[5, 6, 7] +[6, 7, 8] +[7, 8, 9] +[8, 9, 10] +[9, 10, 11] +[10, 11, 12] +[11, 12, 13] + +-- !sequence_datetime_default -- +\N +[] +[] +[] +["2012-03-04 04:03:04"] +["2012-03-05 05:04:05", "2012-03-06 05:04:05"] +["2012-03-06 06:05:06", "2012-03-07 06:05:06", "2012-03-08 06:05:06"] +["2012-03-07 07:06:07", "2012-03-08 07:06:07", "2012-03-09 07:06:07", "2012-03-10 07:06:07"] +["2012-03-08 08:07:08", "2012-03-09 08:07:08", "2012-03-10 08:07:08", "2012-03-11 08:07:08", "2012-03-12 08:07:08"] +["2012-03-09 09:08:09", "2012-03-10 09:08:09", "2012-03-11 09:08:09", "2012-03-12 09:08:09", "2012-03-13 09:08:09", "2012-03-14 09:08:09"] +["2012-03-10 10:09:10", "2012-03-11 10:09:10", "2012-03-12 10:09:10", "2012-03-13 10:09:10", "2012-03-14 10:09:10", "2012-03-15 10:09:10", "2012-03-16 10:09:10"] +["2012-03-11 11:10:11", "2012-03-12 11:10:11", "2012-03-13 11:10:11", "2012-03-14 11:10:11", "2012-03-15 11:10:11", "2012-03-16 11:10:11", "2012-03-17 11:10:11", "2012-03-18 11:10:11"] +["2012-03-12 12:11:12", "2012-03-13 12:11:12", "2012-03-14 12:11:12", "2012-03-15 12:11:12", "2012-03-16 12:11:12", "2012-03-17 12:11:12", "2012-03-18 12:11:12", "2012-03-19 12:11:12", "2012-03-20 12:11:12"] + +-- !sequence_datetime_day -- +\N +["2012-03-01 01:00:01", "2012-03-02 01:00:01"] +["2012-03-02 02:01:02", "2012-03-04 02:01:02"] +["2012-03-03 03:02:03", "2012-03-06 03:02:03"] +["2012-03-04 04:03:04", "2012-03-08 04:03:04"] +["2012-03-05 05:04:05", "2012-03-10 05:04:05"] +["2012-03-06 06:05:06", "2012-03-12 06:05:06"] +["2012-03-07 07:06:07", "2012-03-14 07:06:07"] +["2012-03-08 08:07:08", "2012-03-16 08:07:08"] +["2012-03-09 09:08:09", "2012-03-18 09:08:09"] +["2012-03-10 10:09:10", "2012-03-20 10:09:10"] +["2012-03-11 11:10:11", "2012-03-22 11:10:11"] +["2012-03-12 12:11:12", "2012-03-24 12:11:12"] + +-- !sequence_datetime_week -- +\N +["2012-03-01 01:00:01", "2012-03-08 01:00:01", "2012-03-15 01:00:01"] +["2012-03-02 02:01:02", "2012-03-16 02:01:02"] +["2012-03-03 03:02:03", "2012-03-24 03:02:03"] +["2012-03-04 04:03:04", "2012-04-01 04:03:04"] +["2012-03-05 05:04:05", "2012-04-09 05:04:05"] +["2012-03-06 06:05:06", "2012-04-17 06:05:06"] +["2012-03-07 07:06:07", "2012-04-25 07:06:07"] +["2012-03-08 08:07:08", "2012-05-03 08:07:08"] +["2012-03-09 09:08:09", "2012-05-11 09:08:09"] +["2012-03-10 10:09:10", "2012-05-19 10:09:10"] +["2012-03-11 11:10:11", "2012-05-27 11:10:11"] +["2012-03-12 12:11:12", "2012-06-04 12:11:12"] + +-- !sequence_datetime_month -- +\N +["2012-03-01 01:00:01", "2012-04-01 01:00:01", "2012-05-01 01:00:01", "2012-06-01 01:00:01"] +["2012-03-02 02:01:02", "2012-05-02 02:01:02", "2012-07-02 02:01:02"] +["2012-03-03 03:02:03", "2012-06-03 03:02:03"] +["2012-03-04 04:03:04", "2012-07-04 04:03:04"] +["2012-03-05 05:04:05", "2012-08-05 05:04:05"] +["2012-03-06 06:05:06", "2012-09-06 06:05:06"] +["2012-03-07 07:06:07", "2012-10-07 07:06:07"] +["2012-03-08 08:07:08", "2012-11-08 08:07:08"] +["2012-03-09 09:08:09", "2012-12-09 09:08:09"] +["2012-03-10 10:09:10", "2013-01-10 10:09:10"] +["2012-03-11 11:10:11", "2013-02-11 11:10:11"] +["2012-03-12 12:11:12", "2013-03-12 12:11:12"] + +-- !sequence_datetime_year -- +\N +["2012-03-01 01:00:01", "2013-03-01 01:00:01", "2014-03-01 01:00:01", "2015-03-01 01:00:01"] +["2012-03-02 02:01:02", "2014-03-02 02:01:02", "2016-03-02 02:01:02"] +["2012-03-03 03:02:03", "2015-03-03 03:02:03"] +["2012-03-04 04:03:04", "2016-03-04 04:03:04"] +["2012-03-05 05:04:05", "2017-03-05 05:04:05"] +["2012-03-06 06:05:06", "2018-03-06 06:05:06"] +["2012-03-07 07:06:07", "2019-03-07 07:06:07"] +["2012-03-08 08:07:08", "2020-03-08 08:07:08"] +["2012-03-09 09:08:09", "2021-03-09 09:08:09"] +["2012-03-10 10:09:10", "2022-03-10 10:09:10"] +["2012-03-11 11:10:11", "2023-03-11 11:10:11"] +["2012-03-12 12:11:12", "2024-03-12 12:11:12"] + +-- !sequence_datetime_hour -- +\N +[] +[] +[] +["2012-03-04 04:03:04"] +["2012-03-05 05:04:05"] +["2012-03-06 06:05:06"] +["2012-03-07 07:06:07"] +["2012-03-08 08:07:08"] +["2012-03-09 09:08:09"] +["2012-03-10 10:09:10"] +["2012-03-11 11:10:11"] +["2012-03-12 12:11:12"] + +-- !sequence_datetime_minute -- +\N +["2012-03-01 01:00:01", "2012-03-01 01:01:01"] +["2012-03-02 02:01:02", "2012-03-02 02:03:02"] +["2012-03-03 03:02:03", "2012-03-03 03:05:03"] +["2012-03-04 04:03:04", "2012-03-04 04:07:04"] +["2012-03-05 05:04:05", "2012-03-05 05:09:05"] +["2012-03-06 06:05:06", "2012-03-06 06:11:06"] +["2012-03-07 07:06:07", "2012-03-07 07:13:07"] +["2012-03-08 08:07:08", "2012-03-08 08:15:08"] +["2012-03-09 09:08:09", "2012-03-09 09:17:09"] +["2012-03-10 10:09:10", "2012-03-10 10:19:10"] +["2012-03-11 11:10:11", "2012-03-11 11:21:11"] +["2012-03-12 12:11:12", "2012-03-12 12:23:12"] + +-- !sequence_datetime_second -- +\N +\N +["2012-03-02 02:01:02", "2012-03-02 02:01:03"] +["2012-03-03 03:02:03", "2012-03-03 03:02:05"] +["2012-03-04 04:03:04", "2012-03-04 04:03:07"] +["2012-03-05 05:04:05", "2012-03-05 05:04:09"] +["2012-03-06 06:05:06", "2012-03-06 06:05:11"] +["2012-03-07 07:06:07", "2012-03-07 07:06:13"] +["2012-03-08 08:07:08", "2012-03-08 08:07:15"] +["2012-03-09 09:08:09", "2012-03-09 09:08:17"] +["2012-03-10 10:09:10", "2012-03-10 10:09:19"] +["2012-03-11 11:10:11", "2012-03-11 11:10:21"] +["2012-03-12 12:11:12", "2012-03-12 12:11:23"] \ No newline at end of file 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 1b60f42705..5324b07bf6 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 @@ -1693,3 +1693,134 @@ 1 [1.100000000, 1.100000000] 1.100 1 [1.200000000, 1.200000000] 1.200 +-- !table_select -- +-1 \N +1 [0] +2 [0, 1] +3 [0, 1, 2] +4 [0, 1, 2, 3] +5 [0, 1, 2, 3, 4] +6 [0, 1, 2, 3, 4, 5] +7 [0, 1, 2, 3, 4, 5, 6] +\N \N +8 [0, 1, 2, 3, 4, 5, 6, 7] +9 [0, 1, 2, 3, 4, 5, 6, 7, 8] + +-- !table_select -- +-1 \N +1 [1, 2] +2 [2, 3, 4, 5, 6, 7, 8, 9] +3 \N +4 [4, 5] +5 [5, 6, 7, 8, 9] +6 \N +7 [7, 8, 9] +\N \N +8 [] +9 [9] + +-- !table_select -- +-1 \N +1 [1] +2 [2, 4, 6, 8] +3 \N +4 [4, 5] +5 [5, 6, 7, 8, 9] +6 \N +7 \N +\N \N +8 [] +9 [9] + +-- !table_select -- +2022-05-15T12:00 2022-05-18T12:00:00.123 ["2022-05-15 12:00:00", "2022-05-16 12:00:00", "2022-05-17 12:00:00"] + +-- !table_select -- +2022-05-15T12:00 2022-05-18T12:00:00.123456 ["2022-05-15 12:00:00", "2022-05-16 12:00:00", "2022-05-17 12:00:00"] + +-- !table_select -- +2022-05-15T12:00 2022-05-18T12:00:00.123 1 ["2022-05-15 12:00:00", "2022-05-16 12:00:00", "2022-05-17 12:00:00"] + +-- !table_select -- +2022-04-22T12:00:00.123 2022-05-08T12:00:00.123456 1 ["2022-04-22 12:00:00", "2022-04-29 12:00:00"] + +-- !table_select -- +2022-01-15T12:00:00.123 2022-05-18T12:00:00.123456 2 ["2022-01-15 12:00:00", "2022-03-15 12:00:00"] + +-- !table_select -- +2015-05-15T12:00:00.123 2022-05-18T12:00:00.123456 3 ["2015-05-15 12:00:00", "2018-05-15 12:00:00", "2021-05-15 12:00:00"] + +-- !table_select -- +2022-05-18T12:00:00.123 2022-05-18T23:10:00.123456 4 ["2022-05-18 12:00:00", "2022-05-18 16:00:00", "2022-05-18 20:00:00"] + +-- !table_select -- +2022-05-18T12:00:00.123 2022-05-18T12:16 5 ["2022-05-18 12:00:00", "2022-05-18 12:05:00", "2022-05-18 12:10:00", "2022-05-18 12:15:00"] + +-- !table_select -- +2022-05-18T12:00:10 2022-05-18T12:00:30 6 ["2022-05-18 12:00:10", "2022-05-18 12:00:16", "2022-05-18 12:00:22", "2022-05-18 12:00:28"] + +-- !table_select -- +2022-05-18T12:00:10 2022-05-21T12:00:30 2 ["2022-05-18 12:00:10", "2022-05-20 12:00:10"] +2022-05-22T12:00:10 2022-05-25T12:00:30 2 ["2022-05-22 12:00:10", "2022-05-24 12:00:10"] +2022-05-23T12:00:10 2022-05-26T12:00:30 2 ["2022-05-23 12:00:10", "2022-05-25 12:00:10"] +2022-05-27T12:00:10 2022-05-30T12:00:30 2 ["2022-05-27 12:00:10", "2022-05-29 12:00:10"] + +-- !const_select -- +["2022-05-15 12:00:00", "2022-05-16 12:00:00"] + +-- !const_select -- +["2022-05-15 12:00:00", "2022-05-16 12:00:00"] + +-- !const_select -- +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + +-- !const_select -- +[3, 4, 5, 6, 7, 8, 9] + +-- !const_select -- +[3, 5, 7, 9] + +-- !const_select -- +["2022-05-15 12:00:00", "2022-05-16 12:00:00"] + +-- !const_select -- +["2022-05-15 12:00:00", "2022-05-16 12:00:00"] + +-- !const_select -- +["2022-05-01 12:00:00"] + +-- !const_select -- +["2022-01-15 12:00:00", "2022-04-15 12:00:00"] + +-- !const_select -- +["2019-05-15 12:00:00", "2021-05-15 12:00:00"] + +-- !const_select -- +["2022-05-18 12:00:10", "2022-05-18 16:00:10", "2022-05-18 20:00:10"] + +-- !const_select -- +["2022-05-18 12:00:10", "2022-05-18 12:05:10", "2022-05-18 12:10:10", "2022-05-18 12:15:10"] + +-- !const_select -- +["2022-05-18 12:00:10", "2022-05-18 12:00:16", "2022-05-18 12:00:22", "2022-05-18 12:00:28"] + +-- !const_select -- +\N + +-- !const_select -- +\N + +-- !const_select -- +\N + +-- !const_select -- +\N + +-- !const_select -- +\N + +-- !const_select -- +\N + +-- !const_select -- +\N \ No newline at end of file diff --git a/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy b/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy index 42b5cf8525..e1b7d5d8d4 100644 --- a/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy +++ b/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy @@ -1260,4 +1260,18 @@ suite("nereids_scalar_fn_Array") { // array_zip sql "select array_zip([1], ['1'], [1.0])" + // array_range with datetime argument, sequence with int and datetime argument + qt_array_range_datetime1 """select array_range(kdtmv2s1, date_add(kdtmv2s1, interval kint+1 day), interval kint day) from fn_test order by kdtmv2s1;""" + qt_array_range_datetime2 """select array_range(kdtmv2s1, date_add(kdtmv2s1, interval kint+2 week), interval kint week) from fn_test order by kdtmv2s1;""" + qt_sequence_int_one_para """select sequence(kint) from fn_test order by kint;""" + qt_sequence_int_two_para """select sequence(kint, kint+2) from fn_test order by kint;""" + qt_sequence_int_three_para """select sequence(kint-1, kint+2, 1) from fn_test order by kint;""" + qt_sequence_datetime_default """select sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint-3 day)) from fn_test order by kdtmv2s1;""" + qt_sequence_datetime_day """select sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint+1 day), interval kint day) from fn_test order by kdtmv2s1;""" + qt_sequence_datetime_week """select sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint+2 week), interval kint week) from fn_test order by kdtmv2s1;""" + qt_sequence_datetime_month """select sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint+3 month), interval kint month) from fn_test order by kdtmv2s1;""" + qt_sequence_datetime_year """select sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint+3 year), interval kint year) from fn_test order by kdtmv2s1;""" + qt_sequence_datetime_hour """select sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint-3 hour), interval kint hour) from fn_test order by kdtmv2s1;""" + qt_sequence_datetime_minute """select sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint+1 minute), interval kint minute) from fn_test order by kdtmv2s1;""" + qt_sequence_datetime_second """select sequence(kdtmv2s1, date_add(kdtmv2s1, interval kint second), interval kint-1 second) from fn_test order by kdtmv2s1;""" } \ No newline at end of file diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy index 858a4bdbd3..99bb879e67 100644 --- a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy +++ b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy @@ -335,4 +335,88 @@ suite("test_array_functions") { qt_sql """ select array_position(kadcml, kdcmls1), kadcml, kdcmls1 from fn_test;""" + /* + test scope: + 1.array_range function with datetimev2 type + 2.sequence function(alias of array_range) with int and datetimev2 type + */ + sql "SET enable_nereids_planner=true" + def tableName5 = "tbl_test_sequence" + sql """drop TABLE if EXISTS ${tableName5};""" + sql """ + CREATE TABLE IF NOT EXISTS ${tableName5} ( + `test_id` int(11) NULL COMMENT "", + `k1` int(11) NULL COMMENT "", + `k2` int(11) NULL COMMENT "", + `k3` int(11) NULL COMMENT "", + `k4` datetimev2(0) NULL COMMENT "", + `k5` datetimev2(3) NULL COMMENT "", + `k6` datetimev2(6) NULL COMMENT "", + `step` int(11) NULL COMMENT "" + ) ENGINE=OLAP + DUPLICATE KEY(`test_id`) + DISTRIBUTED BY HASH(`test_id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "storage_format" = "V2" + ); + """ + sql """ INSERT INTO ${tableName5} (test_id, k1, k2, k3) VALUES(1,-1,3,5); """ + sql """ INSERT INTO ${tableName5} (test_id, k1, k2, k3) VALUES(2,1,3,5); """ + sql """ INSERT INTO ${tableName5} (test_id, k1, k2, k3) VALUES(3,2,10,2); """ + sql """ INSERT INTO ${tableName5} (test_id, k1, k2, k3) VALUES(4,3,NULL,NULL); """ + sql """ INSERT INTO ${tableName5} (test_id, k1, k2, k3) VALUES(5,4,6,1); """ + sql """ INSERT INTO ${tableName5} (test_id, k1, k2, k3) VALUES(6,5,10,1); """ + sql """ INSERT INTO ${tableName5} (test_id, k1, k2, k3) VALUES(7,6,NULL,1); """ + sql """ INSERT INTO ${tableName5} (test_id, k1, k2, k3) VALUES(8,7,10,NULL); """ + sql """ INSERT INTO ${tableName5} (test_id, k1, k2, k3) VALUES(9,NULL,10,2); """ + sql """ INSERT INTO ${tableName5} (test_id, k1, k2, k3) VALUES(10,8,2,2); """ + sql """ INSERT INTO ${tableName5} (test_id, k1, k2, k3) VALUES(11,9,10,6); """ + sql """ INSERT INTO ${tableName5} (test_id, k4, k5) VALUES(12, '2022-05-15 12:00:00', '2022-05-18 12:00:00.123'); """ + sql """ INSERT INTO ${tableName5} (test_id, k4, k6) VALUES(13, '2022-05-15 12:00:00', '2022-05-18 12:00:00.123456'); """ + sql """ INSERT INTO ${tableName5} (test_id, k4, k5, step) VALUES(14, '2022-05-15 12:00:00', '2022-05-18 12:00:00.123', 1); """ + sql """ INSERT INTO ${tableName5} (test_id, k5, k6, step) VALUES(15, '2022-04-22 12:00:00.123', '2022-05-08 12:00:00.123456', 1); """ + sql """ INSERT INTO ${tableName5} (test_id, k5, k6, step) VALUES(16, '2022-01-15 12:00:00.123', '2022-05-18 12:00:00.123456', 2); """ + sql """ INSERT INTO ${tableName5} (test_id, k5, k6, step) VALUES(17, '2015-05-15 12:00:00.123', '2022-05-18 12:00:00.123456', 3); """ + sql """ INSERT INTO ${tableName5} (test_id, k5, k6, step) VALUES(18, '2022-05-18 12:00:00.123', '2022-05-18 23:10:00.123456', 4); """ + sql """ INSERT INTO ${tableName5} (test_id, k5, k6, step) VALUES(19, '2022-05-18 12:00:00.123', '2022-05-18 12:16:00', 5); """ + sql """ INSERT INTO ${tableName5} (test_id, k5, k6, step) VALUES(20, '2022-05-18 12:00:10', '2022-05-18 12:00:30', 6); """ + sql """ INSERT INTO ${tableName5} (test_id, k5, k6, step) VALUES(21, '2022-05-18 12:00:10', '2022-05-21 12:00:30', 2); """ + sql """ INSERT INTO ${tableName5} (test_id, k5, k6, step) VALUES(22, '2022-05-22 12:00:10', '2022-05-25 12:00:30', 2); """ + sql """ INSERT INTO ${tableName5} (test_id, k5, k6, step) VALUES(23, '2022-05-23 12:00:10', '2022-05-26 12:00:30', 2); """ + sql """ INSERT INTO ${tableName5} (test_id, k5, k6, step) VALUES(24, '2022-05-27 12:00:10', '2022-05-30 12:00:30', 2); """ + + qt_table_select "SELECT k1, sequence(k1) from ${tableName5} where test_id < 12 ORDER BY test_id; " + qt_table_select "SELECT k1, sequence(k1,k2) from ${tableName5} where test_id < 12 ORDER BY test_id; " + qt_table_select "SELECT k1, sequence(k1,k2,k3) from ${tableName5} where test_id < 12 ORDER BY test_id; " + qt_table_select "SELECT k4, k5, sequence(k4, k5) from ${tableName5} where test_id = 12; " + qt_table_select "SELECT k4, k6, sequence(k4, k6) from ${tableName5} where test_id = 13; " + qt_table_select "SELECT k4, k5, step, sequence(k4, k5, interval step day) from ${tableName5} where test_id = 14; " + qt_table_select "SELECT k5, k6, step, sequence(k5, k6, interval step week) from ${tableName5} where test_id = 15; " + qt_table_select "SELECT k5, k6, step, sequence(k5, k6, interval step month) from ${tableName5} where test_id = 16; " + qt_table_select "SELECT k5, k6, step, sequence(k5, k6, interval step year) from ${tableName5} where test_id = 17; " + qt_table_select "SELECT k5, k6, step, sequence(k5, k6, interval step hour) from ${tableName5} where test_id = 18; " + qt_table_select "SELECT k5, k6, step, sequence(k5, k6, interval step minute) from ${tableName5} where test_id = 19; " + qt_table_select "SELECT k5, k6, step, sequence(k5, k6, interval step second) from ${tableName5} where test_id = 20; " + qt_table_select "SELECT k5, k6, step, sequence(k5, k6, interval step day) from ${tableName5} where test_id between 21 and 24 order by test_id; " + qt_const_select "select array_range(cast('2022-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0))); " + qt_const_select "select array_range(cast('2022-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0)), interval 1 day); " + qt_const_select "select sequence(10); " + qt_const_select "select sequence(3, 10); " + qt_const_select "select sequence(3, 10, 2); " + qt_const_select "select sequence(cast('2022-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0))); " + qt_const_select "select sequence(cast('2022-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0)), interval 1 day); " + qt_const_select "select sequence(cast('2022-05-01 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0)), interval 2 week); " + qt_const_select "select sequence(cast('2022-01-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0)), interval 3 month); " + qt_const_select "select sequence(cast('2019-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0)), interval 2 year); " + qt_const_select "select sequence(cast('2022-05-18 12:00:10' as datetimev2(0)), cast('2022-05-18 22:00:30' as datetimev2(0)), interval 4 hour); " + qt_const_select "select sequence(cast('2022-05-18 12:00:10' as datetimev2(0)), cast('2022-05-18 12:16:30' as datetimev2(0)), interval 5 minute); " + qt_const_select "select sequence(cast('2022-05-18 12:00:10' as datetimev2(0)), cast('2022-05-18 12:00:30' as datetimev2(0)), interval 6 second); " + qt_const_select "select sequence(cast('2022-05-18 12:00:10' as datetimev2(0)), cast('2022-05-18 22:00:30' as datetimev2(0)), interval -4 hour); " + qt_const_select "select sequence(cast('2022-35-38 12:00:10' as datetimev2(0)), cast('2022-05-18 22:00:30' as datetimev2(0)), interval 4 hour); " + qt_const_select "select sequence(cast('2022-05-15 12:00:00' as datetimev2(0)), cast('2022-35-37 12:00:00' as datetimev2(0))); " + qt_const_select "select sequence(1, 10, interval 10 day); " + qt_const_select "select sequence(cast('2022-35-38 12:00:10' as datetimev2(0)), cast('2022-05-18 22:00:30' as datetimev2(0))); " + qt_const_select "select sequence(1, 10, 0); " + qt_const_select "select sequence(cast('2022-05-15 12:00:00' as datetimev2(0)), cast('2022-05-17 12:00:00' as datetimev2(0)), interval 0 day); " }