Skip to content

Commit 0d76d1c

Browse files
committed
Add integration test and trim unit-test comments for alias path fix
Add a QueryValidationIT case asserting that SELECT * over an index whose alias field targets a text multi-field (source.keyword) returns a 400 SemanticCheckException with the descriptive message. An alias pointing at a truly missing field is rejected by OpenSearch at index-creation time, so it is not reachable through the SQL plugin and is covered by the unit test only. Shorten the unit-test comments and drop inline issue references. Signed-off-by: Jialiang Liang <jiallian@amazon.com>
1 parent e533a78 commit 0d76d1c

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/sql/QueryValidationIT.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,33 @@ private static void whenExecuteMalformedPayload() throws IOException {
103103
client().performRequest(request);
104104
}
105105

106+
// An alias field whose path targets a text multi-field (e.g. "source.keyword") must fail with a
107+
// descriptive client error rather than an opaque NullPointerException.
108+
@Test
109+
public void testAliasToKeywordMultiFieldFailsWithBadRequest() throws IOException {
110+
String index = "test_alias_unresolved_keyword";
111+
createIndexWithMapping(
112+
index,
113+
"{ \"properties\": {"
114+
+ " \"source\": { \"type\": \"text\", \"fields\": { \"keyword\": { \"type\":"
115+
+ " \"keyword\" } } },"
116+
+ " \"source_alias\": { \"type\": \"alias\", \"path\": \"source.keyword\" } } }");
117+
118+
expectResponseException()
119+
.hasStatusCode(BAD_REQUEST)
120+
.hasErrorType("SemanticCheckException")
121+
.containsMessage(
122+
"Alias field [source_alias] refers to unresolved path [source.keyword]")
123+
.whenExecute(String.format(Locale.ROOT, "SELECT * FROM %s", index));
124+
}
125+
126+
private static void createIndexWithMapping(String indexName, String mapping)
127+
throws IOException {
128+
Request request = new Request("PUT", "/" + indexName);
129+
request.setJsonEntity(String.format(Locale.ROOT, "{ \"mappings\": %s }", mapping));
130+
client().performRequest(request);
131+
}
132+
106133
public ResponseExceptionAssertion expectResponseException() {
107134
return new ResponseExceptionAssertion(exceptionRule);
108135
}

opensearch/src/test/java/org/opensearch/sql/opensearch/data/type/OpenSearchDataTypeTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,7 @@ public void test_AliasType() {
486486

487487
@Test
488488
public void traverseAndFlatten_alias_to_unresolvable_path_throws_descriptive_error() {
489-
// An alias whose path targets a text multi-field (e.g. "source.keyword"). Multi-fields are
490-
// stored under OpenSearchTextType.fields, not properties, so they are never added to the
491-
// flattened mapping and the alias target resolves to null. Previously this surfaced as an
492-
// opaque NullPointerException (issue #5535).
489+
// Alias path targets a text multi-field, which is not in the flattened mapping.
493490
Map<String, OpenSearchDataType> keywordAliasTree =
494491
Map.of(
495492
"source", textKeywordType,
@@ -505,7 +502,7 @@ public void traverseAndFlatten_alias_to_unresolvable_path_throws_descriptive_err
505502
+ " \"source.keyword.keyword\") or a removed/renamed field is not a valid alias target.",
506503
keywordException.getMessage());
507504

508-
// An alias whose path targets a field that does not exist (e.g. renamed/removed).
505+
// Alias path targets a field that does not exist.
509506
Map<String, OpenSearchDataType> missingFieldTree =
510507
Map.of(
511508
"col1", textType,

0 commit comments

Comments
 (0)