Skip to content

Commit 0327b3f

Browse files
committed
Add a error case for accessing different levels of nested objects in scripts
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 8bf28be commit 0327b3f

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteWhereCommandIT.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import static org.opensearch.sql.util.MatcherUtils.rows;
1212
import static org.opensearch.sql.util.MatcherUtils.schema;
1313
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;
14+
import static org.opensearch.sql.util.MatcherUtils.verifyErrorMessageContains;
1415
import static org.opensearch.sql.util.MatcherUtils.verifySchema;
1516

1617
import java.io.IOException;
@@ -81,6 +82,8 @@ public void testFilterOnNestedFields() throws IOException {
8182

8283
@Test
8384
public void testFilterOnMultipleCascadedNestedFields() throws IOException {
85+
// SQL's static type system does not allow returning list[int] in place of int
86+
enabledOnlyWhenPushdownIsEnabled();
8487
JSONObject result =
8588
executeQuery(
8689
String.format(
@@ -119,4 +122,22 @@ public void testFilterOnMultipleCascadedNestedFields() throws IOException {
119122
"comment",
120123
"Too slow in places"))))));
121124
}
125+
126+
@Test
127+
public void testScriptFilterOnDifferentNestedHierarchyShouldThrow() throws IOException {
128+
enabledOnlyWhenPushdownIsEnabled();
129+
Throwable t =
130+
assertThrows(
131+
Exception.class,
132+
() ->
133+
executeQuery(
134+
String.format(
135+
"source=%s | where author.books.reviews.rating + length(author.books.title)"
136+
+ " > 10",
137+
TEST_INDEX_CASCADED_NESTED)));
138+
verifyErrorMessageContains(
139+
t,
140+
"Accessing multiple nested fields under different hierarchies in script is not supported:"
141+
+ " [author.books.reviews, author.books]");
142+
}
122143
}

opensearch/src/main/java/org/opensearch/sql/opensearch/request/PredicateAnalyzer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,11 +1523,11 @@ public QueryBuilder builder() {
15231523
.distinct()
15241524
.collect(Collectors.toUnmodifiableList());
15251525
if (nestedPaths.size() > 1) {
1526-
throw new UnsupportedOperationException(
1526+
throw new UnsupportedScriptException(
15271527
String.format(
15281528
Locale.ROOT,
1529-
"Accessing multiple nested fields under different hierarchies is not supported:"
1530-
+ " %s",
1529+
"Accessing multiple nested fields under different hierarchies in script is not"
1530+
+ " supported: %s",
15311531
nestedPaths));
15321532
}
15331533
if (!nestedPaths.isEmpty()) {

0 commit comments

Comments
 (0)