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

  1. groupArraySample(max_size[, seed])(x)

Parameters

  • max_size — Maximum size of the resulting array. UInt64.
  • seed — Seed for the random number generator. Optional. UInt64. Default value: 123456.
  • x — Argument (column name or expression).

Returned values

  • Array of randomly selected x arguments.

Type: Array.

Examples

Consider table colors:

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

Query with column name as argument:

  1. SELECT groupArraySample(3)(color) as newcolors FROM colors;

Result:

  1. ┌─newcolors──────────────────┐
  2. ['white','blue','green']
  3. └────────────────────────────┘

Query with column name and different seed:

  1. SELECT groupArraySample(3, 987654321)(color) as newcolors FROM colors;

Result:

  1. ┌─newcolors──────────────────┐
  2. ['red','orange','green']
  3. └────────────────────────────┘

Query with expression as argument:

  1. SELECT groupArraySample(3)(concat('light-', color)) as newcolors FROM colors;

Result:

  1. ┌─newcolors───────────────────────────────────┐
  2. ['light-blue','light-orange','light-green']
  3. └─────────────────────────────────────────────┘