SAMPLE_GEOMETRIC()

All functions > BUSINESS > SAMPLE_GEOMETRIC()

Returns the number of trials until first success, drawn from a geometric distribution, based on the given hashing key.

Signatures

Returns: Deterministic positive integer (>= 1) representing trial count

SAMPLE_GEOMETRIC(hashing_key: VARCHAR, probability: DOUBLE) → BIGINT
sql
ParameterTypeRequiredDescription
hashing_keyVARCHARYesString value to hash (typically user ID or session ID)
probabilityDOUBLEYesProbability of success on each trial (0 < p <= 1)

Notes

  • Deterministic - same key always produces same value
  • Returns the number of trials until first success (1-indexed, minimum is 1)
  • Uses inverse CDF: CEIL(LN(U) / LN(1-p))
  • Mean of distribution is 1/p
  • Models retry counts, attempts before conversion, time to first event
  • Common for customer acquisition modeling, reliability testing
  • Probability must be in (0, 1]

Examples

FeatureQL
SELECT
    f1 := SAMPLE_GEOMETRIC('k', 0.3E0) -- Geometric draw with p=0.3 (mean ~3.3 trials) for a fixed key
;
Result
f1 BIGINT
2

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