1#include <Functions/IFunctionImpl.h>
2#include <Functions/FunctionFactory.h>
3#include <DataTypes/DataTypeString.h>
4#include <Core/Field.h>
5
6
7namespace DB
8{
9
10/// Dump the structure of type and column.
11class FunctionDumpColumnStructure : public IFunction
12{
13public:
14 static constexpr auto name = "dumpColumnStructure";
15 static FunctionPtr create(const Context &)
16 {
17 return std::make_shared<FunctionDumpColumnStructure>();
18 }
19
20 String getName() const override
21 {
22 return name;
23 }
24
25 bool useDefaultImplementationForNulls() const override { return false; }
26
27 size_t getNumberOfArguments() const override
28 {
29 return 1;
30 }
31
32 DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override
33 {
34 return std::make_shared<DataTypeString>();
35 }
36
37 void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) override
38 {
39 const auto & elem = block.getByPosition(arguments[0]);
40
41 /// Note that the result is not a constant, because it contains block size.
42
43 block.getByPosition(result).column
44 = DataTypeString().createColumnConst(input_rows_count,
45 elem.type->getName() + ", " + elem.column->dumpStructure())->convertToFullColumnIfConst();
46 }
47};
48
49
50void registerFunctionDumpColumnStructure(FunctionFactory & factory)
51{
52 factory.registerFunction<FunctionDumpColumnStructure>();
53}
54
55}
56