|
17 | 17 | import java.util.Set;
|
18 | 18 |
|
19 | 19 | import static java.util.stream.Collectors.toList;
|
| 20 | +import static org.elasticsearch.xpack.ql.TestUtils.fieldAttribute; |
| 21 | +import static org.elasticsearch.xpack.ql.TestUtils.of; |
20 | 22 | import static org.hamcrest.Matchers.arrayContaining;
|
21 | 23 | import static org.hamcrest.Matchers.arrayWithSize;
|
22 | 24 | import static org.hamcrest.Matchers.contains;
|
@@ -61,6 +63,35 @@ public void testAttributeMapWithSameAliasesCanResolveAttributes() {
|
61 | 63 | assertTrue(newAttributeMap.get(param2.toAttribute()) == param2.child());
|
62 | 64 | }
|
63 | 65 |
|
| 66 | + public void testResolveRecursively() { |
| 67 | + AttributeMap.Builder<Object> builder = AttributeMap.builder(); |
| 68 | + Attribute one = a("one"); |
| 69 | + Attribute two = fieldAttribute("two", DataTypes.INTEGER); |
| 70 | + Attribute three = fieldAttribute("three", DataTypes.INTEGER); |
| 71 | + Alias threeAlias = new Alias(Source.EMPTY, "three_alias", three); |
| 72 | + Alias threeAliasAlias = new Alias(Source.EMPTY, "three_alias_alias", threeAlias); |
| 73 | + builder.put(one, of("one")); |
| 74 | + builder.put(two, "two"); |
| 75 | + builder.put(three, of("three")); |
| 76 | + builder.put(threeAlias.toAttribute(), threeAlias.child()); |
| 77 | + builder.put(threeAliasAlias.toAttribute(), threeAliasAlias.child()); |
| 78 | + AttributeMap<Object> map = builder.build(); |
| 79 | + |
| 80 | + assertEquals(of("one"), map.get(one)); |
| 81 | + assertEquals(map.get(one), map.getOrDefault(one, null)); |
| 82 | + assertEquals("two", map.get(two)); |
| 83 | + assertEquals(map.get(two), map.getOrDefault(two, null)); |
| 84 | + assertEquals(of("three"), map.get(three)); |
| 85 | + assertEquals(map.get(three), map.getOrDefault(three, null)); |
| 86 | + assertEquals(map.get(three), map.getOrDefault(threeAlias, null)); |
| 87 | + assertEquals(map.get(three), map.get(threeAlias)); |
| 88 | + assertEquals(map.get(three), map.getOrDefault(threeAliasAlias, null)); |
| 89 | + assertEquals(map.get(three), map.get(threeAliasAlias)); |
| 90 | + Attribute four = a("four"); |
| 91 | + assertEquals("not found", map.getOrDefault(four, "not found")); |
| 92 | + assertNull(map.get(four)); |
| 93 | + } |
| 94 | + |
64 | 95 | private Alias createIntParameterAlias(int index, int value) {
|
65 | 96 | Source source = new Source(1, index * 5, "?");
|
66 | 97 | Literal literal = new Literal(source, value, DataTypes.INTEGER);
|
|
0 commit comments