|
29 | 29 | import org.junit.jupiter.api.Assertions; |
30 | 30 | import org.junit.jupiter.api.Test; |
31 | 31 |
|
| 32 | +import java.util.ArrayList; |
32 | 33 | import java.util.Arrays; |
33 | 34 | import java.util.Collections; |
34 | 35 | import java.util.HashMap; |
@@ -189,6 +190,38 @@ public void testBuildThriftParam() { |
189 | 190 | Assertions.assertEquals("content", param.field_bindings.get(1).field_name); |
190 | 191 | } |
191 | 192 |
|
| 193 | + @Test |
| 194 | + public void testNestedAliasUsesPhysicalOwnerAndFullArrayPath() { |
| 195 | + String dsl = "NESTED(doc.items, msg:hello AND tags.name:world)"; |
| 196 | + SearchDslParser.QsPlan plan = SearchDslParser.parseDsl(dsl); |
| 197 | + for (List<String> prefix : Arrays.asList(Collections.<String>emptyList(), Arrays.asList("payload"))) { |
| 198 | + List<String> messagePath = new ArrayList<>(prefix); |
| 199 | + messagePath.addAll(Arrays.asList("items", "msg")); |
| 200 | + List<String> tagPath = new ArrayList<>(prefix); |
| 201 | + tagPath.addAll(Arrays.asList("items", "tags", "name")); |
| 202 | + SearchPredicate predicate = new SearchPredicate(dsl, plan, Arrays.asList( |
| 203 | + createVariantSlot("v", messagePath.toArray(new String[0])), |
| 204 | + createVariantSlot("v", tagPath.toArray(new String[0]))), false); |
| 205 | + TSearchParam param = ExprToThriftVisitor.buildSearchThriftParam(predicate); |
| 206 | + Assertions.assertEquals(prefix.isEmpty() ? "v.items" : "v.payload.items", param.root.nested_path); |
| 207 | + Assertions.assertEquals("doc.items.msg", param.field_bindings.get(0).field_name); |
| 208 | + Assertions.assertEquals("doc.items.tags.name", param.field_bindings.get(1).field_name); |
| 209 | + Assertions.assertEquals("doc.items", plan.getRoot().getNestedPath()); |
| 210 | + } |
| 211 | + } |
| 212 | + |
| 213 | + @Test |
| 214 | + public void testNestedAliasRetainsUnmaterializedPath() { |
| 215 | + String dsl = "NESTED(doc.items, msg:hello)"; |
| 216 | + Expr child = new FunctionCallExpr("element_at", |
| 217 | + Arrays.asList(createVariantSlot("v", "payload"), new StringLiteral("items.msg")), true); |
| 218 | + SearchPredicate predicate = new SearchPredicate(dsl, SearchDslParser.parseDsl(dsl), |
| 219 | + Arrays.asList(child), false); |
| 220 | + TSearchParam param = ExprToThriftVisitor.buildSearchThriftParam(predicate); |
| 221 | + Assertions.assertEquals("v.payload.items", param.root.nested_path); |
| 222 | + Assertions.assertEquals("doc.items.msg", param.field_bindings.get(0).field_name); |
| 223 | + } |
| 224 | + |
192 | 225 | @Test |
193 | 226 | public void testNestedRelativeFieldsAreNormalizedBeforeThrift() { |
194 | 227 | String dsl = "NESTED(data.items, msg:hello AND meta.channel:action)"; |
|
0 commit comments