← aggr operator page · clause/aggr/attribute_role/attribute_next_to_measure

Attribute next to measure 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

aggr Me_1 := sum ( Me_1 ), attribute At_1 := max ( Me_1 ) group by Id_1: a new attribute next to the aggregated measure.

Manual:

Aggregation: "It is possible to specify the role of the calculated Component among measure, attribute, or viral attribute", and "The Attributes calculated through the aggr clauses are maintained in the result".

Expected:

Per Id_1, with Id_2 dropped, the sums Me_1 = 6 and 7 and the maxima At_1 = 5 and 4, an Integer Attribute, as for max "For numeric operands, the result has the same type as the operand"; Me_1 may be Integer or Number, by the integer rule of Sum. The Me_1 item keeps a Measure in the result: Attribute without measure leaves it out.

script.vtl ⇩

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

input/DS_1.csv ⇩

Id_1Id_2Me_1
1A1
1B5
2A3
2B4

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": "Me_1", "type": "Integer", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Me_1At_1
165
274

expected/DS_r.json ⇩

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