mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 07:01:59 +00:00
hex/bin functions support AggregateFunction states.
This commit is contained in:
parent
9c2aad6c17
commit
e4b1e0619c
@ -25,6 +25,7 @@
|
||||
#include <Common/hex.h>
|
||||
#include <Common/typeid_cast.h>
|
||||
#include <Common/BitHelpers.h>
|
||||
#include <Functions/FunctionFactory.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <common/range.h>
|
||||
@ -954,6 +955,8 @@ public:
|
||||
template <typename Impl>
|
||||
class EncodeToBinaryRepr : public IFunction
|
||||
{
|
||||
private:
|
||||
ContextPtr context;
|
||||
public:
|
||||
static constexpr auto name = Impl::name;
|
||||
static constexpr size_t word_size = Impl::word_size;
|
||||
@ -978,18 +981,29 @@ public:
|
||||
!which.isDateTime64() &&
|
||||
!which.isUInt() &&
|
||||
!which.isFloat() &&
|
||||
!which.isDecimal())
|
||||
!which.isDecimal() &&
|
||||
!which.isAggregateFunction())
|
||||
throw Exception("Illegal type " + arguments[0]->getName() + " of argument of function " + getName(),
|
||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
|
||||
return std::make_shared<DataTypeString>();
|
||||
}
|
||||
|
||||
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t /*input_rows_count*/) const override
|
||||
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override
|
||||
{
|
||||
const IColumn * column = arguments[0].column.get();
|
||||
ColumnPtr res_column;
|
||||
|
||||
WhichDataType which(column->getDataType());
|
||||
if (which.isAggregateFunction())
|
||||
{
|
||||
auto to_string = FunctionFactory::instance().get("toString", context);
|
||||
const ColumnPtr col = to_string->build(arguments)->execute(arguments, result_type, input_rows_count);
|
||||
const auto * name_col = checkAndGetColumn<ColumnString>(col.get());
|
||||
tryExecuteString(name_col, res_column);
|
||||
return res_column;
|
||||
}
|
||||
|
||||
if (tryExecuteUInt<UInt8>(column, res_column) ||
|
||||
tryExecuteUInt<UInt16>(column, res_column) ||
|
||||
tryExecuteUInt<UInt32>(column, res_column) ||
|
||||
|
@ -33,3 +33,7 @@
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
2D000000000000000A
|
||||
001011010000000000000000000000000000000000000000000000000000000000001010
|
||||
|
@ -37,3 +37,9 @@ select bin(unbin('0')) == '00000000';
|
||||
select hex('') == bin('');
|
||||
select unhex('') == unbin('');
|
||||
select unhex('0') == unbin('0');
|
||||
|
||||
-- hex and bin support AggregateFunction
|
||||
select hex(sumState(number)) == hex(toString(sumState(number))) from numbers(10);
|
||||
select hex(avgState(number)) == hex(toString(avgState(number))) from numbers(99);
|
||||
select hex(avgState(number)) from numbers(10);
|
||||
select bin(avgState(number)) from numbers(10);
|
||||
|
Loading…
Reference in New Issue
Block a user