← aggregate_invocation operator page · aggregate/aggregate_invocation/group_by/manual_ex_1

Manual example 1 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

avg at data set level grouped by Id_1, on an operand with the non-viral attribute At_1.

Manual:

Aggregate invocation, Example 1, output verbatim: "For invocation at Data Set level, the Attribute propagation rule is applied".

Expected:

At_1 is dropped, as a non-viral attribute; 2010 gives (20 + 1 + 1 + 23) / 4 = 11.25, 2011 gives 10 and 2012 gives 35.

Erratum:

the script comments its two alternative forms with #, which is the membership operator, not a VTL comment. The manual's conventions define /* */ and //, so they are commented with // here.

script.vtl ⇩

DS_r := avg ( DS_1 group by Id_1 );

// Or equivalently:
// DS_r := avg ( DS_1 group except Id_2, Id_3 )
// DS_r := avg ( DS_1#Me_1 group by Id_1 )

input/DS_1.csv ⇩

Id_1Id_2Id_3Me_1At_1
2010EXX20
2010BXX1H
2010RXX1A
2010FYY23
2011EXX20P
2011BZZ1N
2011RYY-1P
2011FXX20Z
2012LZZ40P
2012EYY30P

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "Time_Period", "role": "Identifier", "nullable": false},
        {"name": "Id_2", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Id_3", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "Integer", "role": "Measure", "nullable": true},
        {"name": "At_1", "type": "String", "role": "Attribute", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Me_1
201011.25
201110.0
201235.0

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "Time_Period", "role": "Identifier"},
        {"name": "Me_1", "type": "Number", "role": "Measure"}
      ]
    }
  ]
}