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/// Returns name of IColumn instance.
11class FunctionToColumnTypeName : public IFunction
12{
13public:
14 static constexpr auto name = "toColumnTypeName";
15 static FunctionPtr create(const Context &)
16 {
17 return std::make_shared<FunctionToColumnTypeName>();
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 block.getByPosition(result).column
40 = DataTypeString().createColumnConst(input_rows_count, block.getByPosition(arguments[0]).column->getName());
41 }
42
43 ColumnPtr getResultIfAlwaysReturnsConstantAndHasArguments(const Block & block, const ColumnNumbers & arguments) const override
44 {
45 return DataTypeString().createColumnConst(1, block.getByPosition(arguments[0]).type->createColumn()->getName());
46 }
47};
48
49
50void registerFunctionToColumnTypeName(FunctionFactory & factory)
51{
52 factory.registerFunction<FunctionToColumnTypeName>();
53}
54
55}
56