Inner Join · inner_join

🟢 22 of 22 forms all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc2 (90ee9376) · pandas 2.3.3 · DuckDB 1.5.5
🟢 all ok🟡 partially implemented🛡️ refused with an error🔴 not implemented or crash🔵 engines differ ✅ match · ❌ wrong result · 🛡 guarded error (code) · 💥 crash · 📌 team decision
        ---
config:
  flowchart:
    useMaxWidth: false

---
flowchart LR
    classDef ok fill:#d4edda,stroke:#28a745,color:#000
    classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
    classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
    classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
    classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
    classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
    classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
    O["Inner Join · inner_join 📌<br/>🟢22"]:::ok
    v_bare["inner_join(DS, DS)"]:::ok
    v_aliases["inner_join(DS as a, DS as b)"]:::ok
    v_using["inner_join(DS, DS using Id)"]:::ok
    v_filter["inner_join(DS, DS filter cond)"]:::ok
    v_apply["inner_join(DS, DS apply expr)"]:::ok
    v_calc_default["inner_join(DS, DS calc C #58;#61; expr) 📌"]:::ok
    v_calc_measure["inner_join(DS, DS calc measure C #58;#61; expr)"]:::ok
    v_calc_identifier["inner_join(DS, DS calc identifier C #58;#61; expr)"]:::ok
    v_calc_attribute["inner_join(DS, DS calc attribute C #58;#61; expr)"]:::ok
    v_calc_viral_attribute["inner_join(DS, DS calc viral attribute C #58;#61; expr) 📌"]:::ok
    v_aggr_no_group["inner_join(DS, DS aggr C #58;#61; agg)"]:::ok
    v_aggr_group_by["inner_join(DS, DS aggr C #58;#61; agg group by Id) 📌"]:::ok
    v_aggr_group_except["inner_join(DS, DS aggr C #58;#61; agg group except Id)"]:::ok
    v_aggr_group_all["inner_join(DS, DS aggr C #58;#61; agg group all time_agg(p))"]:::ok
    v_aggr_having["inner_join(DS, DS aggr C #58;#61; agg group by Id having cond)"]:::ok
    v_aggr_measure["inner_join(DS, DS aggr measure C #58;#61; agg group by Id)"]:::ok
    v_aggr_attribute["inner_join(DS, DS aggr C #58;#61; agg, attribute A #58;#61; agg group by Id)"]:::ok
    v_aggr_viral_attribute["inner_join(DS, DS aggr C #58;#61; agg, viral attribute A #58;#61; agg group by Id) 📌"]:::ok
    v_keep["inner_join(DS, DS keep C)"]:::ok
    v_drop["inner_join(DS, DS drop C)"]:::ok
    v_rename["inner_join(DS, DS rename C to C2)"]:::ok
    v_nary["inner_join(DS, DS, DS)"]:::ok
    subgraph G_use["Used with"]
        direction LR
        used__clause__filter["filter ↗<br/><small>uses</small>"]:::ext
        used__clause__calc["calc ↗<br/><small>uses</small>"]:::ext
        used__clause__aggr["aggr ↗<br/><small>uses</small>"]:::ext
        used__clause__keep["keep ↗<br/><small>uses</small>"]:::ext
        used__clause__drop["drop ↗<br/><small>uses</small>"]:::ext
        used__clause__rename["rename ↗<br/><small>uses</small>"]:::ext
    end
    v_bare --- O
    v_aliases --- O
    v_using --- O
    v_filter --- O
    v_apply --- O
    v_calc_default --- O
    v_calc_measure --- O
    v_calc_identifier --- O
    v_calc_attribute --- O
    v_calc_viral_attribute --- O
    v_aggr_no_group --- O
    v_aggr_group_by --- O
    v_aggr_group_except --- O
    v_aggr_group_all --- O
    v_aggr_having --- O
    O --- v_aggr_measure
    O --- v_aggr_attribute
    O --- v_aggr_viral_attribute
    O --- v_keep
    O --- v_drop
    O --- v_rename
    O --- v_nary
    O -.- G_use
    style G_use fill:#ffffff,stroke:#868e96,stroke-width:1px,stroke-dasharray: 1 4
    click v_bare href "#form-bare"
    click v_aliases href "#form-aliases"
    click v_using href "#form-using"
    click v_filter href "#form-filter"
    click v_apply href "#form-apply"
    click v_calc_default href "#form-calc-default"
    click v_calc_measure href "#form-calc-measure"
    click v_calc_identifier href "#form-calc-identifier"
    click v_calc_attribute href "#form-calc-attribute"
    click v_calc_viral_attribute href "#form-calc-viral-attribute"
    click v_aggr_no_group href "#form-aggr-no-group"
    click v_aggr_group_by href "#form-aggr-group-by"
    click v_aggr_group_except href "#form-aggr-group-except"
    click v_aggr_group_all href "#form-aggr-group-all"
    click v_aggr_having href "#form-aggr-having"
    click v_aggr_measure href "#form-aggr-measure"
    click v_aggr_attribute href "#form-aggr-attribute"
    click v_aggr_viral_attribute href "#form-aggr-viral-attribute"
    click v_keep href "#form-keep"
    click v_drop href "#form-drop"
    click v_rename href "#form-rename"
    click v_nary href "#form-nary"
    click used__clause__filter href "../clause/filter.html" "Filtering Data Points · filter"
    click used__clause__calc href "../clause/calc.html" "Calculation of a Component · calc"
    click used__clause__aggr href "../clause/aggr.html" "Aggregation · aggr"
    click used__clause__keep href "../clause/keep.html" "Maintaining Components · keep"
    click used__clause__drop href "../clause/drop.html" "Removal of Components · drop"
    click used__clause__rename href "../clause/rename.html" "Change of Component name · rename"
    

