mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-18 05:32:52 +00:00
97f2a2213e
* Move some code outside dbms/src folder * Fix paths
47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#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;
|
|
|
|
Block temporary_block
|
|
{
|
|
arg,
|
|
{
|
|
DataTypeString().createColumnConst(arg.column->size(), type->getName()),
|
|
std::make_shared<DataTypeString>(),
|
|
""
|
|
},
|
|
{
|
|
nullptr,
|
|
type,
|
|
""
|
|
}
|
|
};
|
|
|
|
FunctionOverloadResolverPtr func_builder_cast = std::make_shared<FunctionOverloadResolverAdaptor>(CastOverloadResolver::createImpl());
|
|
|
|
ColumnsWithTypeAndName arguments{ temporary_block.getByPosition(0), temporary_block.getByPosition(1) };
|
|
auto func_cast = func_builder_cast->build(arguments);
|
|
|
|
func_cast->execute(temporary_block, {0, 1}, 2, arg.column->size());
|
|
return temporary_block.getByPosition(2).column;
|
|
}
|
|
|
|
ColumnPtr castColumn(const ColumnWithTypeAndName & arg, const DataTypePtr & type, const Context &)
|
|
{
|
|
return castColumn(arg, type);
|
|
}
|
|
|
|
}
|