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
ParameterTypeRequiredDescription
featureFEATUREYesFeature to recompute
dependencyFEATUREYesFeature that feature depends on, directly or not
replacementTYesNew definition for the dependency at the same position: a literal, a feature or an expression

Notes

  • REPLACING and WITH list the same number of items, matched by position
  • Replacing a feature that feature does not depend on, or feature itself, 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, A swaps them, and REPLACING X WITH X + 1 does not loop
  • Only the graph of feature changes. 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 BIGINTRESULT1 BIGINTRESULT2 BIGINTRESULT3 BIGINT
2444

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 BIGINTPOWER BIGINTRESULT2 BIGINT
5611

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 BIGINTRESULT1 BIGINT
22
22