Types

Takes boolean, any scalar · Gives any type

Viral attributes: combined with the propagation rules → Viral propagation

Comes from: any operator that returns a value

Goes to: whatever takes its input's type

Forms

inner_join(DS, DS) 🟢 · any scalar → any type

Common keys only 🟢 pandas ✅ · DuckDB ✅
Tests:

the natural inner join of two operands with the same identifiers, with no clause.

Manual:

Inner Join: “if using is not specified, inner_join performs a natural join, that is, it uses all the identifiers appearing in more than one dataset as join keys”, and matches them “according to SQL inner join”.

Expected:

the keys in both operands, (1,A), (2,A) and (2,B), with Me_1 and Me_2; (1,B) is in DS_1 only and (1,C) in DS_2 only.

script.vtl
DS_r := inner_join(DS_1, DS_2);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Me_1Me_2
1A101
2A303
2B404

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

One shared identifier 🟢 pandas ✅ · DuckDB ✅
Tests:

a natural join of DS_1 (Id_1, Id_2) and DS_2 (Id_2, Id_3): they share Id_2, and neither has all the identifiers of the other.

Manual:

Inner Join: inner_join requires “that there exists a permutation of the join operands such that each operand has at least one identifier in common with any of the operands preceding it”, and joins on “all the identifiers appearing in more than one dataset”.

Expected:

the key is Id_2. A pairs the data point of DS_1 with both of DS_2, so the result has Id_1, Id_2, Id_3 = (1,A,X) and (1,A,Y); B and C have no match.

script.vtl
DS_r := inner_join(DS_1, DS_2);
Input DS_1
Id_1Id_2Me_1
1A10
2B20
Input DS_2
Id_2Id_3Me_2
AX1
AY2
CX3
Expected DS_r
Id_1Id_2Id_3Me_1Me_2
1AX101
1AY102

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

No common identifier 🟢 pandas ✅ · DuckDB ✅
Tests:

the natural inner join of two operands with no identifier in common: DS_1 has Id_1 and DS_2 has Id_2.

Manual:

Inner Join: inner_join requires “that there exists a permutation of the join operands such that each operand has at least one identifier in common with any of the operands preceding it”.

Expected:

the error 1-1-13-26, “The operands cannot be ordered so that each one has an identifier in common with one before it, as {dataset} has none in common with the others”, for “if using is not specified, inner_join performs a natural join …; if the required condition does not hold, an error is raised”: the message states that condition, which fails as DS_1 and DS_2 share no identifier.

