Skip to content

Commit 8b8059d

Browse files
loochekanton-bobkov
andauthored
Documentation for ListSample/ListSampleN/ListShuffle (#11802)
Co-authored-by: anton-bobkov <anton-bobkov@yandex-team.ru>
1 parent 2f89980 commit 8b8059d

File tree

2 files changed

+96
-0
lines changed
  • ydb/docs
    • en/core/yql/reference/yql-core/builtins/_includes
    • ru/core/yql/reference/yql-core/builtins/_includes

2 files changed

+96
-0
lines changed

ydb/docs/en/core/yql/reference/yql-core/builtins/_includes/list.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,52 @@ SELECT ListTake(list_column, 3) FROM my_table;
228228

229229
{% endif %}
230230

231+
## ListSample and ListSampleN {#listsample}
232+
233+
Returns a sample without replacement from the list.
234+
235+
- `ListSample` chooses elements independently with the specified probability.
236+
237+
- `ListSampleN` chooses a sample of the specified size (if the length of the list is less than the sample size, returns the original list).
238+
239+
If the probability/sample size is NULL, returns the original list.
240+
241+
An optional argument is used to control randomness, see [documentation for `Random`](./basic/random.md).
242+
243+
### Examples
244+
245+
```yql
246+
ListSample(List<T>, Double?[, U])->List<T>
247+
ListSample(List<T>?, Double?[, U])->List<T>?
248+
249+
ListSampleN(List<T>, Uint64?[, U])->List<T>
250+
ListSampleN(List<T>?, Uint64?[, U])->List<T>?
251+
```
252+
253+
```yql
254+
$list = AsList(1, 2, 3, 4, 5);
255+
256+
SELECT ListSample($list, 0.5); -- [1, 2, 5]
257+
SELECT ListSampleN($list, 2); -- [4, 2]
258+
```
259+
260+
## ListShuffle {#listshuffle}
261+
262+
Returns a shuffled copy of the list. An optional argument is used to control randomness, see [documentation for `Random`](./basic/random.md).
263+
264+
### Examples
265+
266+
```yql
267+
ListShuffle(List<T>[, U])->List<T>
268+
ListShuffle(List<T>?[, U])->List<T>?
269+
```
270+
271+
```yql
272+
$list = AsList(1, 2, 3, 4, 5);
273+
274+
SELECT ListShuffle($list); -- [1, 3, 5, 2, 4]
275+
```
276+
231277
## ListIndexOf {#listindexof}
232278

233279
Searches the list for an element with the specified value and returns its index at the first occurrence. Indexes count from 0. If such element is missing, it returns `NULL`.

ydb/docs/ru/core/yql/reference/yql-core/builtins/_includes/list.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,56 @@ ListTake(List<T>, Uint64)->List<T>
363363
ListTake(List<T>?, Uint64)->List<T>?
364364
```
365365

366+
## ListSample и ListSampleN {#listsample}
367+
368+
Возвращает выборку без повторений из элементов списка.
369+
370+
- `ListSample` выбирает каждый элемент независимо с заданной вероятностью.
371+
372+
- `ListSampleN` выбирает фиксированное количество элементов (если длина списка меньше размера выборки, то вернется исходный список).
373+
374+
Если вероятность/размер выборки является NULL, то вернется исходный список.
375+
376+
Дополнительный аргумент используется для управления случайностью, подробнее см. [документацию к `Random`](./basic/random.md).
377+
378+
### Примеры
379+
380+
```yql
381+
$list = AsList(1, 2, 3, 4, 5);
382+
383+
SELECT ListSample($list, 0.5); -- [1, 2, 5]
384+
SELECT ListSampleN($list, 2); -- [4, 2]
385+
```
386+
387+
### Сигнатура
388+
389+
```yql
390+
ListSample(List<T>, Double?[, U])->List<T>
391+
ListSample(List<T>?, Double?[, U])->List<T>?
392+
393+
ListSampleN(List<T>, Uint64?[, U])->List<T>
394+
ListSampleN(List<T>?, Uint64?[, U])->List<T>?
395+
```
396+
397+
## ListShuffle {#listshuffle}
398+
399+
Возвращает копию списка с элементами, перестановленными в случайном порядке. Дополнительный аргумент используется для управления случайностью, подробнее см. [документацию к `Random`](./basic/random.md).
400+
401+
### Примеры
402+
403+
```yql
404+
$list = AsList(1, 2, 3, 4, 5);
405+
406+
SELECT ListShuffle($list); -- [1, 3, 5, 2, 4]
407+
```
408+
409+
### Сигнатура
410+
411+
```yql
412+
ListShuffle(List<T>[, U])->List<T>
413+
ListShuffle(List<T>?[, U])->List<T>?
414+
```
415+
366416
## ListIndexOf {#listindexof}
367417

368418
Ищет элемент с указанным значением в списке и при первом обнаружении возвращает его индекс. Отсчет индексов начинается с 0, а в случае отсутствия элемента возвращается `NULL`.

0 commit comments

Comments
 (0)