SAMPLE_VALUE(...)

All functions > BUSINESS > SAMPLE_VALUE(...)

Returns a value from the given array of values and proportions based on the given hashing key.

Signatures

Returns: Deterministic value selected based on proportions

SAMPLE_VALUE(hashing_key: VARCHAR, values: ARRAY<T>, proportions: ARRAY<NUMERIC>) → T
sql
ParameterTypeRequiredDescription
hashing_keyVARCHARYesString value to hash (typically user ID or session ID)
valuesARRAY<T>YesArray of possible values to select from
proportionsARRAY<NUMERIC>YesArray of relative weights for each value

Notes

  • Deterministic - same key always produces same value
  • Selects value based on weighted proportions
  • Proportions are relative weights (don't need to sum to 1)
  • Values and proportions arrays must have same length
  • Uses HASH01 internally for stable assignment
  • Useful for weighted A/B/C testing, variant assignment
  • Common for multi-armed bandit experiments

Examples

FeatureQL
SELECT
    f1 := SAMPLE_VALUE('k', ARRAY['a', 'b'], ARRAY[1E0, 2E0]) -- Deterministic pick from weighted values for a fixed key
;
Result
f1 VARCHAR
b

Last update at: 2026/05/26 17:22:09