script.vtl
DS_r := inner_join(DS_1, DS_2);
Input DS_1
Id_1Me_1
110
220
Input DS_2
Id_2Me_2
A1
B2

Expected error 1-1-13-26: At op {op}: The operands cannot be ordered so that each one has an identifier in common with one before it, as {dataset} has none in common with the others.

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/error.json · example page ↗

inner_join(DS as a, DS as b) 🟢 · any scalar → any type

Aliases without clause 🟢 pandas ✅ · DuckDB ✅
Tests:

aliases on the operands (as d1, as d2), with no clause.

Manual:

Inner Join: the aliases are “valid only within the “join” operation to make it easier to refer to them”.

Expected:

the aliases do not change the result: that of Common keys only, (1,A), (2,A) and (2,B) with Me_1 and Me_2.

script.vtl
DS_r := inner_join(DS_1 as d1, DS_2 as d2);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Me_1Me_2
1A101
2A303
2B404

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Alias prefixed measures 🟢 pandas ✅ · DuckDB ✅
Tests:

the measure Me_1 of both operands, named through the aliases (d1#Me_1, d2#Me_1) and renamed: the result depends on the operand each alias stands for.

Manual:

Inner Join: the components in several data sets are in VDS₁ once per data set, and their “names … are prefixed with the alias of the data set they come from, separated by the “#” symbol”.

Expected:

the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands: Me_11 holds the values of DS_1 (10, 30, 40) and Me_12 those of DS_2 (1, 3, 4). An engine that swapped the aliases would swap the columns.

script.vtl
DS_r := inner_join(DS_1 as d1, DS_2 as d2 rename d1#Me_1 to Me_11, d2#Me_1 to Me_12);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_1
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Me_11Me_12
1A101
2A303
2B404

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS using Id) 🟢 · any scalar → any type

All common identifiers 🟢 pandas ✅ · DuckDB ✅
Tests:

using Id_1, Id_2, all the identifiers that the operands have in common.

Manual:

Inner Join: “if using is specified, inner_join removes from each of the I_i sets those identifiers not appearing in the using clause, and only uses the remaining identifiers as join keys if they appear in more than one dataset”.

Expected:

the keys of the natural join, so the result of Common keys only: (1,A), (2,A) and (2,B).

script.vtl
DS_r := inner_join(DS_1, DS_2 using Id_1, Id_2);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Me_1Me_2
1A101
2A303
2B404

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Subset of identifiers 🟢 pandas ✅ · DuckDB ✅
Tests:

using Id_1 only, on operands with Id_1 and Id_2 that share no (Id_1, Id_2) key; the renames name the two Id_2.

Manual:

Inner Join: with using, it “only uses the remaining identifiers as join keys”; the other components of several data sets “appear as many times as the data sets they come from”, with a prefix.

Expected:

Id_1 = 1 pairs both data points of DS_1 with the one of DS_2: (1,A,C) and (1,B,C) as Id_1, Id_21, Id_22. The natural join would match nothing, and without the renames, stripping the prefixes would give two Id_2, an error.

script.vtl
DS_r := inner_join(DS_1 as d1, DS_2 as d2 using Id_1 rename d1#Id_2 to Id_21, d2#Id_2 to Id_22);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2B30
Input DS_2
Id_1Id_2Me_2
1C1
3D3
Expected DS_r
Id_1Id_21Id_22Me_1Me_2
1AC101
1BC201

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS filter cond) 🟢 · any scalar, boolean → any type

Filter on measure 🟢 pandas ✅ · DuckDB ✅
Tests:

filter Me_1 > 15 on the joined data points.

Manual:

Inner Join: the filter “is applied on VDS₁ … when the expression is true the Data Point is kept in the result, otherwise it is discarded”.

Expected:

of the joined keys (1,A), (2,A) and (2,B), the last two (Me_1 = 30 and 40) are kept.

script.vtl
DS_r := inner_join(DS_1, DS_2 filter Me_1 > 15);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Me_1Me_2
2A303
2B404

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS apply expr) 🟢 · any scalar → any type

