1 | #include <Core/Field.h> |
2 | #include <Interpreters/castColumn.h> |
3 | #include <Interpreters/ExpressionActions.h> |
4 | #include <DataTypes/DataTypeString.h> |
5 | #include <Functions/IFunctionAdaptors.h> |
6 | #include <Functions/FunctionsConversion.h> |
7 | |
8 | |
9 | namespace DB |
10 | { |
11 | |
12 | ColumnPtr castColumn(const ColumnWithTypeAndName & arg, const DataTypePtr & type) |
13 | { |
14 | if (arg.type->equals(*type)) |
15 | return arg.column; |
16 | |
17 | Block temporary_block |
18 | { |
19 | arg, |
20 | { |
21 | DataTypeString().createColumnConst(arg.column->size(), type->getName()), |
22 | std::make_shared<DataTypeString>(), |
23 | "" |
24 | }, |
25 | { |
26 | nullptr, |
27 | type, |
28 | "" |
29 | } |
30 | }; |
31 | |
32 | FunctionOverloadResolverPtr func_builder_cast = std::make_shared<FunctionOverloadResolverAdaptor>(CastOverloadResolver::createImpl()); |
33 | |
34 | ColumnsWithTypeAndName arguments{ temporary_block.getByPosition(0), temporary_block.getByPosition(1) }; |
35 | auto func_cast = func_builder_cast->build(arguments); |
36 | |
37 | func_cast->execute(temporary_block, {0, 1}, 2, arg.column->size()); |
38 | return temporary_block.getByPosition(2).column; |
39 | } |
40 | |
41 | ColumnPtr castColumn(const ColumnWithTypeAndName & arg, const DataTypePtr & type, const Context &) |
42 | { |
43 | return castColumn(arg, type); |
44 | } |
45 | |
46 | } |
47 | |