From 927230a8e135f4cc154a95cb762bcce786a323d2 Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Wed, 19 Oct 2022 14:26:07 -0700 Subject: [PATCH] add unit tests Signed-off-by: Joshua Li --- .../planner/physical/ProjectOperatorTest.java | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/opensearch/sql/planner/physical/ProjectOperatorTest.java b/core/src/test/java/org/opensearch/sql/planner/physical/ProjectOperatorTest.java index 3fa312d4c2..24be5eb2b8 100644 --- a/core/src/test/java/org/opensearch/sql/planner/physical/ProjectOperatorTest.java +++ b/core/src/test/java/org/opensearch/sql/planner/physical/ProjectOperatorTest.java @@ -118,7 +118,26 @@ public void project_fields_with_parse_expressions() { DSL.literal("action"))), DSL.named("response", DSL.regex(DSL.ref("response", STRING), DSL.literal("(?\\w+) (?\\d+)"), - DSL.literal("response"))), DSL.named("ignored", + DSL.literal("response")))) + ); + List result = execute(plan); + + assertThat( + result, + allOf( + iterableWithSize(1), + hasItems( + ExprValueUtils.tupleValue(ImmutableMap.of("action", "GET", "response", "200"))))); + } + + @Test + public void project_fields_with_unused_parse_expressions() { + when(inputPlan.hasNext()).thenReturn(true, false); + when(inputPlan.next()) + .thenReturn(ExprValueUtils.tupleValue(ImmutableMap.of("response", "GET 200"))); + PhysicalPlan plan = + project(inputPlan, ImmutableList.of(DSL.named("response", DSL.ref("response", STRING))), + ImmutableList.of(DSL.named("ignored", DSL.regex(DSL.ref("response", STRING), DSL.literal("(?\\w+) (?\\d+)"), DSL.literal("ignored")))) @@ -130,7 +149,33 @@ public void project_fields_with_parse_expressions() { allOf( iterableWithSize(1), hasItems( - ExprValueUtils.tupleValue(ImmutableMap.of("action", "GET", "response", "200"))))); + ExprValueUtils.tupleValue(ImmutableMap.of("response", "GET 200"))))); + } + + @Test + public void project_fields_with_parse_expressions_and_runtime_fields() { + when(inputPlan.hasNext()).thenReturn(true, false); + when(inputPlan.next()) + .thenReturn( + ExprValueUtils.tupleValue(ImmutableMap.of("response", "GET 200", "eval_field", 1))); + PhysicalPlan plan = + project(inputPlan, ImmutableList.of(DSL.named("response", DSL.ref("response", STRING)), + DSL.named("action", DSL.ref("action", STRING)), + DSL.named("eval_field", DSL.ref("eval_field", INTEGER))), + ImmutableList.of(DSL.named("action", + DSL.regex(DSL.ref("response", STRING), + DSL.literal("(?\\w+) (?\\d+)"), + DSL.literal("action")))) + ); + List result = execute(plan); + + assertThat( + result, + allOf( + iterableWithSize(1), + hasItems( + ExprValueUtils.tupleValue( + ImmutableMap.of("response", "GET 200", "action", "GET", "eval_field", 1))))); } @Test