Manual example 4 🟢 pandas ✅ · DuckDB ✅
Tests:

apply d1 || d2, written with the aliases, on two operands that both have Me_1 and Me_2.

Manual:

Inner Join, Example 4, output verbatim: “apply combines the homonym Measures in the source operands”, and “The expression applyExpr can use as input the names or aliases of the operand data sets”.

Expected:

the join keeps (1,A) and (1,B): Me_1 := d1#Me_1 || d2#Me_1 gives AB and CS, Me_2 := d1#Me_2 || d2#Me_2 gives BQ and DT.

script.vtl
DS_r := inner_join (DS_1 as d1, DS_3 as d2 apply d1 || d2);
Input DS_1
Id_1Id_2Me_1Me_2
1AAB
1BCD
2AEF
Input DS_3
Id_1Id_2Me_1Me_2
1ABQ
1BST
3AZM
Expected DS_r
Id_1Id_2Me_1Me_2
1AABBQ
1BCSDT

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_3.csv · input/DS_3.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Sum of homonym measures 🟢 pandas ✅ · DuckDB ✅
Tests:

apply DS_1 + DS_2, written with the data set names, on the homonym measure Me_1.

Manual:

Inner Join: apply “applies the expression to each of the n-uple of homonym Measures in the input data sets producing in the target a single homonym Measure for each n-uple”, and “All the input measures do not appear”.

Expected:

the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands: Me_1 := DS_1#Me_1 + DS_2#Me_1 is 11, 33 and 44.

script.vtl
DS_r := inner_join(DS_1, DS_2 apply DS_1 + DS_2);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_1
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Me_1
1A11
2A33
2B44

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS calc C := expr) 🟢 · any scalar → any type

Manual example 3 🟢 pandas ✅ · DuckDB ✅
Tests:

filter, then calc Me_2 := Me_2 || "_NEW" with no role, then keep, in a join of one operand.

Manual:

Inner Join, Example 3, output verbatim: “If a generated component already exists in any of the input data sets, all input components homonymous to the former are removed, and only the generated component is kept”. The page asks for “a minimum of two data set operands”, but the grammar (joinClauseItem (COMMA joinClauseItem)*?) accepts one and the page prints its result, so the example is kept as it is.

Expected:

VDS₁ is DS_1; filter Id_2 = "B" keeps (1,B), where the calc gives Me_2 = D_NEW, a Measure as “if the role is not specified, it will be measure”, and keep keeps it with Me_1 = C.

script.vtl
DS_r := inner_join ( DS_1  filter Id_2 ="B" calc Me_2 := Me_2 || "_NEW" keep Me_1, Me_2);
Input DS_1
Id_1Id_2Me_1Me_2
1AAB
1BCD
2AEF
Expected DS_r
Id_1Id_2Me_1Me_2
1BCD_NEW

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Default role is measure 🟢 pandas ✅ · DuckDB ✅
Tests:

calc Me_3 := Me_1 + Me_2 with no role.

Manual:

Inner Join: in a join, “The role of the new components can be specified …; if the role is not specified, it will be measure”.

Expected:

the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands. Me_3 is a Measure, as in Explicit measure role of the calc_measure form: 11, 33 and 44.

script.vtl
DS_r := inner_join(DS_1, DS_2 calc Me_3 := Me_1 + Me_2);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Me_1Me_2Me_3
1A10111
2A30333
2B40444

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Attribute becomes measure 🟢 pandas ✅ · DuckDB ✅
Tests:

calc At_1 := At_1 || "x": At_1, a plain (not viral) Attribute of DS_1, recalculated under its own name, with the role left out.

Manual:

Inner Join: VDS₁ has the identifiers and the measures of the operands, and “The viral attributes, coming from any number of Data Sets, which appear once”, and no other attribute, so the clause could not read At_1 (error 1-1-1-10); in calc, “if the role is not specified, it will be measure”.

Expected:

the join keeps (1,A), (1,B) and (2,A) ((2,B) is in DS_1 only), and At_1 is a Measure: ax, bx and cx.

Team decision:

