Cross Join · cross_join
---
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["Cross Join · cross_join 📌<br/>🟢21"]:::ok
v_bare["cross_join(DS, DS)"]:::ok
v_aliases["cross_join(DS as a, DS as b)"]:::ok
v_filter["cross_join(DS, DS filter cond)"]:::ok
v_apply["cross_join(DS, DS apply expr)"]:::ok
v_calc_default["cross_join(DS, DS calc C #58;#61; expr) 📌"]:::ok
v_calc_measure["cross_join(DS, DS calc measure C #58;#61; expr)"]:::ok
v_calc_identifier["cross_join(DS, DS calc identifier C #58;#61; expr)"]:::ok
v_calc_attribute["cross_join(DS, DS calc attribute C #58;#61; expr)"]:::ok
v_calc_viral_attribute["cross_join(DS, DS calc viral attribute C #58;#61; expr) 📌"]:::ok
v_aggr_no_group["cross_join(DS, DS aggr C #58;#61; agg)"]:::ok
v_aggr_group_by["cross_join(DS, DS aggr C #58;#61; agg group by Id) 📌"]:::ok
v_aggr_group_except["cross_join(DS, DS aggr C #58;#61; agg group except Id)"]:::ok
v_aggr_group_all["cross_join(DS, DS aggr C #58;#61; agg group all time_agg(p))"]:::ok
v_aggr_having["cross_join(DS, DS aggr C #58;#61; agg group by Id having cond)"]:::ok
v_aggr_measure["cross_join(DS, DS aggr measure C #58;#61; agg group by Id)"]:::ok
v_aggr_attribute["cross_join(DS, DS aggr C #58;#61; agg, attribute A #58;#61; agg group by Id)"]:::ok
v_aggr_viral_attribute["cross_join(DS, DS aggr C #58;#61; agg, viral attribute A #58;#61; agg group by Id) 📌"]:::ok
v_keep["cross_join(DS, DS keep C)"]:::ok
v_drop["cross_join(DS, DS drop C)"]:::ok
v_rename["cross_join(DS, DS rename C to C2)"]:::ok
v_nary["cross_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_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_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
Comes from: any operator that returns a value
Goes to: whatever takes its input's type
Forms
cross_join(DS, DS) 🟢 · any scalar → any type
Cartesian product 🟢 pandas ✅ · DuckDB ✅
- Tests:
the cross join, with no clause, of two operands with no common component, so the product needs no alias.
- Manual:
Cross Join: it performs “a cartesian product of the input operands”, and “In each step, a data point in VDS₁ is generated for each pair of data points in the partial result and the joined data set”.
- Expected:
the cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points,(1,A),(1,B),(2,A)and(2,B), with each component once, under its name and role.
DS_r := cross_join(DS_1, DS_2);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 1 | A | 10 | 1 |
| 1 | B | 10 | 2 |
| 2 | A | 20 | 1 |
| 2 | B | 20 | 2 |
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 ↗
Expression without alias 🟢 pandas ✅ · DuckDB ✅
- Tests:
a cross join of
DS_1and the expressionDS_2 [filter Me_1 > 0], with no alias; both haveMe_1.- Manual:
Cross Join: the components of several data sets are prefixed with the alias, else with “the data set name”, and the aliases “are mandatory … for non-named data set obtained as result of a sub-expression”.
- Expected:
the error
1-1-13-2, “the operand {operand} needs an alias”: the expression is a non-named data set with no alias, andMe_1, in both operands, needs a prefix.
DS_r := cross_join(DS_1, DS_2 [filter Me_1 > 0]);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_1 |
|---|---|
| A | 1 |
| B | 2 |
Expected error 1-1-13-2: At op {op}: the operand {operand} needs an alias. Aliases are mandatory for the result of a sub-expression and for a Data Set that appears more than once in the join.
Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/error.json · example page ↗
cross_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:
Cross 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 Cartesian product, the four pairs
(1,A),(1,B),(2,A)and(2,B).
DS_r := cross_join(DS_1 as d1, DS_2 as d2);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 1 | A | 10 | 1 |
| 1 | B | 10 | 2 |
| 2 | A | 20 | 1 |
| 2 | B | 20 | 2 |
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_1of 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:
Cross Join: the components of 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 cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points:Me_11holds the values ofDS_1(10, 10, 20, 20) andMe_12those ofDS_2(1, 2, 1, 2). An engine that swapped the aliases would swap the columns.
DS_r := cross_join(DS_1 as d1, DS_2 as d2 rename d1#Me_1 to Me_11, d2#Me_1 to Me_12);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_1 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Me_11 | Me_12 |
|---|---|---|---|
| 1 | A | 10 | 1 |
| 1 | B | 10 | 2 |
| 2 | A | 20 | 1 |
| 2 | B | 20 | 2 |
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 ↗
cross_join(DS, DS filter cond) 🟢 · any scalar, boolean → any type
Filter on measure 🟢 pandas ✅ · DuckDB ✅
- Tests:
filter Me_1 > 15on the pairs of the product.- Manual:
Cross 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:
the cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points; the two withId_1= 2 (Me_1= 20) are kept:(2,A)and(2,B).
DS_r := cross_join(DS_1, DS_2 filter Me_1 > 15);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 2 | A | 20 | 1 |
| 2 | B | 20 | 2 |
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 ↗
cross_join(DS, DS apply expr) 🟢 · any scalar → any type
Sum of homonym measures 🟢 pandas ✅ · DuckDB ✅
- Tests:
apply DS_1 + DS_2, written with the data set names, on the homonym measureMe_1.- Manual:
Cross 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 cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points, withDS_1#Me_1andDS_2#Me_1:Me_1is 11, 12, 21 and 22.
DS_r := cross_join(DS_1, DS_2 apply DS_1 + DS_2);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_1 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | 11 |
| 1 | B | 12 |
| 2 | A | 21 |
| 2 | B | 22 |
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 ↗
cross_join(DS, DS calc C := expr) 🟢 · any scalar → any type
Default role is measure 🟢 pandas ✅ · DuckDB ✅
- Tests:
calc Me_3 := Me_1 + Me_2with no role.- Manual:
Cross 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 cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points.Me_3is a Measure, as in Explicit measure role of thecalc_measureform: 11, 12, 21 and 22.
DS_r := cross_join(DS_1, DS_2 calc Me_3 := Me_1 + Me_2);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|
| 1 | A | 10 | 1 | 11 |
| 1 | B | 10 | 2 | 12 |
| 2 | A | 20 | 1 | 21 |
| 2 | B | 20 | 2 | 22 |
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 ofDS_1, recalculated under its own name, with the role left out.- Manual:
Cross 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(error1-1-1-10); in calc, “if the role is not specified, it will be measure”.- Expected:
the cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points, andAt_1is a Measure:ax,ax,bxandbx.- 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”.
DS_r := cross_join(DS_1, DS_2 calc At_1 := At_1 || "x");
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | a |
| 2 | 20 | b |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Me_1 | Me_2 | At_1 |
|---|---|---|---|---|
| 1 | A | 10 | 1 | ax |
| 1 | B | 10 | 2 | ax |
| 2 | A | 20 | 1 | bx |
| 2 | B | 20 | 2 | bx |
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 ↗
cross_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:
Cross Join: “calc calculates new components by independent sub-expressions evaluated at component level. The role of the new components can be specified”.
- Expected:
the cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points. The input components stay andMe_3is added: 11, 12, 21 and 22.
DS_r := cross_join(DS_1, DS_2 calc measure Me_3 := Me_1 + Me_2);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|
| 1 | A | 10 | 1 | 11 |
| 1 | B | 10 | 2 | 12 |
| 2 | A | 20 | 1 | 21 |
| 2 | B | 20 | 2 | 22 |
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 ↗
cross_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:
Cross Join: “The role of the new components can be specified”;
Id_3is new, so no identifier of the input is overwritten.- Expected:
the cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points; each getsId_3=Xand the keys stay unique. A constant is never null, so the decision of #1010 (1-1-1-16for an identifier calculated from a declared-nullable expression) does not apply.
DS_r := cross_join(DS_1, DS_2 calc identifier Id_3 := "X");
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Id_3 | Me_1 | Me_2 |
|---|---|---|---|---|
| 1 | A | X | 10 | 1 |
| 1 | B | X | 10 | 2 |
| 2 | A | X | 20 | 1 |
| 2 | B | X | 20 | 2 |
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 ↗
cross_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:
Cross 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 cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points, and each gets the String AttributeAt_1=EP.
DS_r := cross_join(DS_1, DS_2 calc attribute At_1 := "EP");
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Me_1 | Me_2 | At_1 |
|---|---|---|---|---|
| 1 | A | 10 | 1 | EP |
| 1 | B | 10 | 2 | EP |
| 2 | A | 20 | 1 | EP |
| 2 | B | 20 | 2 | EP |
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 ↗
cross_join(DS, DS aggr C := agg) 🟢 · any scalar → any type
Sum without grouping 🟢 pandas ✅ · DuckDB ✅
- Tests:
aggrwith no grouping clause.- Manual:
Cross 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:
the cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points, so one data point with no identifier:Me_3= 10 + 10 + 20 + 20 = 60.
DS_r := cross_join(DS_1, DS_2 aggr Me_3 := sum(Me_1));
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Me_3 |
|---|
| 60 |
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 ↗
cross_join(DS, DS aggr C := agg group by Id) 🟢 · any scalar → any type
Sum by id 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
aggrwithgroup by Id_1, which dropsId_2.- Manual:
Cross 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 cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points:Me_3is 10 + 10 = 20 forId_1= 1 and 20 + 20 = 40 forId_1= 2.
DS_r := cross_join(DS_1, DS_2 aggr Me_3 := sum(Me_1) group by Id_1);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Me_3 |
|---|---|
| 1 | 20 |
| 2 | 40 |
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 ofDS_1, aggregated under its own name, with the role left out.- Manual:
Cross 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(error1-1-1-10); in aggr, “if the role is not specified, it will be measure”.- Expected:
the cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 4 data points, andAt_1is a String Measure:aforId_1= 1 andbforId_1= 2.- 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”.
DS_r := cross_join(DS_1, DS_2 aggr At_1 := max(At_1) group by Id_1);
| Id_1 | Me_1 | At_1 |
|---|---|---|
| 1 | 10 | a |
| 2 | 20 | b |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | At_1 |
|---|---|
| 1 | a |
| 2 | b |
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 ↗
cross_join(DS, DS aggr C := agg group except Id) 🟢 · any scalar → any type
Sum except id 2 🟢 pandas ✅ · DuckDB ✅
- Tests:
aggrwithgroup except Id_2, which groups byId_1.- Manual:
Cross 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 cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points; the groups are those ofgroup by Id_1:Me_3is 20 forId_1= 1 and 40 forId_1= 2.
DS_r := cross_join(DS_1, DS_2 aggr Me_3 := sum(Me_1) group except Id_2);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Me_3 |
|---|---|
| 1 | 20 |
| 2 | 40 |
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 ↗
cross_join(DS, DS aggr C := agg group all time_agg(p)) 🟢 · any scalar → any type
Quarters to years 🟢 pandas ✅ · DuckDB ✅
- Tests:
aggrwith the deprecatedgroup all time_agg("A")on the quarters ofDS_1(2010Q1,2010Q2,2011Q1), crossed withDS_2(Id_2A, B).- Manual:
Cross 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
2010Q1into2010.- Expected:
the product has 3 × 2 = 6 data points, and the result keeps
Id_1, as years, andId_2:(2010, A)and(2010, B)giveMe_3= 10 + 20 = 30,(2011, A)and(2011, B)give 40.
DS_r := cross_join(DS_1, DS_2 aggr Me_3 := sum(Me_1) group all time_agg("A"));
| Id_1 | Me_1 |
|---|---|
| 2010Q1 | 10 |
| 2010Q2 | 20 |
| 2011Q1 | 40 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Me_3 |
|---|---|---|
| 2010 | A | 30 |
| 2010 | B | 30 |
| 2011 | A | 40 |
| 2011 | B | 40 |
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 ↗
cross_join(DS, DS aggr C := agg group by Id having cond) 🟢 · any scalar, boolean → any type
Having min above 15 🟢 pandas ✅ · DuckDB ✅
- Tests:
aggrbyId_1withhaving min(Me_1) > 15.- Manual:
Cross Join, and Aggregate invocation: “only groups for which havingCondition evaluates to true appear in the result”, and the condition “must invoke aggregate operators” (
minhere, which the reading of #1119 also allows).- Expected:
the cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points. The smallestMe_1ofId_1= 1 is 10, so onlyId_1= 2 is kept, withMe_3= 40.
DS_r := cross_join(DS_1, DS_2 aggr Me_3 := sum(Me_1) group by Id_1 having min(Me_1) > 15);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Me_3 |
|---|---|
| 2 | 40 |
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 ↗
cross_join(DS, DS aggr measure C := agg group by Id) 🟢 · any scalar → any type
Explicit measure role 🟢 pandas ✅ · DuckDB ✅
- Tests:
aggrwith the role keywordmeasurewritten out.- Manual:
Cross 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_3is 20 forId_1= 1 and 40 forId_1= 2.
DS_r := cross_join(DS_1, DS_2 aggr measure Me_3 := sum(Me_1) group by Id_1);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Me_3 |
|---|---|
| 1 | 20 |
| 2 | 40 |
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 ↗
cross_join(DS, DS aggr C := agg, attribute A := agg group by Id) 🟢 · any scalar → any type
Max as attribute 🟢 pandas ✅ · DuckDB ✅
- Tests:
aggrwith two components: the sum ofMe_1byId_1as the measureMe_3, and its maximum asAt_1, with the roleattribute, as in the page’s syntax exampleaggr Me1 := sum(Me1), attribute At20 := avg(Me2).- Manual:
Cross 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 cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points:Id_1= 1 groupsMe_110 twice, givingMe_3= 20 andAt_1= 10, andId_1= 2 gives 40 and 20.At_1is a Number Attribute.
DS_r := cross_join(DS_1, DS_2 aggr Me_3 := sum(Me_1), attribute At_1 := max(Me_1) group by Id_1);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Me_3 | At_1 |
|---|---|---|
| 1 | 20 | 10 |
| 2 | 40 | 20 |
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 ↗
cross_join(DS, DS keep C) 🟢 · any scalar → any type
Keep one measure 🟢 pandas ✅ · DuckDB ✅
- Tests:
keep Me_1.- Manual:
Cross Join: “keep will maintain all the identifiers and only the specified non-identifier components of VDS₃”.
- Expected:
the cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points, withMe_1only: 10, 10, 20 and 20.
DS_r := cross_join(DS_1, DS_2 keep Me_1);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| 1 | A | 10 |
| 1 | B | 10 |
| 2 | A | 20 |
| 2 | B | 20 |
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 ↗
cross_join(DS, DS drop C) 🟢 · any scalar → any type
Drop one measure 🟢 pandas ✅ · DuckDB ✅
- Tests:
drop Me_1.- Manual:
Cross Join: “drop will remove all specified non-identifier components of VDS₃”.
- Expected:
the cartesian product of
DS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points, with the identifiers andMe_2only: 1, 2, 1 and 2.
DS_r := cross_join(DS_1, DS_2 drop Me_1);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Me_2 |
|---|---|---|
| 1 | A | 1 |
| 1 | B | 2 |
| 2 | A | 1 |
| 2 | B | 2 |
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 ↗
cross_join(DS, DS rename C to C2) 🟢 · any scalar → any type
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
renames, through the aliases, of the four identifiers and of
d1#Me_2, on two operands that both haveId_1,Id_2andMe_2.- Manual:
Cross Join, Example 1, output verbatim: “a data point in VDS₁ is generated for each pair of data points in the partial result and the joined data set”, and the prefixes of the components of several data sets are stripped at the end.
- Expected:
3 × 3 = 9 data points with
Id_11,Id_12,Id_21,Id_22,Me_1,Me_12,Me_1AandMe_2(d2#Me_2stripped). Without the renames, the stripping would give twoId_1,Id_2andMe_2, an error.
DS_r := cross_join (DS_1 as d1, DS_2 as d2 rename d1#Id_1 to Id_11, d1#Id_2 to Id_12, d2#Id_1 to Id_21, d2#Id_2 to Id_22, d1#Me_2 to Me_12 );
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 1 | A | A | B |
| 1 | B | C | D |
| 2 | A | E | F |
| Id_1 | Id_2 | Me_1A | Me_2 |
|---|---|---|---|
| 1 | A | B | Q |
| 1 | B | S | T |
| 3 | A | Z | M |
| Id_11 | Id_12 | Id_21 | Id_22 | Me_1 | Me_12 | Me_1A | Me_2 |
|---|---|---|---|---|---|---|---|
| 1 | A | 1 | A | A | B | B | Q |
| 1 | A | 1 | B | A | B | S | T |
| 1 | A | 3 | A | A | B | Z | M |
| 1 | B | 1 | A | C | D | B | Q |
| 1 | B | 1 | B | C | D | S | T |
| 1 | B | 3 | A | C | D | Z | M |
| 2 | A | 1 | A | E | F | B | Q |
| 2 | A | 1 | B | E | F | S | T |
| 2 | A | 3 | A | E | F | Z | M |
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 ↗
Rename measure 🟢 pandas ✅ · DuckDB ✅
- Tests:
rename Me_1 to Me_10.- Manual:
Cross Join: rename gives “each specified component with a new name. If the chosen name already exists in VDS₄, an error is raised.”
- Expected:
Me_10is not in VDS₄, so no error: the cartesian product ofDS_1(Id_11, 2) andDS_2(Id_2A, B) has 2 × 2 = 4 data points, withMe_10(10, 10, 20, 20) andMe_2.
DS_r := cross_join(DS_1, DS_2 rename Me_1 to Me_10);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_1 | Id_2 | Me_10 | Me_2 |
|---|---|---|---|
| 1 | A | 10 | 1 |
| 1 | B | 10 | 2 |
| 2 | A | 20 | 1 |
| 2 | B | 20 | 2 |
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 ↗
cross_join(DS, DS, DS) 🟢 · any scalar → any type
Three operands 🟢 pandas ✅ · DuckDB ✅
- Tests:
a cross join of three operands with no common component.
- Manual:
Cross Join: “In each step, a data point in VDS₁ is generated for each pair of data points in the partial result and the joined data set”, and “the step is repeated by joining this partial result to the next data set”.
- Expected:
DS_3hasId_3P and Q: 2 × 2 × 2 = 8 data points, withId_1,Id_2,Id_3and the three measures.
DS_r := cross_join(DS_1, DS_2, DS_3);
| Id_1 | Me_1 |
|---|---|
| 1 | 10 |
| 2 | 20 |
| Id_2 | Me_2 |
|---|---|
| A | 1 |
| B | 2 |
| Id_3 | Me_3 |
|---|---|
| P | 100 |
| Q | 200 |
| Id_1 | Id_2 | Id_3 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|---|
| 1 | A | P | 10 | 1 | 100 |
| 1 | A | Q | 10 | 1 | 200 |
| 1 | B | P | 10 | 2 | 100 |
| 1 | B | Q | 10 | 2 | 200 |
| 2 | A | P | 20 | 1 | 100 |
| 2 | A | Q | 20 | 1 | 200 |
| 2 | B | P | 20 | 2 | 100 |
| 2 | B | Q | 20 | 2 | 200 |
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 ↗