mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Fixed element types for explicit set in IN function. [#CLICKHOUSE-3730]
This commit is contained in:
parent
651bac519c
commit
e6adcfaad5
@ -755,7 +755,7 @@ public:
|
|||||||
tuple = typeid_cast<const ColumnTuple *>(materialized_tuple.get());
|
tuple = typeid_cast<const ColumnTuple *>(materialized_tuple.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tuple)
|
if (tuple && type_tuple->getElements().size() != 1)
|
||||||
{
|
{
|
||||||
const Columns & tuple_columns = tuple->getColumns();
|
const Columns & tuple_columns = tuple->getColumns();
|
||||||
const DataTypes & tuple_types = type_tuple->getElements();
|
const DataTypes & tuple_types = type_tuple->getElements();
|
||||||
|
@ -1649,7 +1649,23 @@ void ExpressionAnalyzer::makeExplicitSet(const ASTFunction * node, const Block &
|
|||||||
|
|
||||||
const ASTPtr & left_arg = args.children.at(0);
|
const ASTPtr & left_arg = args.children.at(0);
|
||||||
const ASTPtr & right_arg = args.children.at(1);
|
const ASTPtr & right_arg = args.children.at(1);
|
||||||
|
|
||||||
|
auto getTupleTypeFromAst = [this](const ASTPtr & node) -> DataTypePtr
|
||||||
|
{
|
||||||
|
auto ast_function = typeid_cast<const ASTFunction *>(node.get());
|
||||||
|
if (ast_function && ast_function->name == "tuple" && !ast_function->arguments->children.empty())
|
||||||
|
{
|
||||||
|
/// Won't parse all values of outer tuple.
|
||||||
|
auto element = ast_function->arguments->children.at(0);
|
||||||
|
std::pair<Field, DataTypePtr> value_raw = evaluateConstantExpression(element, context);
|
||||||
|
return std::make_shared<DataTypeTuple>(DataTypes({value_raw.second}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return evaluateConstantExpression(node, context).second;
|
||||||
|
};
|
||||||
|
|
||||||
const DataTypePtr & left_arg_type = sample_block.getByName(left_arg->getColumnName()).type;
|
const DataTypePtr & left_arg_type = sample_block.getByName(left_arg->getColumnName()).type;
|
||||||
|
const DataTypePtr & right_arg_type = getTupleTypeFromAst(right_arg);
|
||||||
|
|
||||||
std::function<size_t(const DataTypePtr &)> getTupleDepth;
|
std::function<size_t(const DataTypePtr &)> getTupleDepth;
|
||||||
getTupleDepth = [&getTupleDepth](const DataTypePtr & type) -> size_t
|
getTupleDepth = [&getTupleDepth](const DataTypePtr & type) -> size_t
|
||||||
@ -1660,35 +1676,15 @@ void ExpressionAnalyzer::makeExplicitSet(const ASTFunction * node, const Block &
|
|||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto getTupleDepthFromAst = [&getTupleDepth](const ASTPtr & node) -> size_t
|
|
||||||
{
|
|
||||||
size_t depth = 0;
|
|
||||||
ASTPtr element = node;
|
|
||||||
|
|
||||||
auto ast_function = typeid_cast<const ASTFunction *>(node.get());
|
|
||||||
if (ast_function && ast_function->name == "tuple" && !ast_function->arguments->children.empty())
|
|
||||||
{
|
|
||||||
++depth;
|
|
||||||
element = ast_function->arguments->children.at(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::pair<Field, DataTypePtr> value_raw = evaluateConstantExpression(element, context);
|
|
||||||
return depth + getTupleDepth(value_raw.second);
|
|
||||||
};
|
|
||||||
|
|
||||||
size_t left_tuple_depth = getTupleDepth(left_arg_type);
|
size_t left_tuple_depth = getTupleDepth(left_arg_type);
|
||||||
size_t right_tuple_depth = getTupleDepthFromAst(right_arg);
|
size_t right_tuple_depth = getTupleDepth(right_arg_type);
|
||||||
|
|
||||||
DataTypes set_element_types;
|
DataTypes set_element_types = {left_arg_type};
|
||||||
ASTPtr elements_ast = nullptr;
|
auto left_tuple_type = typeid_cast<const DataTypeTuple *>(left_arg_type.get());
|
||||||
|
if (left_tuple_type && left_tuple_type->getElements().size() != 1)
|
||||||
if (left_tuple_depth > 0)
|
|
||||||
{
|
|
||||||
auto left_tuple_type = static_cast<const DataTypeTuple *>(left_arg_type.get());
|
|
||||||
set_element_types = left_tuple_type->getElements();
|
set_element_types = left_tuple_type->getElements();
|
||||||
}
|
|
||||||
else
|
ASTPtr elements_ast = nullptr;
|
||||||
set_element_types.push_back(left_arg_type);
|
|
||||||
|
|
||||||
/// 1 in 1; (1, 2) in (1, 2); identity(tuple(tuple(tuple(1)))) in tuple(tuple(tuple(1))); etc.
|
/// 1 in 1; (1, 2) in (1, 2); identity(tuple(tuple(tuple(1)))) in tuple(tuple(tuple(1))); etc.
|
||||||
if (left_tuple_depth == right_tuple_depth)
|
if (left_tuple_depth == right_tuple_depth)
|
||||||
|
Loading…
Reference in New Issue
Block a user