#1258: the joins keep their non-viral Attributes until the VTL Task Force settles sdmx-twg/vtl#730, “Attributes in joins should be treated as measures”: dropping them “may have many unintended implications in the use of non-viral attributes”.

script.vtl
DS_r := inner_join(DS_1, DS_2 calc At_1 := At_1 || "x");
Input DS_1
Id_1Id_2Me_1At_1
1A10a
1B20b
2A30c
2B40d
Input DS_2
Id_1Id_2Me_2
1A1
1B2
2A3
Expected DS_r
Id_1Id_2Me_1Me_2At_1
1A101ax
1B202bx
2A303cx

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS calc measure C := expr) 🟢 · any scalar → any type

Explicit measure role 🟢 pandas ✅ · DuckDB ✅
Tests:

calc measure Me_3 := Me_1 + Me_2, with the role keyword written out.

Manual:

Inner Join: “calc calculates new components by independent sub-expressions evaluated at component level. The role of the new components can be specified”.

Expected:

the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands. The input components stay and Me_3 is added: 11, 33 and 44.

script.vtl
DS_r := inner_join(DS_1, DS_2 calc measure Me_3 := Me_1 + Me_2);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Me_1Me_2Me_3
1A10111
2A30333
2B40444

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS calc identifier C := expr) 🟢 · any scalar → any type

Constant identifier 🟢 pandas ✅ · DuckDB ✅
Tests:

calc identifier Id_3 := "X", a new constant identifier.

Manual:

Inner Join: “The role of the new components can be specified”; Id_3 is new, so no identifier of the input is overwritten.

Expected:

the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands; each gets Id_3 = X and the keys stay unique. A constant is never null, so the decision of #1010 (1-1-1-16 for an identifier calculated from a declared-nullable expression) does not apply.

script.vtl
DS_r := inner_join(DS_1, DS_2 calc identifier Id_3 := "X");
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Id_3Me_1Me_2
1AX101
2AX303
2BX404

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS calc attribute C := expr) 🟢 · any scalar → any type

Constant attribute 🟢 pandas ✅ · DuckDB ✅
Tests:

calc attribute At_1 := "EP", a constant attribute.

Manual:

Inner Join: “calc calculates new components by independent sub-expressions evaluated at component level. The role of the new components can be specified”. The calc clause page has the same calculation, DS_1 [ calc attribute At_1:= "EP" ] (its Example 2).

Expected:

the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands, and each gets the String Attribute At_1 = EP.

script.vtl
DS_r := inner_join(DS_1, DS_2 calc attribute At_1 := "EP");
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Me_1Me_2At_1
1A101EP
2A303EP
2B404EP

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS calc viral attribute C := expr) 🟢 · any scalar → any type

Constant viral attribute 🟢 pandas ✅ · DuckDB ✅
Tests:

calc viral attribute At_1 := "EP", a constant viral attribute.

Manual:

Inner Join: on viral attributes, “if the calc clause is present instead, it may directly replace the computation algorithm used for the propagation”.

Expected:

the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands, and each gets the String Viral Attribute At_1 = EP.

Team decision:

#1257: as the comments on sdmx-twg/vtl#731 propose, a viral Attribute needs a propagation rule only where its values are combined, until the VTL Task Force discusses it.

script.vtl
DS_r := inner_join(DS_1, DS_2 calc viral attribute At_1 := "EP");
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Me_1Me_2At_1
1A101EP
2A303EP
2B404EP

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS aggr C := agg) 🟢 · any scalar → any type

Sum without grouping 🟢 pandas ✅ · DuckDB ✅
Tests:

aggr with no grouping clause.

Manual:

Inner Join: “If no grouping clause is specified, then all the input Data Points are aggregated in a single group and the clause returns a data set that contains a single Data Point and has no Identifier Components.”

Expected:

one data point with no identifier: Me_3 = 10 + 30 + 40 = 80, the Me_1 of the three joined keys.

script.vtl
DS_r := inner_join(DS_1, DS_2 aggr Me_3 := sum(Me_1));
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Me_3
80

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS aggr C := agg group by Id) 🟢 · any scalar → any type

