ClickHouse/docs/en/sql-reference/aggregate-functions/reference/grouparraysample.md
olgarev 7a8b1f064b
DOCSUP-928: Documented the groupArraySample function (#13791)
* En docs for groupArraySample function.

* Bug fixed.

* Update docs/en/sql-reference/aggregate-functions/reference/grouparraysample.md

Co-authored-by: Olga Revyakina <revolg@yandex-team.ru>
Co-authored-by: Ivan Blinkov <github@blinkov.ru>
2020-08-17 11:00:24 +03:00

1.9 KiB

toc_priority
114

groupArraySample

Creates an array of sample argument values. The size of the resulting array is limited to max_size elements. Argument values are selected and added to the array randomly.

Syntax

groupArraySample(max_size)(x)

or

groupArraySample(max_size, seed)(x)

Parameters

  • max_size — Maximum size of the resulting array. Positive UInt64.
  • seed — Seed for the random number generator. Optional, can be omitted. Positive UInt64. Default value: 123456.
  • x — Argument name. String.

Returned values

  • Array of randomly selected x arguments.

Type: Array.

Examples

Consider table colors:

┌─id─┬─color──┐
│  1 │ red    │
│  2 │ blue   │
│  3 │ green  │
│  4 │ white  │
│  5 │ orange │
└────┴────────┘

Select id-s query:

SELECT groupArraySample(3)(id) FROM colors;

Result:

┌─groupArraySample(3)(id)─┐
│ [1,2,4]                 │
└─────────────────────────┘

Select color-s query:

SELECT groupArraySample(3)(color) FROM colors;

Result:

┌─groupArraySample(3)(color)─┐
│ ['white','blue','green']   │
└────────────────────────────┘

Select color-s query with different seed:

SELECT groupArraySample(3, 987654321)(color) FROM colors;

Result:

┌─groupArraySample(3, 987654321)(color)─┐
│ ['red','orange','green']              │
└───────────────────────────────────────┘