Skip to content

Commit

Permalink
Fixing bug for missing collection values not showing as null.
Browse files Browse the repository at this point in the history
Signed-off-by: forestmvey <forestv@bitquilltech.com>
  • Loading branch information
forestmvey committed Apr 5, 2023
1 parent 8526ef1 commit 3ff9fdd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import org.opensearch.sql.expression.NamedExpression;
import org.opensearch.sql.expression.ReferenceExpression;

/**
* Logical Nested plan.
*/
@EqualsAndHashCode(callSuper = true)
@Getter
@ToString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.opensearch.sql.data.model.ExprCollectionValue;
import org.opensearch.sql.data.model.ExprNullValue;
import org.opensearch.sql.data.model.ExprTupleValue;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.expression.ReferenceExpression;
Expand Down Expand Up @@ -256,6 +257,7 @@ private void getNested(
currentObj = currentMap.tupleValue().get(splitKeys[0]);
} else {
currentObj = null;
ret.add(new LinkedHashMap<>(Map.of(field, ExprNullValue.of())));
}
} else if (currentObj instanceof ExprCollectionValue) {
ExprValue arrayObj = currentObj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opensearch.sql.data.model.ExprNullValue;
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.expression.ReferenceExpression;

Expand Down Expand Up @@ -57,12 +58,9 @@ class NestedOperatorTest extends PhysicalPlanTestBase {
"message",
collectionValue(
List.of(
Map.of("info", "a"),
Map.of("info", "b"),
Map.of("info", "c"),
Map.of("id", "1"),
Map.of("id", "2"),
Map.of("id", "3")
Map.of("info", "a", "id", "1"),
Map.of("info", "b", "id", "2"),
Map.of("info", "c", "id", "3")
)
)
)
Expand Down Expand Up @@ -304,11 +302,11 @@ public void nested_missing_tuple_field() {
Set<String> fields = Set.of("message.val");
Map<String, List<String>> groupedFieldsByPath =
Map.of("message", List.of("message.val"));
assertTrue(
execute(new NestedOperator(inputPlan, fields, groupedFieldsByPath))
.get(0)
.tupleValue()
.size() == 0
assertThat(
execute(new NestedOperator(inputPlan, fields, groupedFieldsByPath)),
contains(
tupleValue(new LinkedHashMap<>(Map.of("message.val", ExprNullValue.of())))
)
);
}

Expand Down

0 comments on commit 3ff9fdd

Please sign in to comment.