Sum by id 1 🟢 pandas ✅ · DuckDB ✅
Tests:

aggr with group by Id_1, which drops Id_2.

Manual:

Inner Join: “All non-identifier components are removed, and only the components generated by the sub-expressions are kept”; Aggregate invocation: with group by “The Identifiers not specified are dropped in the result”.

Expected:

the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands: Me_3 is 10 for Id_1 = 1 and 30 + 40 = 70 for Id_1 = 2.

script.vtl
DS_r := inner_join(DS_1, DS_2 aggr Me_3 := sum(Me_1) group by Id_1);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Me_3
110
270

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Attribute becomes measure 🟢 pandas ✅ · DuckDB ✅
Tests:

aggr At_1 := max(At_1) group by Id_1: At_1, a plain (not viral) Attribute of DS_1, aggregated under its own name, with the role left out.

Manual:

Inner Join: VDS₁ has the identifiers and the measures of the operands, and “The viral attributes, coming from any number of Data Sets, which appear once”, and no other attribute, so the clause could not read At_1 (error 1-1-1-10); in aggr, “if the role is not specified, it will be measure”.

Expected:

At_1 comes from one operand, and the result has it as a String Measure (the maximum of a String is a String): b for Id_1 = 1 and c for Id_1 = 2, as (2,B) is in DS_1 only.

Team decision:

#1258: the joins keep their non-viral Attributes until the VTL Task Force settles sdmx-twg/vtl#730, “Attributes in joins should be treated as measures”: dropping them “may have many unintended implications in the use of non-viral attributes”.

script.vtl
DS_r := inner_join(DS_1, DS_2 aggr At_1 := max(At_1) group by Id_1);
Input DS_1
Id_1Id_2Me_1At_1
1A10a
1B20b
2A30c
2B40d
Input DS_2
Id_1Id_2Me_2
1A1
1B2
2A3
Expected DS_r
Id_1At_1
1b
2c

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS aggr C := agg group except Id) 🟢 · any scalar → any type

Sum except id 2 🟢 pandas ✅ · DuckDB ✅
Tests:

aggr with group except Id_2, which groups by Id_1.

Manual:

Inner Join, and Aggregate invocation: with group except “the Data Points are grouped by the values of the Identifiers not specified in the clause. The specified Identifiers are dropped in the result”.

Expected:

the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands; the groups are those of group by Id_1: Me_3 is 10 for Id_1 = 1 and 70 for Id_1 = 2.

script.vtl
DS_r := inner_join(DS_1, DS_2 aggr Me_3 := sum(Me_1) group except Id_2);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Me_3
110
270

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS aggr C := agg group all time_agg(p)) 🟢 · any scalar → any type

Quarters to years 🟢 pandas ✅ · DuckDB ✅
Tests:

aggr with the deprecated group all time_agg("A"), which groups the quarters of a time_period identifier by year.

Manual:

Inner Join, and Aggregate invocation: group all “converts the values of an Identifier Component using conversionExpr and keeps all the resulting Identifiers” (“This option is deprecated”). Time aggregation maps a time_period “into the comprising larger time period”, as its Example 1 turns 2010Q1 into 2010.

Expected:

the inner join keeps 2010Q1, 2011Q1 and 2011Q2: Me_3 is 10 for 2010 and 30 + 40 = 70 for 2011.

script.vtl
DS_r := inner_join(DS_1, DS_2 aggr Me_3 := sum(Me_1) group all time_agg("A"));
Input DS_1
Id_1Me_1
2010Q110
2010Q220
2011Q130
2011Q240
Input DS_2
Id_1Me_2
2010Q11
2010Q32
2011Q13
2011Q24
Expected DS_r
Id_1Me_3
201010
201170

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS aggr C := agg group by Id having cond) 🟢 · any scalar, boolean → any type

Having min above 15 🟢 pandas ✅ · DuckDB ✅
Tests:

aggr by Id_1 with having min(Me_1) > 15.

Manual:

