2019-10-04 17:46:36 +00:00
|
|
|
#include <Core/Field.h>
|
2017-12-08 03:52:33 +00:00
|
|
|
#include <Interpreters/castColumn.h>
|
|
|
|
#include <Interpreters/ExpressionActions.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
2019-12-25 19:17:41 +00:00
|
|
|
#include <Functions/IFunctionAdaptors.h>
|
|
|
|
#include <Functions/FunctionsConversion.h>
|
2017-12-08 03:52:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-12-25 19:17:41 +00:00
|
|
|
ColumnPtr castColumn(const ColumnWithTypeAndName & arg, const DataTypePtr & type)
|
2017-12-08 03:52:33 +00:00
|
|
|
{
|
2018-02-15 18:54:12 +00:00
|
|
|
if (arg.type->equals(*type))
|
|
|
|
return arg.column;
|
|
|
|
|
2017-12-08 03:52:33 +00:00
|
|
|
Block temporary_block
|
|
|
|
{
|
|
|
|
arg,
|
|
|
|
{
|
2017-12-10 22:44:04 +00:00
|
|
|
DataTypeString().createColumnConst(arg.column->size(), type->getName()),
|
2017-12-08 03:52:33 +00:00
|
|
|
std::make_shared<DataTypeString>(),
|
|
|
|
""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nullptr,
|
|
|
|
type,
|
|
|
|
""
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-25 19:17:41 +00:00
|
|
|
FunctionOverloadResolverPtr func_builder_cast = std::make_shared<FunctionOverloadResolverAdaptor>(CastOverloadResolver::createImpl());
|
2017-12-08 03:52:33 +00:00
|
|
|
|
2018-02-02 08:33:36 +00:00
|
|
|
ColumnsWithTypeAndName arguments{ temporary_block.getByPosition(0), temporary_block.getByPosition(1) };
|
|
|
|
auto func_cast = func_builder_cast->build(arguments);
|
2017-12-08 03:52:33 +00:00
|
|
|
|
2018-04-24 07:16:39 +00:00
|
|
|
func_cast->execute(temporary_block, {0, 1}, 2, arg.column->size());
|
2017-12-08 03:52:33 +00:00
|
|
|
return temporary_block.getByPosition(2).column;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|