Skip to content

Commit

Permalink
Re-add nested tests into core
Browse files Browse the repository at this point in the history
Signed-off-by: acarbonetto <[email protected]>
  • Loading branch information
acarbonetto committed Aug 22, 2023
1 parent 32ce604 commit 4c582d0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,59 +106,75 @@ public void visit_should_return_default_physical_operator() {
ImmutablePair.of(Sort.SortOption.DEFAULT_ASC, ref("name1", STRING));
Integer limit = 1;
Integer offset = 1;
List<Map<String, ReferenceExpression>> nestedArgs =
List.of(
Map.of(
"field", new ReferenceExpression("message.info", STRING),
"path", new ReferenceExpression("message", STRING)));
List<NamedExpression> nestedProjectList =
List.of(
new NamedExpression("message.info", DSL.nested(DSL.ref("message.info", STRING)), null));
Set<String> nestedOperatorArgs = Set.of("message.info");
Map<String, List<String>> groupedFieldsByPath = Map.of("message", List.of("message.info"));

LogicalPlan plan =
project(
limit(
LogicalPlanDSL.dedupe(
rareTopN(
sort(
eval(
remove(
rename(
aggregation(
filter(values(emptyList()), filterExpr),
aggregators,
groupByExprs),
mappings),
exclude),
newEvalField),
sortField),
CommandType.TOP,
topByExprs,
rareTopNField),
dedupeField),
limit,
offset),
nested(
limit(
LogicalPlanDSL.dedupe(
rareTopN(
sort(
eval(
remove(
rename(
aggregation(
filter(values(emptyList()), filterExpr),
aggregators,
groupByExprs),
mappings),
exclude),
newEvalField),
sortField),
CommandType.TOP,
topByExprs,
rareTopNField),
dedupeField),
limit,
offset),
nestedArgs,
nestedProjectList),
include);

PhysicalPlan actual = plan.accept(implementor, null);

assertEquals(
PhysicalPlanDSL.project(
PhysicalPlanDSL.limit(
PhysicalPlanDSL.dedupe(
PhysicalPlanDSL.rareTopN(
PhysicalPlanDSL.sort(
PhysicalPlanDSL.eval(
PhysicalPlanDSL.remove(
PhysicalPlanDSL.rename(
PhysicalPlanDSL.agg(
PhysicalPlanDSL.filter(
PhysicalPlanDSL.values(emptyList()),
filterExpr),
aggregators,
groupByExprs),
mappings),
exclude),
newEvalField),
sortField),
CommandType.TOP,
topByExprs,
rareTopNField),
dedupeField),
limit,
offset),
PhysicalPlanDSL.nested(
PhysicalPlanDSL.limit(
PhysicalPlanDSL.dedupe(
PhysicalPlanDSL.rareTopN(
PhysicalPlanDSL.sort(
PhysicalPlanDSL.eval(
PhysicalPlanDSL.remove(
PhysicalPlanDSL.rename(
PhysicalPlanDSL.agg(
PhysicalPlanDSL.filter(
PhysicalPlanDSL.values(emptyList()),
filterExpr),
aggregators,
groupByExprs),
mappings),
exclude),
newEvalField),
sortField),
CommandType.TOP,
topByExprs,
rareTopNField),
dedupeField),
limit,
offset),
nestedOperatorArgs,
groupedFieldsByPath),
include),
actual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ public TableWriteOperator build(PhysicalPlan child) {
LogicalPlan ml = new LogicalML(relation, Map.of());
LogicalPlan paginate = new LogicalPaginate(42, List.of(relation));

List<Map<String, ReferenceExpression>> nestedArgs =
List.of(
Map.of(
"field", new ReferenceExpression("message.info", STRING),
"path", new ReferenceExpression("message", STRING)));
List<NamedExpression> projectList =
List.of(
new NamedExpression("message.info", DSL.nested(DSL.ref("message.info", STRING)), null));

LogicalNested nested = new LogicalNested(null, nestedArgs, projectList);

LogicalFetchCursor cursor = new LogicalFetchCursor("n:test", mock(StorageEngine.class));

LogicalCloseCursor closeCursor = new LogicalCloseCursor(cursor);
Expand All @@ -150,6 +161,7 @@ public TableWriteOperator build(PhysicalPlan child) {
ad,
ml,
paginate,
nested,
cursor,
closeCursor)
.map(Arguments::of);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.opensearch.sql.ast.tree.Sort;
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.expression.DSL;
import org.opensearch.sql.expression.NamedExpression;
import org.opensearch.sql.expression.ReferenceExpression;
import org.opensearch.sql.planner.logical.LogicalPaginate;
import org.opensearch.sql.planner.logical.LogicalPlan;
Expand Down Expand Up @@ -217,7 +218,9 @@ void table_scan_builder_support_nested_push_down_can_apply_its_rule() {
nested(
relation("schema", table),
List.of(Map.of("field", new ReferenceExpression("message.info", STRING))),
List.of())));
List.of(
new NamedExpression(
"message.info", DSL.nested(DSL.ref("message.info", STRING)), null)))));
}

@Test
Expand Down

0 comments on commit 4c582d0

Please sign in to comment.