Skip to content

Fix unclear PPL error message for empty mapping on wildcard indices#5609

Open
anohedr wants to merge 3 commits into
opensearch-project:mainfrom
anohedr:feature/unclear_ppl_err_msg_4968
Open

Fix unclear PPL error message for empty mapping on wildcard indices#5609
anohedr wants to merge 3 commits into
opensearch-project:mainfrom
anohedr:feature/unclear_ppl_err_msg_4968

Conversation

@anohedr

@anohedr anohedr commented Jul 6, 2026

Copy link
Copy Markdown

Description

Improves the error message returned when an index has an empty mapping. This change makes the error clearer and more actionable for users while preserving the existing behavior. Unit tests have been updated to verify the new error message.

Related Issues

Resolves #[4872]

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: anohedr <anoopmahenderkar@gmail.com>
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

(Review updated until commit 5e50c14)

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ Recommended focus areas for review

Null Handling

The method filters null elements from the array when checking for patterns but does not filter them when joining. If indexExpression contains null elements, String.join(",", exprs) will produce "null" as a substring in the joined string. This can lead to confusing error messages that literally contain the word "null" instead of omitting those entries.

|| Arrays.stream(exprs)
    .filter(e -> e != null)
    .anyMatch(
        e ->
            e.contains("*")
                || e.contains("?")
                || e.startsWith("<")
                || e.startsWith("-")
                || e.equals("_all"));
Array Bounds

The catch block at line 115 references indexExpression[0] without verifying that indexExpression is non-empty. If getIndexMappings is called with an empty array and an OpenSearchSecurityException is thrown, this will cause an ArrayIndexOutOfBoundsException.

.context("index_name", indexExpression[0])
.build();

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Latest suggestions up to 5e50c14

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Fix pattern detection for exclusions

The pattern detection logic treats any expression starting with - as a pattern, but
- is used for exclusions in multi-index patterns (e.g., index
,-excluded). A single
expression starting with - (like -myindex) is invalid and should not be classified
as a pattern requiring the "compatible mapping" hint.
*

opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchClient.java [144-154]

 boolean isPattern =
     exprs.length > 1
         || Arrays.stream(exprs)
             .filter(e -> e != null)
             .anyMatch(
                 e ->
                     e.contains("*")
                         || e.contains("?")
                         || e.startsWith("<")
-                        || e.startsWith("-")
                         || e.equals("_all"));
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that a single expression starting with - (like -myindex) is invalid and shouldn't trigger the "compatible mapping" hint. However, the logic exprs.length > 1 already handles multi-index patterns where exclusions are valid, so removing the e.startsWith("-") check is appropriate for single-expression cases.

Medium

Previous suggestions

Suggestions up to commit 8f53d9a
CategorySuggestion                                                                                                                                    Impact
General
Remove redundant ErrorReport catch block

Catching and re-throwing ErrorReport is unnecessary since ErrorReport extends
RuntimeException. The existing catch block for generic Exception will not catch
ErrorReport anyway due to the order. Remove this redundant catch block to simplify
the exception handling flow.

opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchNodeClient.java [117-119]

-} catch (ErrorReport e) {
-  throw e;
 } catch (Exception e) {
Suggestion importance[1-10]: 4

__

Why: The catch block for ErrorReport appears redundant since it only re-throws the exception. However, it serves to preserve the specific ErrorReport type before the generic Exception handler wraps it in IllegalStateException. Removing it would change exception handling behavior, though the impact is minor since ErrorReport extends RuntimeException.

Low
Fix pattern detection for multi-index queries

The pattern detection logic treats a comma within a single string as a pattern
indicator, but commas are also used to separate multiple index names in a single
argument. This can cause false positives where legitimate multi-index queries
without wildcards are incorrectly flagged as patterns. Consider checking if the
array contains multiple elements OR if any single element contains pattern syntax.

opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchClient.java [134-146]

 String[] exprs = indexExpression != null ? indexExpression : new String[0];
 String joined = String.join(",", exprs);
 boolean isPattern =
-    Arrays.stream(exprs)
-        .filter(e -> e != null)
-        .anyMatch(
-            e ->
-                e.contains("*")
-                    || e.contains("?")
-                    || e.contains(",")
-                    || e.startsWith("<")
-                    || e.startsWith("-")
-                    || e.equals("_all"));
+    exprs.length > 1
+        || Arrays.stream(exprs)
+            .filter(e -> e != null)
+            .anyMatch(
+                e ->
+                    e.contains("*")
+                        || e.contains("?")
+                        || e.contains(",")
+                        || e.startsWith("<")
+                        || e.startsWith("-")
+                        || e.equals("_all"));
Suggestion importance[1-10]: 3

__

Why: The suggestion identifies a potential issue where exprs.length > 1 could help distinguish multi-index queries, but the current logic already handles commas within strings as pattern indicators (which is correct per OpenSearch syntax). The test at line 310-314 validates this behavior. The suggestion may introduce unintended changes to the error message logic without clear benefit.

Low
Suggestions up to commit ae77f2a
CategorySuggestion                                                                                                                                    Impact
General
Fix pattern detection for hyphenated names

The pattern detection logic may incorrectly classify indices with hyphens in their
names (e.g., my-index) as patterns because it checks e.startsWith("-"). This check
is intended for exclusion patterns but will match any index name containing a
leading hyphen. Consider checking for exclusion syntax more precisely or documenting
this behavior.

opensearch/src/main/java/org/opensearch/sql/opensearch/client/OpenSearchClient.java [135-144]

 boolean isPattern =
     Arrays.stream(indexExpression)
         .filter(e -> e != null)
         .anyMatch(
             e ->
                 e.contains("*")
                     || e.contains("?")
                     || e.startsWith("<")
-                    || e.startsWith("-")
+                    || (e.startsWith("-") && e.length() > 1 && !Character.isLetterOrDigit(e.charAt(1)))
                     || e.equals("_all"));
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies a critical bug where e.startsWith("-") would incorrectly classify normal index names like my-index as patterns. The improved code adds a check to distinguish between exclusion patterns (e.g., -excluded*) and regular hyphenated names, preventing false positives that would show incorrect error messages to users.

Medium

Signed-off-by: anohedr <anoopmahenderkar@gmail.com>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 8f53d9a

Signed-off-by: anohedr <anoopmahenderkar@gmail.com>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 5e50c14

@RyanL1997 RyanL1997 added the enhancement New feature or request label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants