2021-06-22 16:21:23 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/IFunction.h>
|
2021-08-13 08:18:34 +00:00
|
|
|
#include <Core/Field.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
2023-09-28 12:23:13 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2018-09-08 22:04:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-09-07 18:00:37 +00:00
|
|
|
namespace
|
|
|
|
{
|
2018-09-08 22:04:39 +00:00
|
|
|
|
|
|
|
/** toTypeName(x) - get the type name
|
|
|
|
* Returns name of IDataType instance (name of data type).
|
|
|
|
*/
|
2021-05-22 12:49:21 +00:00
|
|
|
class FunctionToTypeName : public IFunction
|
2018-09-08 22:04:39 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-09-29 03:35:24 +00:00
|
|
|
explicit FunctionToTypeName(bool print_pretty_type_names_) : print_pretty_type_names(print_pretty_type_names_)
|
2023-09-28 12:23:13 +00:00
|
|
|
{
|
|
|
|
}
|
2019-08-19 17:48:19 +00:00
|
|
|
|
2021-05-22 12:49:21 +00:00
|
|
|
static constexpr auto name = "toTypeName";
|
2018-09-08 22:04:39 +00:00
|
|
|
|
2023-09-28 12:23:13 +00:00
|
|
|
static FunctionPtr create(ContextPtr context)
|
2018-09-08 22:04:39 +00:00
|
|
|
{
|
2023-09-28 12:23:13 +00:00
|
|
|
return std::make_shared<FunctionToTypeName>(context->getSettingsRef().print_pretty_type_names);
|
2018-09-08 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2021-05-22 12:49:21 +00:00
|
|
|
String getName() const override
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
2019-08-19 17:48:19 +00:00
|
|
|
|
2021-05-22 12:49:21 +00:00
|
|
|
bool useDefaultImplementationForNulls() const override { return false; }
|
2021-06-07 10:55:55 +00:00
|
|
|
|
2022-05-12 15:15:31 +00:00
|
|
|
bool useDefaultImplementationForNothing() const override { return false; }
|
|
|
|
|
2021-06-07 10:55:55 +00:00
|
|
|
|
2021-06-22 16:21:23 +00:00
|
|
|
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
|
2019-10-10 14:38:08 +00:00
|
|
|
|
2021-05-22 12:49:21 +00:00
|
|
|
bool useDefaultImplementationForLowCardinalityColumns() const override { return false; }
|
2019-08-19 17:48:19 +00:00
|
|
|
|
2021-05-22 12:49:21 +00:00
|
|
|
size_t getNumberOfArguments() const override
|
2018-09-08 22:04:39 +00:00
|
|
|
{
|
2021-05-22 12:49:21 +00:00
|
|
|
return 1;
|
2018-09-08 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2021-05-22 12:49:21 +00:00
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override
|
2018-09-08 22:04:39 +00:00
|
|
|
{
|
2021-05-22 12:49:21 +00:00
|
|
|
return std::make_shared<DataTypeString>();
|
2018-09-08 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2021-05-22 12:49:21 +00:00
|
|
|
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override
|
2018-09-08 22:04:39 +00:00
|
|
|
{
|
2023-09-28 12:23:13 +00:00
|
|
|
return DataTypeString().createColumnConst(input_rows_count, print_pretty_type_names ? arguments[0].type->getPrettyName() : arguments[0].type->getName());
|
2021-05-22 12:49:21 +00:00
|
|
|
}
|
2019-08-19 18:34:12 +00:00
|
|
|
|
2021-05-24 11:25:02 +00:00
|
|
|
ColumnPtr getConstantResultForNonConstArguments(const ColumnsWithTypeAndName & arguments, const DataTypePtr &) const override
|
2021-05-22 12:49:21 +00:00
|
|
|
{
|
2023-09-28 12:23:13 +00:00
|
|
|
return DataTypeString().createColumnConst(1, print_pretty_type_names ? arguments[0].type->getPrettyName() : arguments[0].type->getName());
|
2018-09-08 22:04:39 +00:00
|
|
|
}
|
2019-08-20 08:36:10 +00:00
|
|
|
|
2019-10-02 17:51:00 +00:00
|
|
|
ColumnNumbers getArgumentsThatDontImplyNullableReturnType(size_t /*number_of_arguments*/) const override { return {0}; }
|
2023-09-28 12:23:13 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool print_pretty_type_names;
|
2018-09-08 22:04:39 +00:00
|
|
|
};
|
|
|
|
|
2020-09-07 18:00:37 +00:00
|
|
|
}
|
2018-09-08 22:04:39 +00:00
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(ToTypeName)
|
2018-09-08 22:04:39 +00:00
|
|
|
{
|
2021-05-22 12:49:21 +00:00
|
|
|
factory.registerFunction<FunctionToTypeName>();
|
2018-09-08 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|