ClickHouse/src/Interpreters/castColumn.cpp

38 lines
1007 B
C++
Raw Normal View History

2019-10-04 17:46:36 +00:00
#include <Core/Field.h>
#include <Interpreters/castColumn.h>
#include <Interpreters/ExpressionActions.h>
#include <DataTypes/DataTypeString.h>
#include <Functions/IFunctionAdaptors.h>
#include <Functions/FunctionsConversion.h>
namespace DB
{
ColumnPtr castColumn(const ColumnWithTypeAndName & arg, const DataTypePtr & type)
{
if (arg.type->equals(*type))
return arg.column;
ColumnsWithTypeAndName arguments
{
arg,
{
2017-12-10 22:44:04 +00:00
DataTypeString().createColumnConst(arg.column->size(), type->getName()),
std::make_shared<DataTypeString>(),
""
}
};
2020-06-18 10:18:28 +00:00
FunctionOverloadResolverPtr func_builder_cast =
std::make_shared<FunctionOverloadResolverAdaptor>(CastOverloadResolver::createImpl(false));
2018-02-02 08:33:36 +00:00
auto func_cast = func_builder_cast->build(arguments);
arguments.emplace_back(ColumnWithTypeAndName{nullptr, type, ""});
func_cast->execute(arguments, {0, 1}, 2, arg.column->size());
return arguments[2].column;
}
}