Skip to content

ReplaceAt

mapping category: array no `||` new-mode: required resultSize: 1

Replaces the element at the given 0-based index of an ARRAY with a new value.

ReplaceAt(N, value) returns a new ARRAY with the element at index N replaced by value. Out-of-range indices are silently ignored — the array is returned unchanged.

Both the index and the replacement value can be literals or field references; field references are resolved per row from the current pipeline state. Field-reference indices must be INT-valued, while field-reference values can be any scalar. The transformer also supports infix arithmetic in the index parameter (e.g. :len - 1).

Available in new mode only.

Parameters

1index Mandatory — accepts: INT, field

0-based index, either as an integer literal or a field reference to an INT-valued pipeline field.

2value Mandatory — accepts: BOOLEAN, DATE, FLOAT, INT, STRING, NULL, field

Replacement value. May be a scalar literal or a field reference to any non-ARRAY pipeline field.

Input type

  • ARRAY

Output type

  • ARRAY

Requires

  • Exactly one ARRAY-typed pipeline input.
  • When index is a field reference the referenced field must hold an INT.

Examples

Replace a literal position with a literal value

:array => ReplaceAt(2, "new")

Use field-reference index and value

:array => ReplaceAt(:idx, :val)

Replace the last element via infix arithmetic

:array => ReplaceAt(:len - 1, :val)

Errors

  • `ReplaceAt': input must be ARRAY-typed
    The pipeline value reaching the rule is not an ARRAY.
  • `ReplaceAt': index field:idx' must be an integer`
    The referenced index field is not an INT.
  • `ReplaceAt': value field:val' could not be resolved`
    The referenced value field is not in the pipeline or has no value.
  • `ReplaceAt' is only available in new mode
    New mode is not enabled in etl.conf.

See also

At, InsertAt, RemoveAt, Remove, Size