mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Merge branch 'patch-6' of https://github.com/hczhcz/ClickHouse into hczhcz-patch-6
This commit is contained in:
commit
b14a6ab8ab
@ -8,6 +8,7 @@ namespace DB
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
||||
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
||||
}
|
||||
|
||||
@ -50,48 +51,54 @@ public:
|
||||
const Array & params
|
||||
) const override
|
||||
{
|
||||
for (const Field & param : params)
|
||||
{
|
||||
if (
|
||||
param.getType() != Field::Types::UInt64
|
||||
&& param.getType() != Field::Types::Int64
|
||||
)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
WhichDataType which {
|
||||
arguments.back()
|
||||
};
|
||||
|
||||
if (
|
||||
which.isNativeUInt()
|
||||
|| which.isDateOrDateTime()
|
||||
)
|
||||
if (which.isNativeUInt() || which.isDateOrDateTime())
|
||||
{
|
||||
UInt64 begin = params[params.size() - 3].safeGet<UInt64>();
|
||||
UInt64 end = params[params.size() - 2].safeGet<UInt64>();
|
||||
|
||||
UInt64 step = params[params.size() - 1].safeGet<UInt64>();
|
||||
|
||||
return std::make_shared<AggregateFunctionResample<UInt64>>(
|
||||
nested_function,
|
||||
params.front().get<UInt64>(),
|
||||
params[1].get<UInt64>(),
|
||||
params.back().get<UInt64>(),
|
||||
begin,
|
||||
end,
|
||||
step,
|
||||
arguments,
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
if (which.isNativeInt() || which.isEnum() || which.isInterval())
|
||||
{
|
||||
Int64 begin, end;
|
||||
|
||||
// notice: UInt64 -> Int64 may lead to overflow
|
||||
if (!params[params.size() - 3].tryGet<Int64>(begin))
|
||||
begin = params[params.size() - 3].safeGet<UInt64>();
|
||||
if (!params[params.size() - 2].tryGet<Int64>(end))
|
||||
end = params[params.size() - 2].safeGet<UInt64>();
|
||||
|
||||
UInt64 step = params[params.size() - 1].safeGet<UInt64>();
|
||||
|
||||
if (
|
||||
which.isNativeInt()
|
||||
|| which.isEnum()
|
||||
|| which.isInterval()
|
||||
)
|
||||
return std::make_shared<AggregateFunctionResample<Int64>>(
|
||||
nested_function,
|
||||
params.front().get<Int64>(),
|
||||
params[1].get<Int64>(),
|
||||
params.back().get<Int64>(),
|
||||
begin,
|
||||
end,
|
||||
step,
|
||||
arguments,
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
// TODO
|
||||
return nullptr;
|
||||
throw Exception(
|
||||
"Illegal types of argument for aggregate function " + getName()
|
||||
+ ", the type of the last argument should be native integer or integer-like",
|
||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -10,7 +10,7 @@ namespace DB
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int BAD_ARGUMENTS;
|
||||
extern const int ARGUMENT_OUT_OF_BOUND;
|
||||
}
|
||||
|
||||
template <typename Key>
|
||||
@ -27,7 +27,7 @@ private:
|
||||
|
||||
Key begin;
|
||||
Key end;
|
||||
Key step;
|
||||
size_t step;
|
||||
|
||||
size_t total;
|
||||
size_t aod;
|
||||
@ -38,7 +38,7 @@ public:
|
||||
AggregateFunctionPtr nested_function,
|
||||
Key begin,
|
||||
Key end,
|
||||
Key step,
|
||||
size_t step,
|
||||
const DataTypes & arguments,
|
||||
const Array & params
|
||||
) :
|
||||
@ -50,11 +50,7 @@ public:
|
||||
begin {begin},
|
||||
end {end},
|
||||
step {step},
|
||||
total {
|
||||
static_cast<size_t>(
|
||||
(end - begin + step - (step >= 0 ? 1 : -1)) / step
|
||||
)
|
||||
},
|
||||
total {0},
|
||||
aod {nested_function->alignOfData()},
|
||||
sod {(nested_function->sizeOfData() + aod - 1) / aod * aod}
|
||||
{
|
||||
@ -63,21 +59,20 @@ public:
|
||||
throw Exception(
|
||||
"The step given in function "
|
||||
+ getName() + " should not be zero",
|
||||
ErrorCodes::BAD_ARGUMENTS
|
||||
ErrorCodes::ARGUMENT_OUT_OF_BOUND
|
||||
);
|
||||
|
||||
if (end < begin)
|
||||
total = 0;
|
||||
else
|
||||
total = (end - begin + step - 1) / step;
|
||||
|
||||
if (total > MAX_ELEMENTS)
|
||||
throw Exception(
|
||||
"The range given in function "
|
||||
+ getName() + " contains too many elements",
|
||||
ErrorCodes::BAD_ARGUMENTS
|
||||
ErrorCodes::ARGUMENT_OUT_OF_BOUND
|
||||
);
|
||||
|
||||
if ((step > 0 && end < begin) || (step < 0 && end > begin))
|
||||
{
|
||||
end = begin;
|
||||
total = 0;
|
||||
}
|
||||
}
|
||||
|
||||
String getName() const override
|
||||
@ -141,10 +136,7 @@ public:
|
||||
else
|
||||
key = columns[last_col]->getUInt(row_num);
|
||||
|
||||
if (step > 0 && (key < begin || key >= end))
|
||||
return;
|
||||
|
||||
if (step < 0 && (key > begin || key <= end))
|
||||
if (key < begin || key >= end)
|
||||
return;
|
||||
|
||||
size_t pos = (key - begin) / step;
|
||||
|
@ -1,16 +1,16 @@
|
||||
[11,12,13,14,15,16]
|
||||
[27,31,17]
|
||||
[39,48,18]
|
||||
[19,35,31,27,23,10]
|
||||
[39,48,18]
|
||||
[0,0,0,0,0,0]
|
||||
[0.5,0.5,0]
|
||||
[0.816496580927726,0.816496580927726,0]
|
||||
[0,0.5,0.5,0.5,0.5,0]
|
||||
[0.816496580927726,0.816496580927726,0]
|
||||
[[11],[12],[13],[14],[15],[16]]
|
||||
[[13,14],[15,16],[17]]
|
||||
[[12,13,14],[15,16,17],[18]]
|
||||
[[19],[17,18],[15,16],[13,14],[11,12],[10]]
|
||||
[[12,13,14],[15,16,17],[18]]
|
||||
[1,1,1,1,1,1]
|
||||
[2,2,1]
|
||||
[3,3,1]
|
||||
[1,2,2,2,2,1]
|
||||
[3,3,1]
|
||||
|
@ -1,16 +1,16 @@
|
||||
select arrayReduce('sumResample(1, 7, 1)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('sumResample(3, 8, 2)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('sumResample(2, 9, 3)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('sumResample(10, -1, -2)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [-0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('sumResample(2, 9, 3)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [-0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('stddevPopResample(1, 7, 1)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('stddevPopResample(3, 8, 2)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('stddevPopResample(2, 9, 3)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('stddevPopResample(10, -1, -2)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [-0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('stddevPopResample(2, 9, 3)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [-0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('groupArrayResample(1, 7, 1)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('groupArrayResample(3, 8, 2)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('groupArrayResample(2, 9, 3)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('groupArrayResample(10, -1, -2)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [-0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('groupArrayResample(2, 9, 3)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [-0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('uniqResample(1, 7, 1)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('uniqResample(3, 8, 2)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('uniqResample(2, 9, 3)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('uniqResample(10, -1, -2)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [-0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
select arrayReduce('uniqResample(2, 9, 3)', [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [-0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
|
Loading…
Reference in New Issue
Block a user