VARIANT()
All functions > CORE > VARIANT()
Recomputes a feature with some of its dependencies replaced by other definitions.
Signatures
Returns: The feature computed with the replaced dependencies
VARIANT( feature REPLACING dependency, ... WITH replacement, ... ) → FEATURE
| Parameter | Type | Required | Description |
|---|---|---|---|
feature | FEATURE | Yes | Feature to recompute |
dependency | FEATURE | Yes | Feature that feature depends on, directly or not |
replacement | T | Yes | New definition for the dependency at the same position: a literal, a feature or an expression |
Notes
REPLACINGandWITHlist the same number of items, matched by position- Replacing a feature that
featuredoes not depend on, orfeatureitself, raises UE/VARIANT-ORIGIN-NOT-A-DEPENDENCY - Replacements apply at the same time and are computed with the original features:
REPLACING A, B WITH B, Aswaps them, andREPLACING X WITH X + 1does not loop - Only the graph of
featurechanges. Other features keep their original dependencies - The rewritten graph is type-checked again, so a replacement can change downstream types
See also
Examples
Evaluate a formula with other input values
FeatureQL
DEFINE
expr := INPUT(BIGINT),
power := INPUT(BIGINT),
operation := POW(expr, power)
RETURN
result1 := VARIANT(operation REPLACING expr, power WITH 2, 2)
;Result
| RESULT1 BIGINT |
|---|
| 4 |
Replace with a feature or an expression
FeatureQL
DEFINE
expr := INPUT(BIGINT),
power := INPUT(BIGINT),
operation := POW(expr, power)
RETURN
expr2 := 2,
result1 := VARIANT(operation REPLACING expr, power WITH 2, 2),
result2 := VARIANT(operation REPLACING expr, power WITH 2, expr2),
result3 := VARIANT(operation REPLACING expr, power WITH expr2, expr2)
;Result
| EXPR2 BIGINT | RESULT1 BIGINT | RESULT2 BIGINT | RESULT3 BIGINT |
|---|---|---|---|
| 2 | 4 | 4 | 4 |
Swap an intermediate formula
FeatureQL
DEFINE
expr := INPUT(BIGINT),
power := INPUT(BIGINT),
operation_base := POW(expr, power),
operation_replacement := expr + power,
operation_alias := operation_base
RETURN
expr,
power,
result2 := VARIANT(
operation_alias REPLACING operation_base WITH operation_replacement
)
FOR
expr := BIND_VALUE(5),
power := BIND_VALUE(6)
;Result
| EXPR BIGINT | POWER BIGINT | RESULT2 BIGINT |
|---|---|---|
| 5 | 6 | 11 |
Replace an input with a value from a mapping
FeatureQL
DEFINE
id := INPUT(VARCHAR),
expr := INPUT(BIGINT),
power := INPUT(BIGINT),
operation := POW(expr, power)
RETURN
expr2 := 2,
result1 := VARIANT(
operation REPLACING expr, power WITH 2, INLINE_COLUMNS(
id VARCHAR BIND TO id,
val BIGINT
FROM CSV(
id,val
a,1
b,1
)
)[val]
)
FOR
id := BIND_VALUES(ARRAY('a', 'b'))
;Result
| EXPR2 BIGINT | RESULT1 BIGINT |
|---|---|
| 2 | 2 |
| 2 | 2 |