|
7 | 7 | import fr.insee.vtl.model.Dataset; |
8 | 8 | import fr.insee.vtl.model.InMemoryDataset; |
9 | 9 | import fr.insee.vtl.model.Structured; |
| 10 | +import java.util.Arrays; |
10 | 11 | import java.util.List; |
11 | 12 | import java.util.Map; |
12 | 13 | import java.util.stream.Collectors; |
@@ -247,4 +248,36 @@ public void testUnionMultiple() throws ScriptException { |
247 | 248 | Map.of("name", "Franck2", "age", 12L, "weight", 9L), |
248 | 249 | Map.of("name", "Hadrien2", "age", 10L, "weight", 11L)); |
249 | 250 | } |
| 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 | + } |
250 | 283 | } |
0 commit comments