2022-03-17 07:35:35 +00:00
|
|
|
#include <Functions/IFunction.h>
|
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypeArray.h>
|
|
|
|
#include <DataTypes/DataTypeFactory.h>
|
|
|
|
#include <DataTypes/Serializations/ISerialization.h>
|
|
|
|
#include <Core/Field.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
#include <Functions/FunctionHelpers.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Enumerate stream paths of data type.
|
2022-03-25 06:51:59 +00:00
|
|
|
class FunctionGetTypeSerializationStreams : public IFunction
|
2022-03-17 07:35:35 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-03-25 06:51:59 +00:00
|
|
|
static constexpr auto name = "getTypeSerializationStreams";
|
2022-03-17 07:35:35 +00:00
|
|
|
static FunctionPtr create(ContextPtr)
|
|
|
|
{
|
2022-03-25 06:51:59 +00:00
|
|
|
return std::make_shared<FunctionGetTypeSerializationStreams>();
|
2022-03-17 07:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String getName() const override
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
|
|
|
|
|
|
|
|
size_t getNumberOfArguments() const override
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-03-21 04:49:05 +00:00
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes &) const override
|
2022-03-17 07:35:35 +00:00
|
|
|
{
|
|
|
|
return std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>());
|
|
|
|
}
|
|
|
|
|
|
|
|
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
|
|
|
|
{
|
2022-03-21 04:49:05 +00:00
|
|
|
auto type = getType(arguments[0]);
|
2022-03-17 07:35:35 +00:00
|
|
|
|
|
|
|
SerializationPtr serialization = type->getDefaultSerialization();
|
|
|
|
auto col_res = ColumnArray::create(ColumnString::create());
|
|
|
|
ColumnString & col_res_strings = typeid_cast<ColumnString &>(col_res->getData());
|
|
|
|
ColumnVectorHelper::Offsets & col_res_offsets = typeid_cast<ColumnArray::Offsets &>(col_res->getOffsets());
|
|
|
|
serialization->enumerateStreams([&](const ISerialization::SubstreamPath & substream_path)
|
|
|
|
{
|
|
|
|
col_res_strings.insert(substream_path.toString());
|
|
|
|
});
|
|
|
|
col_res_offsets.push_back(col_res_strings.size());
|
|
|
|
return ColumnConst::create(std::move(col_res), input_rows_count);
|
|
|
|
}
|
2022-03-21 04:49:05 +00:00
|
|
|
|
|
|
|
private:
|
2022-03-21 06:19:54 +00:00
|
|
|
static DataTypePtr getType(const ColumnWithTypeAndName & argument)
|
2022-03-21 04:49:05 +00:00
|
|
|
{
|
|
|
|
const IColumn * arg_column = argument.column.get();
|
|
|
|
const ColumnString * arg_string = checkAndGetColumnConstData<ColumnString>(arg_column);
|
|
|
|
if (!arg_string)
|
|
|
|
return argument.type;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
DataTypePtr type = DataTypeFactory::instance().get(arg_string->getDataAt(0).toString());
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
catch (const DB::Exception &)
|
|
|
|
{
|
|
|
|
return argument.type;
|
|
|
|
}
|
|
|
|
}
|
2022-03-17 07:35:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(GetTypeSerializationStreams)
|
2022-03-17 07:35:35 +00:00
|
|
|
{
|
2022-03-25 06:51:59 +00:00
|
|
|
factory.registerFunction<FunctionGetTypeSerializationStreams>();
|
2022-03-17 07:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|