Inner Join, and Aggregate invocation: “only groups for which havingCondition evaluates to true appear in the result”, and the condition “must invoke aggregate operators” (min here, which the reading of #1119 also allows).

Expected:

the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands. The smallest Me_1 of Id_1 = 1 is 10, so only Id_1 = 2 is kept, with Me_3 = 70.

script.vtl
DS_r := inner_join(DS_1, DS_2 aggr Me_3 := sum(Me_1) group by Id_1 having min(Me_1) > 15);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Me_3
270

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS aggr measure C := agg group by Id) 🟢 · any scalar → any type

Explicit measure role 🟢 pandas ✅ · DuckDB ✅
Tests:

aggr with the role keyword measure written out.

Manual:

Inner Join: aggrRole ::= { measure | attribute | viral attribute }, and “if the role is not specified, it will be measure”.

Expected:

the result of Sum by id 1, which leaves the role out: Me_3 is 10 for Id_1 = 1 and 70 for Id_1 = 2.

script.vtl
DS_r := inner_join(DS_1, DS_2 aggr measure Me_3 := sum(Me_1) group by Id_1);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Me_3
110
270

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS aggr C := agg, attribute A := agg group by Id) 🟢 · any scalar → any type

Max as attribute 🟢 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:

Inner 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 natural join keeps (1,A), (2,A) and (2,B), the keys in both operands. Id_1 = 1 gives Me_3 = 10 and At_1 = 10, Id_1 = 2 gives 70 and 40; At_1 is a Number Attribute.

script.vtl
DS_r := inner_join(DS_1, DS_2 aggr Me_3 := sum(Me_1), attribute At_1 := max(Me_1) group by Id_1);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Me_3At_1
11010
27040

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS aggr C := agg, viral attribute A := agg group by Id) 🟢 · any scalar → any type

Max as viral attribute 🟢 pandas ✅ · DuckDB ✅
Tests:

aggr with the sum of Me_1 by Id_1 as Me_3 and its maximum as At_1, with the role viral attribute.

Manual:

Inner Join: the role of an aggregated component is aggrRole ::= { measure | attribute | viral attribute }, and “if omitted, the Measure role is assumed”; on viral attributes, “if the aggr clause is present, the Attribute propagation rule is again applied to the set of all values that are aggregated”.

Expected:

the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands. Id_1 = 1 gives Me_3 = 10 and At_1 = 10, Id_1 = 2 gives 70 and 40; At_1 is a Number Viral Attribute.

Team decision:

#1257: as the comments on sdmx-twg/vtl#731 propose, a viral Attribute needs a propagation rule only where its values are combined, until the VTL Task Force discusses it.

script.vtl
DS_r := inner_join(DS_1, DS_2 aggr Me_3 := sum(Me_1), viral attribute At_1 := max(Me_1) group by Id_1);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Me_3At_1
11010
27040

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS keep C) 🟢 · any scalar → any type

Manual example 1 🟢 pandas ✅ · DuckDB ✅
Tests:

keep Me_1, d2#Me_2, Me_1A on two operands that both have Me_2: the aliases let d2#Me_2 name one of them.

Manual:

Inner Join, Example 1, output verbatim: “keep will maintain all the identifiers and only the specified non-identifier components”, and then “all components that originally appeared in multiple input data sets, are renamed by stripping their previously determined prefix”.

Expected:

the keys in both operands, (1,A) and (1,B); d1#Me_2 goes and d2#Me_2 becomes Me_2 (Q, T).

script.vtl
DS_r := inner_join (DS_1 as d1, DS_2 as d2 keep Me_1, d2#Me_2, Me_1A );
Input DS_1
Id_1Id_2Me_1Me_2
1AAB
1BCD
2AEF
Input DS_2
Id_1Id_2Me_1AMe_2
1ABQ
1BST
3AZM
Expected DS_r
Id_1Id_2Me_1Me_2Me_1A
1AAQB
1BCTS

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Keep one measure 🟢 pandas ✅ · DuckDB ✅
Tests:

keep Me_1.

Manual:

Inner Join: “keep will maintain all the identifiers and only the specified non-identifier components of VDS₃”.

Expected:

the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands, with Me_1 only: 10, 30 and 40.

script.vtl
DS_r := inner_join(DS_1, DS_2 keep Me_1);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Me_1
1A10
2A30
2B40

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS drop C) 🟢 · any scalar → any type

