diff --git a/dbms/src/Functions/FunctionsHigherOrder.h b/dbms/src/Functions/FunctionsHigherOrder.h index b02653b5320..b97ece46f90 100644 --- a/dbms/src/Functions/FunctionsHigherOrder.h +++ b/dbms/src/Functions/FunctionsHigherOrder.h @@ -62,7 +62,6 @@ struct ArrayCumSumImpl static DataTypePtr getReturnType(const DataTypePtr & expression_return, const DataTypePtr & /*array_element*/) { - //return std::make_shared(array_element); if (checkDataType(&*expression_return) || checkDataType(&*expression_return) || checkDataType(&*expression_return) || @@ -79,7 +78,7 @@ struct ArrayCumSumImpl checkDataType(&*expression_return)) return std::make_shared(std::make_shared()); - throw Exception("arraySum cannot add values of type " + expression_return->getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); + throw Exception("arrayCumSum cannot add values of type " + expression_return->getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); } @@ -90,7 +89,7 @@ struct ArrayCumSumImpl if (!column) return false; - /*if (!column) + if (!column) { const ColumnConst * column_const = checkAndGetColumnConst>(&*mapped); @@ -99,9 +98,10 @@ struct ArrayCumSumImpl const Element x = column_const->template getValue(); - auto res_nested = ColumnVector::create(); - ColumnVector::Container & res_values = res_nested->getData(); - res_values.resize(offsets.size()); + i // create output column + auto res_nested = ColumnVector::create(); + typename ColumnVector::Container & res_values = res_nested->getData(); + res_values.resize(data.size()); size_t pos = 0; for (size_t i = 0; i < offsets.size(); ++i) @@ -115,7 +115,7 @@ struct ArrayCumSumImpl res_ptr = ColumnArray::create(std::move(res_nested), offsets); return true; - }*/ + } const IColumn::Offsets & offsets = array.getOffsets(); const typename ColumnVector::Container & data = column->getData(); diff --git a/dbms/tests/queries/0_stateless/00182_functions_higher_order_and_consts.sql b/dbms/tests/queries/0_stateless/00182_functions_higher_order_and_consts.sql index 5513df2e1b0..4f8772d807b 100644 --- a/dbms/tests/queries/0_stateless/00182_functions_higher_order_and_consts.sql +++ b/dbms/tests/queries/0_stateless/00182_functions_higher_order_and_consts.sql @@ -51,6 +51,13 @@ SELECT arrayFirstIndex(x -> 0, range(number)) FROM system.numbers LIMIT 10; SELECT arrayFirstIndex(x -> 1, emptyArrayUInt8()); SELECT arrayFirstIndex(x -> 1, [1, 2, 3]); SELECT arrayFirstIndex(x -> 1, range(number)) FROM system.numbers LIMIT 10; +SELECT '---cumsum---'; +SELECT arrayCumSum(x -> 0, emptyArrayUInt8()); +SELECT arrayCumSum(x -> 0, [1, 2, 3]); +SELECT arrayCumSum(x -> 0, range(number)) FROM system.numbers LIMIT 10; +SELECT arrayCumSum(x -> 10, emptyArrayUInt8()); +SELECT arrayCumSum(x -> 10, [1, 2, 3]); +SELECT arrayCumSum(x -> 10, range(number)) FROM system.numbers LIMIT 10; SELECT '---map--'; SELECT arrayMap(x -> materialize(123), emptyArrayUInt8()); @@ -105,6 +112,13 @@ SELECT arrayFirstIndex(x -> materialize(0), range(number)) FROM system.numbers L SELECT arrayFirstIndex(x -> materialize(1), emptyArrayUInt8()); SELECT arrayFirstIndex(x -> materialize(1), [1, 2, 3]); SELECT arrayFirstIndex(x -> materialize(1), range(number)) FROM system.numbers LIMIT 10; +SELECT '--cumsum---'; +SELECT arrayCumSum(x -> materialize(0), emptyArrayUInt8()); +SELECT arrayCumSum(x -> materialize(0), [1, 2, 3]); +SELECT arrayCumSum(x -> materialize(0), range(number)) FROM system.numbers LIMIT 10; +SELECT arrayCumSum(x -> materialize(10), emptyArrayUInt8()); +SELECT arrayCumSum(x -> materialize(10), [1, 2, 3]); +SELECT arrayCumSum(x -> materialize(10), range(number)) FROM system.numbers LIMIT 10; SELECT '---map--'; SELECT arrayMap(x -> 123, emptyArrayString()); @@ -159,6 +173,13 @@ SELECT arrayFirstIndex(x -> 0, arrayMap(x -> toString(x), range(number))) FROM s SELECT arrayFirstIndex(x -> 1, emptyArrayString()); SELECT arrayFirstIndex(x -> 1, arrayMap(x -> toString(x), [1, 2, 3])); SELECT arrayFirstIndex(x -> 1, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; +SELECT '---cumsum---'; +SELECT arrayCumSum(x -> 0, emptyArrayString()); +SELECT arrayCumSum(x -> 0, arrayMap(x -> toString(x), [1, 2, 3])); +SELECT arrayCumSum(x -> 0, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; +SELECT arrayCumSum(x -> 10, emptyArrayString()); +SELECT arrayCumSum(x -> 10, arrayMap(x -> toString(x), [1, 2, 3])); +SELECT arrayCumSum(x -> 10, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; SELECT '---map--'; SELECT arrayMap(x -> materialize(123), emptyArrayString()); @@ -213,7 +234,13 @@ SELECT arrayFirstIndex(x -> materialize(0), arrayMap(x -> toString(x), range(num SELECT arrayFirstIndex(x -> materialize(1), emptyArrayString()); SELECT arrayFirstIndex(x -> materialize(1), arrayMap(x -> toString(x), [1, 2, 3])); SELECT arrayFirstIndex(x -> materialize(1), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; - +SELECT '---cumsum---'; +SELECT arrayCumSum(x -> materialize(0), emptyArrayString()); +SELECT arrayCumSum(x -> materialize(0), arrayMap(x -> toString(x), [1, 2, 3])); +SELECT arrayCumSum(x -> materialize(0), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; +SELECT arrayCumSum(x -> materialize(10), emptyArrayString()); +SELECT arrayCumSum(x -> materialize(10), arrayMap(x -> toString(x), [1, 2, 3])); +SELECT arrayCumSum(x -> materialize(10), arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; SELECT '--- ---'; SELECT arrayMap(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; @@ -224,6 +251,7 @@ SELECT arrayAll(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; SELECT arrayExists(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; SELECT arrayFirst(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; SELECT arrayFirstIndex(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; +SELECT arrayCumSum(x -> number % 2, range(number)) FROM system.numbers LIMIT 10; SELECT '--- ---'; SELECT arrayMap(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; SELECT arrayFilter(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; @@ -233,3 +261,4 @@ SELECT arrayAll(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM SELECT arrayExists(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; SELECT arrayFirst(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; SELECT arrayFirstIndex(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10; +SELECT arrayCumSum(x -> number % 2, arrayMap(x -> toString(x), range(number))) FROM system.numbers LIMIT 10;