2021-05-17 07:30:42 +00:00
|
|
|
#include <Functions/IFunction.h>
|
2020-02-01 19:41:35 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <IO/NullWriteBuffer.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-09-07 18:00:37 +00:00
|
|
|
namespace
|
|
|
|
{
|
2020-02-01 19:41:35 +00:00
|
|
|
|
2020-10-14 14:04:50 +00:00
|
|
|
/// Returns size on disk for *columns* (without taking into account compression).
|
2020-02-01 19:41:35 +00:00
|
|
|
class FunctionBlockSerializedSize : public IFunction
|
|
|
|
{
|
|
|
|
public:
|
2020-10-14 19:25:36 +00:00
|
|
|
static constexpr auto name = "blockSerializedSize";
|
2020-02-01 19:41:35 +00:00
|
|
|
|
2021-06-01 12:20:52 +00:00
|
|
|
static FunctionPtr create(ContextPtr)
|
2020-02-01 19:41:35 +00:00
|
|
|
{
|
|
|
|
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; }
|
2021-06-22 16:21:23 +00:00
|
|
|
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
|
2020-02-01 19:41:35 +00:00
|
|
|
|
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override
|
|
|
|
{
|
|
|
|
return std::make_shared<DataTypeUInt64>();
|
|
|
|
}
|
|
|
|
|
2020-11-17 13:24:45 +00:00
|
|
|
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
|
2020-02-01 19:41:35 +00:00
|
|
|
{
|
|
|
|
UInt64 size = 0;
|
|
|
|
|
2020-10-17 16:48:53 +00:00
|
|
|
for (const auto & arg : arguments)
|
|
|
|
size += columnsSerializedSizeOne(arg);
|
2020-02-01 19:41:35 +00:00
|
|
|
|
2020-10-17 16:48:53 +00:00
|
|
|
return DataTypeUInt64().createColumnConst(input_rows_count, size)->convertToFullColumnIfConst();
|
2020-02-01 19:41:35 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 14:04:50 +00:00
|
|
|
static UInt64 columnsSerializedSizeOne(const ColumnWithTypeAndName & elem)
|
2020-02-01 19:41:35 +00:00
|
|
|
{
|
|
|
|
ColumnPtr full_column = elem.column->convertToFullColumnIfConst();
|
|
|
|
|
2021-03-09 14:46:52 +00:00
|
|
|
ISerialization::SerializeBinaryBulkSettings settings;
|
2020-02-01 19:41:35 +00:00
|
|
|
NullWriteBuffer out;
|
|
|
|
|
2021-03-09 14:46:52 +00:00
|
|
|
settings.getter = [&out](ISerialization::SubstreamPath) -> WriteBuffer * { return &out; };
|
2020-02-01 19:41:35 +00:00
|
|
|
|
2021-03-09 14:46:52 +00:00
|
|
|
ISerialization::SerializeBinaryBulkStatePtr state;
|
2020-03-10 17:50:02 +00:00
|
|
|
|
2021-03-09 14:46:52 +00:00
|
|
|
auto serialization = elem.type->getDefaultSerialization();
|
|
|
|
|
2022-09-08 15:16:39 +00:00
|
|
|
serialization->serializeBinaryBulkStatePrefix(*full_column, settings, state);
|
2021-03-09 14:46:52 +00:00
|
|
|
serialization->serializeBinaryBulkWithMultipleStreams(*full_column,
|
2020-02-01 19:41:35 +00:00
|
|
|
0 /** offset */, 0 /** limit */,
|
|
|
|
settings, state);
|
2021-03-09 14:46:52 +00:00
|
|
|
serialization->serializeBinaryBulkStateSuffix(settings, state);
|
2020-02-01 19:41:35 +00:00
|
|
|
|
2023-06-01 17:00:47 +00:00
|
|
|
out.finalize();
|
2020-02-01 19:41:35 +00:00
|
|
|
return out.count();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
}
|
2020-02-01 19:41:35 +00:00
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(BlockSerializedSize)
|
2020-02-01 19:41:35 +00:00
|
|
|
{
|
|
|
|
factory.registerFunction<FunctionBlockSerializedSize>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|