Skip to content

Commit 9f1bbc8

Browse files
authored
YQL-16218 fix SqlIn for tuples (#801)
YQL-16218 fix SqlIn for tuples
1 parent c288b66 commit 9f1bbc8

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

ydb/library/yql/core/peephole_opt/yql_opt_peephole_physical.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,15 +1813,34 @@ TExprNode::TPtr BuildDictOverList(TPositionHandle pos, const TExprNode::TPtr& co
18131813

18141814
TExprNode::TPtr BuildDictOverTuple(TExprNode::TPtr&& collection, const TTypeAnnotationNode*& dictKeyType, TExprContext& ctx)
18151815
{
1816-
if (!collection->GetTypeAnn()->Cast<TTupleExprType>()->GetSize()) {
1816+
const auto pos = collection->Pos();
1817+
const auto tupleType = collection->GetTypeAnn()->Cast<TTupleExprType>();
1818+
if (!tupleType->GetSize()) {
18171819
dictKeyType = nullptr;
18181820
return nullptr;
18191821
}
1822+
TTypeAnnotationNode::TListType types(tupleType->GetItems());
1823+
dictKeyType = CommonType(pos, types, ctx);
1824+
YQL_ENSURE(dictKeyType, "Uncompatible collection elements.");
18201825

1821-
dictKeyType = CommonTypeForChildren(*collection, ctx);
1822-
YQL_ENSURE(dictKeyType, "Uncompatible colllection elements.");
1823-
const auto pos = collection->Pos();
1824-
return ctx.NewCallable(pos, "DictFromKeys", {ExpandType(pos, *dictKeyType, ctx), std::move(collection)});
1826+
TExprNode::TPtr tuple;
1827+
if (collection->IsList()) {
1828+
tuple = collection;
1829+
} else {
1830+
TExprNode::TListType items;
1831+
items.reserve(tupleType->GetSize());
1832+
for (size_t i = 0; i != tupleType->GetSize(); ++i) {
1833+
items.push_back(
1834+
ctx.NewCallable(
1835+
pos,
1836+
"Nth",
1837+
{collection, ctx.NewAtom(pos, ui32(i))}
1838+
)
1839+
);
1840+
}
1841+
tuple = ctx.NewList(pos, std::move(items));
1842+
}
1843+
return ctx.NewCallable(pos, "DictFromKeys", {ExpandType(pos, *dictKeyType, ctx), std::move(tuple)});
18251844
}
18261845

18271846
TExprNode::TPtr ExpandSqlIn(const TExprNode::TPtr& input, TExprContext& ctx) {

0 commit comments

Comments
 (0)