← inner_join operator page · join/inner_join/nary/manual_ex_5

Manual example 5 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

three statements: the last joins DS_4 with two aliased expressions, IBSC and IBSD, renamed so that Id_1 is their only common identifier.

Manual:

Inner Join, Example 5, with the page's result: "The contents of inner_join are ideally determined stepwise".

Expected:

five data points on the key Id_1, with the Me_3 of IBSD (null, and 50 for Id_1 = 3); only DS_r is compared.

Erratum:

Me_3 is in both IBSC and IBSD, and stripping the prefixes would give two Me_3, an error by the Behaviour section, so the script adds drop IBSC#Me_3 (null everywhere); ds_5.json declares Me_2 an Identifier, but the result has Me_21 and Me_22 as Measures, so it is loaded as a Measure. The input files also name their data set DS_r, a slip with no effect: they are loaded as DS_5 and DS_6.

script.vtl ⇩

IBSC := inner_join(DS_5, DS_6[sub Id_4 = "c"] as CI);
IBSD := inner_join(DS_5, DS_6[sub Id_4 = "d"] as DI);

DS_r := inner_join (
   DS_4,
   IBSC[rename Id_2 to Id_21, Id_3 to Id_31, Me_2 to Me_21] as IBSC,
   IBSD[rename Id_2 to Id_22, Id_3 to Id_32, Me_2 to Me_22] as IBSD
   drop IBSC#Me_3
);

input/DS_4.csv ⇩

Id_1Me_1
1200
2300
3100

input/DS_4.json ⇩

{
  "datasets": [
    {
      "name": "DS_4",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "Integer", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

input/DS_5.csv ⇩

Id_2Id_3Me_2
10S1112345678
20S287654321
30S12118273645

input/DS_5.json ⇩

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

input/DS_6.csv ⇩

Id_1Id_2Id_4Me_3
130c
110d
230c
220c
210d
330c
310d50
320d50

input/DS_6.json ⇩

{
  "datasets": [
    {
      "name": "DS_6",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Id_2", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Id_4", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Me_3", "type": "Integer", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Id_21Id_22Me_1Id_31Me_21Id_32Me_22Me_3
13010200S12118273645S1112345678
23010300S12118273645S1112345678
22010300S287654321S1112345678
33010100S12118273645S111234567850
33020100S12118273645S28765432150

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier"},
        {"name": "Id_21", "type": "Integer", "role": "Identifier"},
        {"name": "Id_22", "type": "Integer", "role": "Identifier"},
        {"name": "Me_1", "type": "Integer", "role": "Measure"},
        {"name": "Id_31", "type": "String", "role": "Identifier"},
        {"name": "Me_21", "type": "Integer", "role": "Measure"},
        {"name": "Id_32", "type": "String", "role": "Identifier"},
        {"name": "Me_22", "type": "Integer", "role": "Measure"},
        {"name": "Me_3", "type": "Integer", "role": "Measure"}
      ]
    }
  ]
}