[chore] add int128/256, uint128/256 for arrayDifference, arrayCumSum

1. add tests.

Signed-off-by: clundro <859287553@qq.com>
This commit is contained in:
clundro 2023-04-18 01:05:08 +08:00 committed by cluster
parent ba5ca15c40
commit a2c8661936
4 changed files with 96 additions and 46 deletions

View File

@ -29,15 +29,28 @@ struct ArrayCumSumImpl
{
WhichDataType which(expression_return);
if (which.isNativeUInt())
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>());
if (which.isUInt())
{
if (which.isNativeUInt())
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>());
if (which.isUInt256())
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt256>());
else
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt128>());
}
if (which.isNativeInt())
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeInt64>());
if (which.isInt())
{
if (which.isNativeInt())
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeInt64>());
if (which.isInt256())
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeInt256>());
else
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeInt128>());
}
if (which.isFloat())
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeFloat64>());
if (which.isDecimal())
{
UInt32 scale = getDecimalScale(*expression_return);
@ -54,8 +67,8 @@ struct ArrayCumSumImpl
template <typename Src, typename Dst>
static void NO_SANITIZE_UNDEFINED implConst(
size_t size, const IColumn::Offset * __restrict offsets, Dst * __restrict res_values, Src src_value)
static void NO_SANITIZE_UNDEFINED
implConst(size_t size, const IColumn::Offset * __restrict offsets, Dst * __restrict res_values, Src src_value)
{
size_t pos = 0;
for (const auto * end = offsets + size; offsets < end; ++offsets)
@ -71,8 +84,8 @@ struct ArrayCumSumImpl
}
template <typename Src, typename Dst>
static void NO_SANITIZE_UNDEFINED implVector(
size_t size, const IColumn::Offset * __restrict offsets, Dst * __restrict res_values, const Src * __restrict src_values)
static void NO_SANITIZE_UNDEFINED
implVector(size_t size, const IColumn::Offset * __restrict offsets, Dst * __restrict res_values, const Src * __restrict src_values)
{
size_t pos = 0;
for (const auto * end = offsets + size; offsets < end; ++offsets)
@ -136,35 +149,31 @@ struct ArrayCumSumImpl
implVector(offsets.size(), offsets.data(), res_values.data(), data.data());
res_ptr = ColumnArray::create(std::move(res_nested), array.getOffsetsPtr());
return true;
}
static ColumnPtr execute(const ColumnArray & array, ColumnPtr mapped)
{
ColumnPtr res;
if (executeType< UInt8 , UInt64>(mapped, array, res) ||
executeType< UInt16, UInt64>(mapped, array, res) ||
executeType< UInt32, UInt64>(mapped, array, res) ||
executeType< UInt64, UInt64>(mapped, array, res) ||
executeType< Int8 , Int64>(mapped, array, res) ||
executeType< Int16, Int64>(mapped, array, res) ||
executeType< Int32, Int64>(mapped, array, res) ||
executeType< Int64, Int64>(mapped, array, res) ||
executeType<Float32,Float64>(mapped, array, res) ||
executeType<Float64,Float64>(mapped, array, res) ||
executeType<Decimal32, Decimal128>(mapped, array, res) ||
executeType<Decimal64, Decimal128>(mapped, array, res) ||
executeType<Decimal128, Decimal128>(mapped, array, res) ||
executeType<Decimal256, Decimal256>(mapped, array, res))
if (executeType<UInt8, UInt64>(mapped, array, res) || executeType<UInt16, UInt64>(mapped, array, res)
|| executeType<UInt32, UInt64>(mapped, array, res) || executeType<UInt64, UInt64>(mapped, array, res)
|| executeType<UInt128, UInt128>(mapped, array, res) || executeType<UInt256, UInt256>(mapped, array, res)
|| executeType<Int8, Int64>(mapped, array, res) || executeType<Int16, Int64>(mapped, array, res)
|| executeType<Int32, Int64>(mapped, array, res) || executeType<Int64, Int64>(mapped, array, res)
|| executeType<Int128, Int128>(mapped, array, res) || executeType<Int256, Int256>(mapped, array, res)
|| executeType<Float32, Float64>(mapped, array, res) || executeType<Float64, Float64>(mapped, array, res)
|| executeType<Decimal32, Decimal128>(mapped, array, res) || executeType<Decimal64, Decimal128>(mapped, array, res)
|| executeType<Decimal128, Decimal128>(mapped, array, res) || executeType<Decimal256, Decimal256>(mapped, array, res))
return res;
else
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Unexpected column for arrayCumSum: {}", mapped->getName());
}
};
struct NameArrayCumSum { static constexpr auto name = "arrayCumSum"; };
struct NameArrayCumSum
{
static constexpr auto name = "arrayCumSum";
};
using FunctionArrayCumSum = FunctionArrayMapped<ArrayCumSumImpl, NameArrayCumSum>;
REGISTER_FUNCTION(ArrayCumSum)

View File

