← left_join operator page · join/left_join/aggr_attribute/max_as_attribute

Max as attribute 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

aggr with two components: the sum of Me_1 by Id_1 as the measure Me_3, and its maximum as At_1, with the role attribute.

Manual:

Left Join: the role of an aggregated component is aggrRole ::= { measure | attribute | viral attribute }, and "if omitted, the Measure role is assumed"; "All non-identifier components are removed, and only the components generated by the sub-expressions are kept".

Expected:

the left join keeps the four keys of DS_1, with Me_2 null at (1,B). Id_1 = 1 gives Me_3 = 30 and At_1 = 20, Id_1 = 2 gives 70 and 40; At_1 is a Number Attribute.

script.vtl ⇩

DS_r := left_join(DS_1, DS_2 aggr Me_3 := sum(Me_1), attribute At_1 := max(Me_1) group by Id_1);

input/DS_1.csv ⇩

Id_1Id_2Me_1
1A10
1B20
2A30
2B40

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

input/DS_2.csv ⇩

Id_1Id_2Me_2
1A1
1C2
2A3
2B4

input/DS_2.json ⇩

{
  "datasets": [
    {
      "name": "DS_2",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Id_2", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Me_2", "type": "Number", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Me_3At_1
13020
27040

expected/DS_r.json ⇩

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