Reshapes
← Relifold documentationApply
Perform a custom deterministic rows-to-rows reshape.
Apply is the escape hatch for a deterministic whole-Space reshape that does not fit a named operation.
Worked example
Apply(
name="latest-behavior-per-user",
input_spaces=("behaviors",),
output_space="latest-behaviors",
fn=PythonFunction(
name="latest_row_per_user",
source="""def latest_row_per_user(rows):
latest = None
for row in rows:
if latest is None or row.get("time", "") > latest.get("time", ""):
latest = row
return [] if latest is None else [latest]
""",
),
group_by="user_id",
emits=("user_id", "history"),
output_fields=("user_id", "history"),
)| Parameter | Default | Meaning |
|---|---|---|
input_spaces | required | The Space or Spaces read by the reshape. |
name | required | A stable node name shown in the pipeline and session. |
output_space | required | The Space receiving returned rows. |
fn | required | A callable receiving one flat list containing the ordinary mappings gathered from every input Space, and returning an iterable of ordinary mappings. |
emits | none | Descriptive names of fields produced by the callable. |
output_fields | none | Complete output schema when the callable builds new rows instead of retaining all fields from its input rows. |
group_by | none | Optional column or composite key. Relifold invokes the callable once per exact key group and records only that group's rows as support for its outputs. |
max_output_rows | none | Optional positive global hard ceiling enforced across all returned rows, not once per group. Use it after deterministic whole-hand ranking to bound downstream work and its forecast cost. |
Output
Exactly the ordinary row mappings returned by the callable.
Design guidance
Prefer a named reshape when one expresses the operation. Apply is appropriate for explicit aggregations and projections, not semantic decisions. Set group_by for per-entity reductions; reserve whole-hand Apply for genuinely global operations.