@ -41,6 +41,12 @@ struct ArrayDifferenceImpl
if (which.isUInt32() || which.isUInt64() || which.isInt32() || which.isInt64() || which.isDate32() || which.isDateTime())
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeInt64>());
if (which.isUInt128() || which.isInt128())
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeInt128>());
if (which.isUInt256() || which.isInt256())
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeInt256>());
if (which.isFloat32() || which.isFloat64())
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeFloat64>());
@ -55,7 +61,8 @@ struct ArrayDifferenceImpl
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeDecimal<Decimal64>>(precision, scale));
}
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "arrayDifference cannot process values of type {}", expression_return->getName());
throw Exception(
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "arrayDifference cannot process values of type {}", expression_return->getName());
}
@ -82,9 +89,7 @@ struct ArrayDifferenceImpl
ResultNativeType result_value;
bool overflow = common::subOverflow(
static_cast<ResultNativeType>(curr.value),
static_cast<ResultNativeType>(prev.value),
result_value);
static_cast<ResultNativeType>(curr.value), static_cast<ResultNativeType>(prev.value), result_value);
if (overflow)
throw Exception(ErrorCodes::DECIMAL_OVERFLOW, "Decimal math overflow");
@ -141,28 +146,26 @@ struct ArrayDifferenceImpl
ColumnPtr res;
mapped = mapped->convertToFullColumnIfConst();
if (executeType< UInt8 , Int16>(mapped, array, res) ||
executeType< UInt16, Int32>(mapped, array, res) ||
executeType< UInt32, Int64>(mapped, array, res) ||
executeType< UInt64, Int64>(mapped, array, res) ||
executeType< Int8 , Int16>(mapped, array, res) ||
executeType< Int16, Int32>(mapped, array, res) ||
executeType< Int32, Int64>(mapped, array, res) ||
executeType< Int64, Int64>(mapped, array, res) ||
executeType<Float32,Float64>(mapped, array, res) ||
executeType<Float64,Float64>(mapped, array, res) ||
executeType<Decimal32, Decimal32>(mapped, array, res) ||
executeType<Decimal64, Decimal64>(mapped, array, res) ||
executeType<Decimal128, Decimal128>(mapped, array, res) ||
executeType<Decimal256, Decimal256>(mapped, array, res) ||
executeType<DateTime64, Decimal64>(mapped, array, res))
if (executeType<UInt8, Int16>(mapped, array, res) || executeType<UInt16, Int32>(mapped, array, res)
|| executeType<UInt32, Int64>(mapped, array, res) || executeType<UInt64, Int64>(mapped, array, res)
|| executeType<Int8, Int16>(mapped, array, res) || executeType<Int16, Int32>(mapped, array, res)
|| executeType<Int32, Int64>(mapped, array, res) || executeType<Int64, Int64>(mapped, array, res)
|| executeType<UInt128, Int128>(mapped, array, res) || executeType<Int128, Int128>(mapped, array, res)
|| executeType<UInt256, Int256>(mapped, array, res) || executeType<Int256, Int256>(mapped, array, res)
|| executeType<Float32, Float64>(mapped, array, res) || executeType<Float64, Float64>(mapped, array, res)
|| executeType<Decimal32, Decimal32>(mapped, array, res) || executeType<Decimal64, Decimal64>(mapped, array, res)
|| executeType<Decimal128, Decimal128>(mapped, array, res) || executeType<Decimal256, Decimal256>(mapped, array, res)
|| executeType<DateTime64, Decimal64>(mapped, array, res))
return res;
else
throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Unexpected column for arrayDifference: {}", mapped->getName());
}
};
struct NameArrayDifference { static constexpr auto name = "arrayDifference"; };
struct NameArrayDifference
{
static constexpr auto name = "arrayDifference";
};
using FunctionArrayDifference = FunctionArrayMapped<ArrayDifferenceImpl, NameArrayDifference>;
REGISTER_FUNCTION(ArrayDifference)

View File

@ -0,0 +1,19 @@
[1,3]
[1,3]
[1,3]
[1,3]
[3,4,5]
[1,2]
Array(UInt128)
Array(Int128)
Array(UInt256)
Array(Int256)
[0,2]
[0,2]
[0,2]
[0,2]
Array(Int128)
Array(Int128)
Array(Int256)
Array(Int256)

View File

@ -0,0 +1,19 @@
SELECT arrayCumSum([CAST('1', 'Int128'), 2]);
SELECT arrayCumSum([CAST('1', 'Int256'), 2]);
SELECT arrayCumSum([CAST('1', 'UInt128'), 2]);
SELECT arrayCumSum([CAST('1', 'UInt256'), 2]);
SELECT arrayCumSum([3, CAST('1', 'Int128'),CAST('1', 'Int256')]);
SELECT arrayCumSum([CAST('1', 'Int256'), CAST('1', 'Int128')]);
SELECT toTypeName(arrayCumSum([CAST('1', 'UInt128'), 2]));
SELECT toTypeName(arrayCumSum([CAST('1', 'Int128'), 2]));
SELECT toTypeName(arrayCumSum([CAST('1', 'UInt256'), CAST('1', 'UInt128')]));
SELECT toTypeName(arrayCumSum([CAST('1', 'Int256'), CAST('1', 'Int128')]));
SELECT arrayDifference([CAST('1', 'Int256'), 3]);
SELECT arrayDifference([CAST('1', 'UInt256'), 3]);
SELECT arrayDifference([CAST('1', 'UInt128'), 3]);
SELECT arrayDifference([CAST('1', 'Int128'), 3]);
SELECT toTypeName(arrayDifference([CAST('1', 'UInt128'), 3]));
SELECT toTypeName(arrayDifference([CAST('1', 'Int128'), 3]));
SELECT toTypeName(arrayDifference([CAST('1', 'UInt256'), 3]));
SELECT toTypeName(arrayDifference([CAST('1', 'Int256'), 3]));