← aggr operator page · clause/aggr/group_by/manual_ex_1

Manual example 1 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

aggr Me_1 := sum( Me_1 ) group by Id_1 , Id_2, over an Integer measure.

Manual:

Aggregation, Example 1, with the manual's data points: "group by: the Data Points are grouped by the values of the specified Identifiers (groupingId). The Identifiers not specified are dropped in the result."

Expected:

Id_3 is dropped, and the sums are 2, 8 and 9. Me_1 may be Integer, as the manual's ex_1.json writes it, or Number: Sum says "implementations may preserve the integer type for the resulting measure or component when all operand values are integer and the sum is computed in integer arithmetic".

script.vtl ⇩

DS_r := DS_1 [ aggr Me_1:= sum( Me_1 ) group by Id_1 , Id_2 ];

input/DS_1.csv ⇩

Id_1Id_2Id_3Me_1
1AXX0
1AYY2
1BXX3
1BYY5
2AXX7
2AYY2

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "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}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Id_2Me_1
1A2
1B8
2A9

expected/DS_r.json ⇩

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