Skip to content

GROUP with BY and TOP / OFFSET fails the param count check #1706

Description

@ichavchavadze

Problem

Any GROUP in the context-independent form (with BY) that uses TOP / OFFSET fails at startup with a param count mismatch:

someInt = DATA INTEGER ();

firstPaymentPeriod(PaymentCondition c) = GROUP LAST PaymentPeriod p ORDER DESC p TOP someInt() OFFSET someInt() BY paymentCondition(p);
PaymentCondition:51:135 3 parameter(s) expected, 2 provided

Even the documented example fails the same way (GROUP_operator.md):

last3HostGoalsScored(team) = GROUP SUM hostGoals(Game game) ORDER DESC date(game), game TOP 3 BY hostTeam(game);

This is not a v6 -> master regression: the whole chain (addOGProp, the selectTop join block in addScriptedCDIGProp) is identical on both branches, so v6 fails identically. Only the dependent form (without BY) works.

Cause

addOGProp appends the TOP / OFFSET window interfaces as extra interfaces of the group property, so its interface count is |BY keys| + |window params| (plus the used outer params). But the join in ScriptingLogicsModule.addScriptedCDIGProp that binds the window interfaces to the TOP / OFFSET expressions builds its mapping from the result interfaces and the TOP / OFFSET expressions only — the group (BY) keys are omitted, hence expected = resultInterfaces + BY + window vs provided = resultInterfaces + window.

Fix

Build the join mapping with an entry per group interface, mirroring the getAllGroupProps interleave: the result interfaces are bound to their params as before, and the group (BY) keys stay free params at their positions, so the joined property keeps the group interfaces (and the signature order). The params of the TOP / OFFSET expressions are included in the result interfaces computation, so an expression referencing an outer param gets a consistent implicit interface. In the dependent form (without BY) the mapping is built exactly as before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions