Skip to content

Commit 060c4b6

Browse files
committed
Add test for 456 issue
1 parent df765a2 commit 060c4b6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

vtl-engine/src/test/java/fr/insee/vtl/engine/visitors/expression/functions/SetFunctionsVisitorTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import fr.insee.vtl.model.Dataset;
88
import fr.insee.vtl.model.InMemoryDataset;
99
import fr.insee.vtl.model.Structured;
10+
import java.util.Arrays;
1011
import java.util.List;
1112
import java.util.Map;
1213
import java.util.stream.Collectors;
@@ -247,4 +248,36 @@ public void testUnionMultiple() throws ScriptException {
247248
Map.of("name", "Franck2", "age", 12L, "weight", 9L),
248249
Map.of("name", "Hadrien2", "age", 10L, "weight", 11L));
249250
}
251+
252+
@Test
253+
public void testUnion456Issue() throws ScriptException {
254+
InMemoryDataset MULTIMODE =
255+
new InMemoryDataset(
256+
List.of(
257+
new Structured.Component("interrogationId", String.class, Dataset.Role.IDENTIFIER),
258+
new Structured.Component("LOOP", String.class, Dataset.Role.IDENTIFIER),
259+
new Structured.Component("LOOP.FOO1", String.class, Dataset.Role.MEASURE),
260+
new Structured.Component("FOO", String.class, Dataset.Role.MEASURE)),
261+
Arrays.asList("T01", "LOOP-01", "foo11", "foo1"),
262+
Arrays.asList("T01", "LOOP-02", "foo12", "foo1"),
263+
Arrays.asList("T02", null, "foo21", "foo2"));
264+
265+
engine.put("$vtl.engine.use_dag", "false");
266+
ScriptContext context = engine.getContext();
267+
context.getBindings(ScriptContext.ENGINE_SCOPE).put("MULTIMODE", MULTIMODE);
268+
269+
engine.eval(
270+
"TEMP_RACINE := MULTIMODE [keep interrogationId, FOO];\n"
271+
+ "RACINE := union(TEMP_RACINE, TEMP_RACINE) ;\n"
272+
+ "TEMP_LOOP := MULTIMODE [keep interrogationId, LOOP, LOOP.FOO1]\n"
273+
+ " [filter LOOP <> \"\"]\n"
274+
+ " [rename LOOP.FOO1 to FOO1];\n"
275+
+ "LOOP := union(TEMP_LOOP, TEMP_LOOP);");
276+
277+
Object result = engine.getContext().getAttribute("LOOP");
278+
assertThat(result).isInstanceOf(Dataset.class);
279+
assertThat(((Dataset) result).getDataAsList().size()).isEqualTo(2);
280+
assertThat(((Dataset) result).getDataAsList().stream().map(l -> l.get(1)))
281+
.isEqualTo(List.of("LOOP-01", "LOOP-02"));
282+
}
250283
}

0 commit comments

Comments
 (0)