|
@@ -1524,6 +1524,115 @@ namespace {
|
|
return OptListWrapperImpl<1U>(input, output, ctx, "Collect");
|
|
return OptListWrapperImpl<1U>(input, output, ctx, "Collect");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ IGraphTransformer::TStatus ListSampleWrapperCommon(const TExprNode::TPtr& input, TExprNode::TPtr& output, NUdf::EDataSlot probArgDataType, TContext& ctx) {
|
|
|
|
+ if (!EnsureMinMaxArgsCount(*input, 2, 3, ctx.Expr)) {
|
|
|
|
+ return IGraphTransformer::TStatus::Error;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (IsNull(input->Head())) {
|
|
|
|
+ output = input->HeadPtr();
|
|
|
|
+ return IGraphTransformer::TStatus::Repeat;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!EnsureComputable(input->Head(), ctx.Expr)) {
|
|
|
|
+ return IGraphTransformer::TStatus::Error;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ auto type = input->Head().GetTypeAnn();
|
|
|
|
+ if (type->GetKind() == ETypeAnnotationKind::Optional) {
|
|
|
|
+ type = type->Cast<TOptionalExprType>()->GetItemType();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (type->GetKind() != ETypeAnnotationKind::List && type->GetKind() != ETypeAnnotationKind::EmptyList) {
|
|
|
|
+ ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Head().Pos()), TStringBuilder()
|
|
|
|
+ << "Expected (empty) list or optional of (empty) list, but got: " << *input->Head().GetTypeAnn()));
|
|
|
|
+ return IGraphTransformer::TStatus::Error;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (type->GetKind() == ETypeAnnotationKind::EmptyList) {
|
|
|
|
+ output = input->HeadPtr();
|
|
|
|
+ return IGraphTransformer::TStatus::Repeat;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (IsNull(*input->Child(1))) {
|
|
|
|
+ output = input->HeadPtr();
|
|
|
|
+ return IGraphTransformer::TStatus::Repeat;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!EnsureSpecificDataType(*input->Child(1), probArgDataType, ctx.Expr, true)) {
|
|
|
|
+ return IGraphTransformer::TStatus::Error;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (input->ChildrenSize() == 2) {
|
|
|
|
+ auto children = input->ChildrenList();
|
|
|
|
+ children.push_back(ctx.Expr.NewCallable(input->Pos(), "Null", {}));
|
|
|
|
+ output = ctx.Expr.ChangeChildren(*input, std::move(children));
|
|
|
|
+ return IGraphTransformer::TStatus::Repeat;
|
|
|
|
+ }
|
|
|
|
+ YQL_ENSURE(input->ChildrenSize() == 3);
|
|
|
|
+
|
|
|
|
+ if (!EnsureComputable(*input->Child(2), ctx.Expr)) {
|
|
|
|
+ return IGraphTransformer::TStatus::Error;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ input->SetTypeAnn(input->Head().GetTypeAnn());
|
|
|
|
+ return IGraphTransformer::TStatus::Ok;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ IGraphTransformer::TStatus ListSampleWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
|
|
|
|
+ return ListSampleWrapperCommon(input, output, NUdf::EDataSlot::Double, ctx);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ IGraphTransformer::TStatus ListSampleNWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
|
|
|
|
+ return ListSampleWrapperCommon(input, output, NUdf::EDataSlot::Uint64, ctx);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ IGraphTransformer::TStatus ListShuffleWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
|
|
|
|
+ if (!EnsureMinMaxArgsCount(*input, 1, 2, ctx.Expr)) {
|
|
|
|
+ return IGraphTransformer::TStatus::Error;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (IsNull(input->Head())) {
|
|
|
|
+ output = input->HeadPtr();
|
|
|
|
+ return IGraphTransformer::TStatus::Repeat;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!EnsureComputable(input->Head(), ctx.Expr)) {
|
|
|
|
+ return IGraphTransformer::TStatus::Error;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ auto type = input->Head().GetTypeAnn();
|
|
|
|
+ if (type->GetKind() == ETypeAnnotationKind::Optional) {
|
|
|
|
+ type = type->Cast<TOptionalExprType>()->GetItemType();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (type->GetKind() != ETypeAnnotationKind::List && type->GetKind() != ETypeAnnotationKind::EmptyList) {
|
|
|
|
+ ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Head().Pos()), TStringBuilder()
|
|
|
|
+ << "Expected (empty) list or optional of (empty) list, but got: " << *input->Head().GetTypeAnn()));
|
|
|
|
+ return IGraphTransformer::TStatus::Error;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (type->GetKind() == ETypeAnnotationKind::EmptyList) {
|
|
|
|
+ output = input->HeadPtr();
|
|
|
|
+ return IGraphTransformer::TStatus::Repeat;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (input->ChildrenSize() == 1) {
|
|
|
|
+ auto children = input->ChildrenList();
|
|
|
|
+ children.push_back(ctx.Expr.NewCallable(input->Pos(), "Null", {}));
|
|
|
|
+ output = ctx.Expr.ChangeChildren(*input, std::move(children));
|
|
|
|
+ return IGraphTransformer::TStatus::Repeat;
|
|
|
|
+ }
|
|
|
|
+ YQL_ENSURE(input->ChildrenSize() == 2);
|
|
|
|
+
|
|
|
|
+ if (!EnsureComputable(*input->Child(1), ctx.Expr)) {
|
|
|
|
+ return IGraphTransformer::TStatus::Error;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ input->SetTypeAnn(input->Head().GetTypeAnn());
|
|
|
|
+ return IGraphTransformer::TStatus::Ok;
|
|
|
|
+ }
|
|
|
|
+
|
|
IGraphTransformer::TStatus OptListFold1WrapperImpl(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx, TExprNode::TPtr&& updateLambda) {
|
|
IGraphTransformer::TStatus OptListFold1WrapperImpl(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx, TExprNode::TPtr&& updateLambda) {
|
|
if (IsNull(input->Head())) {
|
|
if (IsNull(input->Head())) {
|
|
output = input->HeadPtr();
|
|
output = input->HeadPtr();
|