SAMPLE_VALUE
All functions > BUSINESS_SIMULATIONS > SAMPLE_VALUE
Returns a value from the given array of values and proportions based on the given hashing key.
Syntax
SAMPLE_VALUE(hashing_key: VARCHAR, values: ARRAY<T>, proportions: ARRAY<NUMERIC>) → T
sql
Type Parameters:
T
: Any type
Arguments
Parameter | Type | Required | Description |
---|---|---|---|
hashing_key | VARCHAR | Yes | String value to hash (typically user ID or session ID) |
values | ARRAY<T> | Yes | Array of possible values to select from |
proportions | ARRAY<NUMERIC> | Yes | Array of relative weights for each value |
Returns
T - Deterministic value selected based on proportions
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