2020-02-01 19:41:35 +00:00
|
|
|
#include <Functions/IFunctionImpl.h>
|
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <IO/NullWriteBuffer.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Returns size on disk for *block* (without taking into account compression).
|
|
|
|
class FunctionBlockSerializedSize : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static constexpr auto name = "blockSerializedSize";
|
|
|
|
|
|
|
|
static FunctionPtr create(const Context &)
|
|
|
|
{
|
|
|
|
return std::make_shared<FunctionBlockSerializedSize>();
|
|
|
|
}
|
|
|
|
|
|
|
|
String getName() const override { return name; }
|
|
|
|
bool useDefaultImplementationForNulls() const override { return false; }
|
|
|
|
size_t getNumberOfArguments() const override { return 0; }
|
|
|
|
bool isVariadic() const override { return true; }
|
|
|
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override
|
|
|
|
{
|
|
|
|
return std::make_shared<DataTypeUInt64>();
|
|
|
|
}
|
|
|
|
|
2020-07-21 13:58:07 +00:00
|
|
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) const override
|
2020-02-01 19:41:35 +00:00
|
|
|
{
|
|
|
|
UInt64 size = 0;
|
|
|
|
|
2020-03-09 03:38:43 +00:00
|
|
|
for (auto arg_pos : arguments)
|
|
|
|
size += blockSerializedSizeOne(block.getByPosition(arg_pos));
|
2020-02-01 19:41:35 +00:00
|
|
|
|
|
|
|
block.getByPosition(result).column = DataTypeUInt64().createColumnConst(
|
|
|
|
input_rows_count, size)->convertToFullColumnIfConst();
|
|
|
|
}
|
|
|
|
|
2020-03-18 00:57:00 +00:00
|
|
|
static UInt64 blockSerializedSizeOne(const ColumnWithTypeAndName & elem)
|
2020-02-01 19:41:35 +00:00
|
|
|
{
|
|
|
|
ColumnPtr full_column = elem.column->convertToFullColumnIfConst();
|
|
|
|
|
|
|
|
IDataType::SerializeBinaryBulkSettings settings;
|
|
|
|
NullWriteBuffer out;
|
|
|
|
|
|
|
|
settings.getter = [&out](IDataType::SubstreamPath) -> WriteBuffer * { return &out; };
|
|
|
|
|
|
|
|
IDataType::SerializeBinaryBulkStatePtr state;
|
2020-03-10 17:50:02 +00:00
|
|
|
|
|
|
|
elem.type->serializeBinaryBulkStatePrefix(settings, state);
|
2020-02-01 19:41:35 +00:00
|
|
|
elem.type->serializeBinaryBulkWithMultipleStreams(*full_column,
|
|
|
|
0 /** offset */, 0 /** limit */,
|
|
|
|
settings, state);
|
2020-03-10 17:50:02 +00:00
|
|
|
elem.type->serializeBinaryBulkStateSuffix(settings, state);
|
2020-02-01 19:41:35 +00:00
|
|
|
|
|
|
|
return out.count();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void registerFunctionBlockSerializedSize(FunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionBlockSerializedSize>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|