Skip to content

Commit b16d37f

Browse files
authored
Merge 72f15bb into e44bcd8
2 parents e44bcd8 + 72f15bb commit b16d37f

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

ydb/library/yql/core/type_ann/type_ann_core.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12346,6 +12346,8 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
1234612346
Functions["ListFlatten"] = &ListFlattenWrapper;
1234712347
Functions["ListUniq"] = &ListUniqWrapper;
1234812348
Functions["ListUniqStable"] = &ListUniqStableWrapper;
12349+
Functions["ListTop"] = &ListTopSortWrapper;
12350+
Functions["ListTopSort"] = &ListTopSortWrapper;
1234912351

1235012352
Functions["ExpandMap"] = &ExpandMapWrapper;
1235112353
Functions["WideMap"] = &WideMapWrapper;

ydb/library/yql/core/type_ann/type_ann_list.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,36 @@ namespace {
14361436
return OptListWrapperImpl<3U>(input, output, ctx, "Sort");
14371437
}
14381438

1439+
IGraphTransformer::TStatus ListTopSortWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
1440+
TExprNode::TPtr outputPre = nullptr;
1441+
auto res = OptListWrapperImpl<2U, 3U>(input, outputPre, ctx, input->Content().Skip(4));
1442+
if (res != IGraphTransformer::TStatus::Repeat) {
1443+
return res;
1444+
}
1445+
TExprNode::TPtr sortLambda = nullptr;
1446+
if (outputPre->ChildrenSize() == 3) {
1447+
sortLambda = outputPre->ChildPtr(2);
1448+
} else {
1449+
sortLambda = ctx.Expr.Builder(input->Pos())
1450+
.Lambda()
1451+
.Param("item")
1452+
.Arg("item")
1453+
.Seal()
1454+
.Build();
1455+
}
1456+
output = ctx.Expr.Builder(input->Pos())
1457+
.Callable(outputPre->Content())
1458+
.Add(0, outputPre->ChildPtr(0))
1459+
.Add(1, outputPre->ChildPtr(1))
1460+
.Callable(2, "Bool")
1461+
.Atom(0, "true")
1462+
.Seal()
1463+
.Add(3, sortLambda)
1464+
.Seal()
1465+
.Build();
1466+
return res;
1467+
}
1468+
14391469
IGraphTransformer::TStatus ListExtractWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
14401470
return OptListWrapperImpl<2U>(input, output, ctx, "OrderedExtract");
14411471
}

ydb/library/yql/core/type_ann/type_ann_list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ namespace NTypeAnnImpl {
3737
IGraphTransformer::TStatus ListEnumerateWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
3838
IGraphTransformer::TStatus ListReverseWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
3939
IGraphTransformer::TStatus ListSortWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
40+
IGraphTransformer::TStatus ListTopWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
41+
IGraphTransformer::TStatus ListTopSortWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
4042
IGraphTransformer::TStatus ListExtractWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
4143
IGraphTransformer::TStatus ListCollectWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);
4244
IGraphTransformer::TStatus FoldMapWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx);

ydb/library/yql/sql/v1/builtin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,6 +2904,8 @@ struct TBuiltinFuncData {
29042904
{"listcollect", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("ListCollect", 1, 1) },
29052905
{"listnotnull", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("ListNotNull", 1, 1)},
29062906
{"listflatten", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("ListFlatten", 1, 1)},
2907+
{"listtop", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("ListTop", 2, 3)},
2908+
{"listtopsort", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("ListTopSort", 2, 3)},
29072909

29082910
// Dict builtins
29092911
{"dictlength", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("Length", 1, 1)},

0 commit comments

Comments
 (0)