Manual example 2 🟢 pandas ✅ · DuckDB ✅
Tests:

drop d1#Me_2, the page’s only example of drop, after a filter and a calc, on two operands that both have Me_2.

Manual:

Inner Join, Example 2, output verbatim: “drop will remove all specified non-identifier components of VDS₃”, and then the prefixes of the components that were in several data sets are stripped.

Expected:

the join keeps (1,A) and (1,B); filter Me_1 = "A" keeps (1,A), calc Me_4 := Me_1 || Me_1A gives the Measure AB, and d2#Me_2 becomes Me_2 = Q.

script.vtl
DS_r := inner_join (DS_1 as d1, DS_2 as d2 filter Me_1 = "A" calc Me_4 := Me_1 || Me_1A drop d1#Me_2);
Input DS_1
Id_1Id_2Me_1Me_2
1AAB
1BCD
2AEF
Input DS_2
Id_1Id_2Me_1AMe_2
1ABQ
1BST
3AZM
Expected DS_r
Id_1Id_2Me_1Me_1AMe_2Me_4
1AABQAB

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Drop one measure 🟢 pandas ✅ · DuckDB ✅
Tests:

drop Me_1.

Manual:

Inner Join: “drop will remove all specified non-identifier components of VDS₃”.

Expected:

the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands, with the identifiers and Me_2 only: 1, 3 and 4.

script.vtl
DS_r := inner_join(DS_1, DS_2 drop Me_1);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Me_2
1A1
2A3
2B4

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS rename C to C2) 🟢 · any scalar → any type

Rename measure 🟢 pandas ✅ · DuckDB ✅
Tests:

rename Me_1 to Me_10.

Manual:

Inner Join: rename gives “each specified component with a new name. If the chosen name already exists in VDS₄, an error is raised.”

Expected:

Me_10 is not in VDS₄, so no error: the natural join keeps (1,A), (2,A) and (2,B), the keys in both operands, with Me_10 (10, 30, 40) and Me_2.

script.vtl
DS_r := inner_join(DS_1, DS_2 rename Me_1 to Me_10);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Expected DS_r
Id_1Id_2Me_10Me_2
1A101
2A303
2B404

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

inner_join(DS, DS, DS) 🟢 · any scalar → any type

Manual example 5 🟢 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
Id_1Me_1
1200
2300
3100
Input DS_5
Id_2Id_3Me_2
10S1112345678
20S287654321
30S12118273645
Input DS_6
Id_1Id_2Id_4Me_3
130c
110d
230c
220c
210d
330c
310d50
320d50
Expected DS_r
Id_1Id_21Id_22Me_1Id_31Me_21Id_32Me_22Me_3
13010200S12118273645S1112345678
23010300S12118273645S1112345678
22010300S287654321S1112345678
33010100S12118273645S111234567850
33020100S12118273645S28765432150

Files: script.vtl · input/DS_4.csv · input/DS_4.json · input/DS_5.csv · input/DS_5.json · input/DS_6.csv · input/DS_6.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Three operands 🟢 pandas ✅ · DuckDB ✅
Tests:

a natural inner join of three operands with the same identifiers.

Manual:

Inner Join: the contents “are ideally determined stepwise … joining each of the other input data sets to the partial result”.

Expected:

DS_1 and DS_2 match at (1,A), (2,A) and (2,B), and of these DS_3 has (1,A) and (2,B): two data points, with Me_1, Me_2 and Me_3.

script.vtl
DS_r := inner_join(DS_1, DS_2, DS_3);
Input DS_1
Id_1Id_2Me_1
1A10
1B20
2A30
2B40
Input DS_2
Id_1Id_2Me_2
1A1
1C2
2A3
2B4
Input DS_3
Id_1Id_2Me_3
1A100
2B400
3A500
Expected DS_r
Id_1Id_2Me_1Me_2Me_3
1A101100
2B404400

Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · input/DS_3.csv · input/DS_3.json · expected/DS_r.csv · expected/DS_r.json · example page ↗