Attempt to normalize big integers

This commit is contained in:
Alexey Milovidov 2021-04-25 12:51:18 +03:00
parent 649550c5ab
commit 76a5d023e0
6 changed files with 21 additions and 11 deletions

View File

@ -38,7 +38,7 @@ struct MovingData
using Array = PODArray<T, 32, Allocator>;
Array value; /// Prefix sums.
T sum = 0;
T sum{};
void NO_SANITIZE_UNDEFINED add(T val, Arena * arena)
{
@ -69,9 +69,9 @@ struct MovingAvgData : public MovingData<T>
T NO_SANITIZE_UNDEFINED get(size_t idx, UInt64 window_size) const
{
if (idx < window_size)
return this->value[idx] / window_size;
return this->value[idx] / T(window_size);
else
return (this->value[idx] - this->value[idx - window_size]) / window_size;
return (this->value[idx] - this->value[idx - window_size]) / T(window_size);
}
};

View File

@ -100,13 +100,14 @@ AggregateFunctionPtr createAggregateFunctionQuantile(const std::string & name, c
if (which.idx == TypeIndex::Decimal32) return std::make_shared<Function<Decimal32, false>>(argument_types, params);
if (which.idx == TypeIndex::Decimal64) return std::make_shared<Function<Decimal64, false>>(argument_types, params);
if (which.idx == TypeIndex::Decimal128) return std::make_shared<Function<Decimal128, false>>(argument_types, params);
if (which.idx == TypeIndex::Decimal256) return std::make_shared<Function<Decimal256, false>>(argument_types, params);
if (which.idx == TypeIndex::DateTime64) return std::make_shared<Function<DateTime64, false>>(argument_types, params);
//if (which.idx == TypeIndex::Decimal256) return std::make_shared<Function<Decimal256, false>>(argument_types, params);
}
if constexpr (supportBigInt<Function>())
{
if (which.idx == TypeIndex::Int128) return std::make_shared<Function<Int128, true>>(argument_types, params);
if (which.idx == TypeIndex::UInt128) return std::make_shared<Function<Int128, true>>(argument_types, params);
if (which.idx == TypeIndex::Int256) return std::make_shared<Function<Int256, true>>(argument_types, params);
if (which.idx == TypeIndex::UInt256) return std::make_shared<Function<UInt256, true>>(argument_types, params);
}

View File

@ -131,11 +131,10 @@ public:
static_cast<ResultType>(static_cast<const ColVecT2 &>(*columns[1]).getData()[row_num]));
else
{
if constexpr (std::is_same_v<T1, Decimal256>)
if constexpr (IsDecimalNumber<T1>)
{
this->data(place).add(static_cast<ResultType>(
static_cast<const ColVecT1 &>(*columns[0]).getData()[row_num].value
));
static_cast<const ColVecT1 &>(*columns[0]).getData()[row_num].value));
}
else
this->data(place).add(

View File

@ -21,6 +21,7 @@
M(UInt16) \
M(UInt32) \
M(UInt64) \
M(UInt128) \
M(UInt256) \
M(Int8) \
M(Int16) \
@ -109,6 +110,7 @@ static IAggregateFunction * createWithUnsignedIntegerType(const IDataType & argu
if (which.idx == TypeIndex::UInt16) return new AggregateFunctionTemplate<UInt16, Data<UInt16>>(std::forward<TArgs>(args)...);
if (which.idx == TypeIndex::UInt32) return new AggregateFunctionTemplate<UInt32, Data<UInt32>>(std::forward<TArgs>(args)...);
if (which.idx == TypeIndex::UInt64) return new AggregateFunctionTemplate<UInt64, Data<UInt64>>(std::forward<TArgs>(args)...);
if (which.idx == TypeIndex::UInt128) return new AggregateFunctionTemplate<UInt128, Data<UInt128>>(std::forward<TArgs>(args)...);
return nullptr;
}

View File

@ -54,7 +54,7 @@ struct QuantileReservoirSampler
/// Get the value of the `level` quantile. The level must be between 0 and 1.
Value get(Float64 level)
{
return data.quantileInterpolated(level);
return Value(data.quantileInterpolated(level));
}
/// Get the `size` values of `levels` quantiles. Write `size` results starting with `result` address.
@ -62,7 +62,7 @@ struct QuantileReservoirSampler
void getMany(const Float64 * levels, const size_t * indices, size_t size, Value * result)
{
for (size_t i = 0; i < size; ++i)
result[indices[i]] = data.quantileInterpolated(levels[indices[i]]);
result[indices[i]] = Value(data.quantileInterpolated(levels[indices[i]]));
}
/// The same, but in the case of an empty state, NaN is returned.

View File

@ -131,12 +131,20 @@ public:
size_t left_index = static_cast<size_t>(index);
size_t right_index = left_index + 1;
if (right_index == samples.size())
return static_cast<double>(samples[left_index]);
{
if constexpr (DB::IsDecimalNumber<T>)
return static_cast<double>(samples[left_index].value);
else
return static_cast<double>(samples[left_index]);
}
double left_coef = right_index - index;
double right_coef = index - left_index;
return static_cast<double>(samples[left_index]) * left_coef + static_cast<double>(samples[right_index]) * right_coef;
if constexpr (DB::IsDecimalNumber<T>)
return static_cast<double>(samples[left_index].value) * left_coef + static_cast<double>(samples[right_index].value) * right_coef;
else
return static_cast<double>(samples[left_index]) * left_coef + static_cast<double>(samples[right_index]) * right_coef;
}
void merge(const ReservoirSampler<T, OnEmpty> & b)