@@ -1524,6 +1524,115 @@ namespace {
15241524 return OptListWrapperImpl<1U >(input, output, ctx, " Collect" );
15251525 }
15261526
1527+ IGraphTransformer::TStatus ListSampleWrapperCommon (const TExprNode::TPtr& input, TExprNode::TPtr& output, NUdf::EDataSlot probArgDataType, TContext& ctx) {
1528+ if (!EnsureMinMaxArgsCount (*input, 2 , 3 , ctx.Expr )) {
1529+ return IGraphTransformer::TStatus::Error;
1530+ }
1531+
1532+ if (IsNull (input->Head ())) {
1533+ output = input->HeadPtr ();
1534+ return IGraphTransformer::TStatus::Repeat;
1535+ }
1536+
1537+ if (!EnsureComputable (input->Head (), ctx.Expr )) {
1538+ return IGraphTransformer::TStatus::Error;
1539+ }
1540+
1541+ auto type = input->Head ().GetTypeAnn ();
1542+ if (type->GetKind () == ETypeAnnotationKind::Optional) {
1543+ type = type->Cast <TOptionalExprType>()->GetItemType ();
1544+ }
1545+
1546+ if (type->GetKind () != ETypeAnnotationKind::List && type->GetKind () != ETypeAnnotationKind::EmptyList) {
1547+ ctx.Expr .AddError (TIssue (ctx.Expr .GetPosition (input->Head ().Pos ()), TStringBuilder ()
1548+ << " Expected (empty) list or optional of (empty) list, but got: " << *input->Head ().GetTypeAnn ()));
1549+ return IGraphTransformer::TStatus::Error;
1550+ }
1551+
1552+ if (type->GetKind () == ETypeAnnotationKind::EmptyList) {
1553+ output = input->HeadPtr ();
1554+ return IGraphTransformer::TStatus::Repeat;
1555+ }
1556+
1557+ if (IsNull (*input->Child (1 ))) {
1558+ output = input->HeadPtr ();
1559+ return IGraphTransformer::TStatus::Repeat;
1560+ }
1561+
1562+ if (!EnsureSpecificDataType (*input->Child (1 ), probArgDataType, ctx.Expr , true )) {
1563+ return IGraphTransformer::TStatus::Error;
1564+ }
1565+
1566+ if (input->ChildrenSize () == 2 ) {
1567+ auto children = input->ChildrenList ();
1568+ children.push_back (ctx.Expr .NewCallable (input->Pos (), " Null" , {}));
1569+ output = ctx.Expr .ChangeChildren (*input, std::move (children));
1570+ return IGraphTransformer::TStatus::Repeat;
1571+ }
1572+ YQL_ENSURE (input->ChildrenSize () == 3 );
1573+
1574+ if (!EnsureComputable (*input->Child (2 ), ctx.Expr )) {
1575+ return IGraphTransformer::TStatus::Error;
1576+ }
1577+
1578+ input->SetTypeAnn (input->Head ().GetTypeAnn ());
1579+ return IGraphTransformer::TStatus::Ok;
1580+ }
1581+
1582+ IGraphTransformer::TStatus ListSampleWrapper (const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
1583+ return ListSampleWrapperCommon (input, output, NUdf::EDataSlot::Double, ctx);
1584+ }
1585+
1586+ IGraphTransformer::TStatus ListSampleNWrapper (const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
1587+ return ListSampleWrapperCommon (input, output, NUdf::EDataSlot::Uint64, ctx);
1588+ }
1589+
1590+ IGraphTransformer::TStatus ListShuffleWrapper (const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) {
1591+ if (!EnsureMinMaxArgsCount (*input, 1 , 2 , ctx.Expr )) {
1592+ return IGraphTransformer::TStatus::Error;
1593+ }
1594+
1595+ if (IsNull (input->Head ())) {
1596+ output = input->HeadPtr ();
1597+ return IGraphTransformer::TStatus::Repeat;
1598+ }
1599+
1600+ if (!EnsureComputable (input->Head (), ctx.Expr )) {
1601+ return IGraphTransformer::TStatus::Error;
1602+ }
1603+
1604+ auto type = input->Head ().GetTypeAnn ();
1605+ if (type->GetKind () == ETypeAnnotationKind::Optional) {
1606+ type = type->Cast <TOptionalExprType>()->GetItemType ();
1607+ }
1608+
1609+ if (type->GetKind () != ETypeAnnotationKind::List && type->GetKind () != ETypeAnnotationKind::EmptyList) {
1610+ ctx.Expr .AddError (TIssue (ctx.Expr .GetPosition (input->Head ().Pos ()), TStringBuilder ()
1611+ << " Expected (empty) list or optional of (empty) list, but got: " << *input->Head ().GetTypeAnn ()));
1612+ return IGraphTransformer::TStatus::Error;
1613+ }
1614+
1615+ if (type->GetKind () == ETypeAnnotationKind::EmptyList) {
1616+ output = input->HeadPtr ();
1617+ return IGraphTransformer::TStatus::Repeat;
1618+ }
1619+
1620+ if (input->ChildrenSize () == 1 ) {
1621+ auto children = input->ChildrenList ();
1622+ children.push_back (ctx.Expr .NewCallable (input->Pos (), " Null" , {}));
1623+ output = ctx.Expr .ChangeChildren (*input, std::move (children));
1624+ return IGraphTransformer::TStatus::Repeat;
1625+ }
1626+ YQL_ENSURE (input->ChildrenSize () == 2 );
1627+
1628+ if (!EnsureComputable (*input->Child (1 ), ctx.Expr )) {
1629+ return IGraphTransformer::TStatus::Error;
1630+ }
1631+
1632+ input->SetTypeAnn (input->Head ().GetTypeAnn ());
1633+ return IGraphTransformer::TStatus::Ok;
1634+ }
1635+
15271636 IGraphTransformer::TStatus OptListFold1WrapperImpl (const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx, TExprNode::TPtr&& updateLambda) {
15281637 if (IsNull (input->Head ())) {
15291638 output = input->HeadPtr ();
0 commit comments