[RFC] Misleading SQL naming in PPL error responses

Aperta
#5,951 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java

Direzione di ricerca

Read the error response examples and the discussion of the two proposed parts: cleaning up the JDBC wrapper and choosing a stable client classification field. The issue is an open RFC with unresolved questions about client compatibility and error behavior, so a contributor should first help settle the desired contract. Done would mean an agreed approach that defines the response fields and their compatibility expectations.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

error-experience PPL RFC

Problem Statement

The problem. PPL error responses can identify a failure as a SQL exception, even though the user wrote PPL. More broadly, they show names from the engine's implementation rather than terms that describe the failure.

Why it matters. Users, support engineers and client tools can all be misled about what failed and who should act. A mistake in the query can look like a failure in a SQL engine.

The gap, from PPL's side. The error response has no public vocabulary of its own. Its main classifier is the name of whichever Java exception reaches the response, and the language-neutral alternative covers only some failures. We need to decide what clients should rely on and how much of today's response can change.

Current State

SQL and PPL share one plugin and much of their error-handling code.

  • type is a Java class name. It was not designed as a public name, but clients already read it and some match specific values.
  • code is the language-neutral field. It came from the work under #4919 and #5261, but many common failures, including syntax and shard-level errors, have no specific code.
  • The real cause can be buried. Engine wrapper text can appear ahead of the actual reason, so a query mistake reads like an engine failure.
  • Not every consumer reads the response. Some plugins call PPL over transport and receive the exception directly.

"SQL" reaches users from three places:

Source of the name Who sees it Accurate?
SQL-named classes in the legacy engine SQL users Yes
java.sql.SQLException from the JDBC layer under Calcite PPL users No, it refers to JDBC rather than the SQL language
Infrastructure names such as the sql-worker thread pool SQL and PPL users It is the real name, but reads as SQL-specific to PPL users

On the default route, Calcite serves only PPL, so PPL users see java.sql.SQLException and SQL users do not.

Long-Term Goals

  • PPL errors describe the failure in the user's terms, not in terms of the engine's internals.
  • Clients and tools have one documented, language-neutral field to classify errors.
  • Existing clients are not broken without notice.

Proposal

Initial proposal, open for discussion. It combines one option from each part of the comparison below:

  • Clean up the error before returning it, so PPL responses show the real cause instead of the JDBC wrapper.
  • Make code the stable field: fill it in for common failures and document it as the field to rely on.
  • Document the error fields: which ones are stable, and that type is for diagnostics.

This leaves the engine's own error handling unchanged, and keeps today's type values for every failure that is not an engine wrapper.

Approach

The problem has two independent parts, and the proposal picks one option from each. All options below use the same running example.

Running example

source=logs | sort user, where user is an object field. OpenSearch cannot sort on an object field, so the mistake is in the query. Today PPL returns:

{
  "status": 400,
  "error": {
    "type": "RuntimeException",
    "code": "UNKNOWN",
    "reason": "java.sql.SQLException: exception while executing query: Failed to fetch data from the index: the background task failed or interrupted. Inner error: Failed to execute phase [query], all shards failed; ... QueryShardException[No mapping found for [user] in order to sort on]"
  }
}

The user's actual mistake is only at the very end. Everything before it is engine internals, and it starts with a SQL exception.

Part 1: What users read

The engine runs PPL through a JDBC layer. That layer wraps failures in java.sql.SQLException, which can hide the real cause.

Option What changes Pros Cons Client impact
Explain it in the docs Nothing in the response; the docs explain the name No risk Users still see the misleading name None
Clean up the error before returning it The response shows the real cause instead of the wrapper Fixes what users see; engine logic is untouched Plugins that call PPL directly, such as Alerting, still get the old text Medium
Clean up the error where it is thrown The engine stops passing the wrapper up Also fixes plugins that call PPL directly Engine logic depends on these wrappers today, so regressions are likely Medium for clients, high for the engine

How each option changes the running example:

  • Explain it in the docs. The response stays as above. The docs gain a note such as: "java.sql.SQLException in a PPL error comes from the JDBC layer the engine runs on. It does not mean your query was run as SQL."
  • Clean up the error before returning it. The response becomes (illustrative):
    {
      "type": "SearchPhaseExecutionException",
      "reason": "No mapping found for [user] in order to sort on"
    }
    
  • Clean up the error where it is thrown. The response is the same as with the previous option. The difference is for plugins such as Alerting that call PPL directly: they receive the exception rather than the response. Today that exception's message starts with java.sql.SQLException: exception while executing query, and only this option changes it.
Part 2: What tools rely on
Option What changes Pros Cons Client impact
Make code the stable field Common failures get a specific code, and the docs name it as the field to rely on Additive; breaks no client Ongoing work; type keeps exposing class names Low
Redefine type type carries designed, language-neutral names instead of class names One clean field Breaks clients that match today's values; may need a major version High

Two PPL errors today:

reason type code
Field [usr] not found. IllegalArgumentException FIELD_NOT_FOUND
Rex pattern must contain at least one named capture group IllegalArgumentException UNKNOWN
  • Make code the stable field. A tool can tell these two errors apart by code, but not by type. The work is to fill in code wherever it is missing or UNKNOWN. That includes the running example and syntax errors, which today have no code at all.
  • Redefine type. The first error's type would become a designed name such as FieldNotFound. Clients that match today's values break. For example, the Traces view in OpenSearch Dashboards detects a missing field by checking type === "SemanticCheckException".

Client impact is based on public OpenSearch repositories. Private integrations are unknown, so feedback from those users is especially welcome.

Alternative

Besides the options compared above, two more were considered. Neither solves the problem:

  • Rename our Java exceptions. The misleading name is the JDK's java.sql.SQLException, which we cannot rename. Renaming our own classes, such as SqlParseException, would not change the running example at all, and those classes only reach SQL users, where the name is accurate.
  • Add a language field. The running example would gain "language": "ppl", but its reason would still start with java.sql.SQLException.

Implementation Discussion

  • Plugins that call PPL directly. Should they also get the cleaned-up error? That needs the error cleaned up where it is thrown, or a change on their side.
  • Stability of type. Should type be documented as unstable, or should today's values be kept as they are, apart from the engine wrappers?
  • Existing dependence. Does anyone match on the engine wrapper text, or on type values such as RuntimeException?
Lingua principale
Java
Stelle
176
Fork
237
Merge medio
2g 12h
PR unite (30g)
34

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di opensearch-project/sql

Tutte le issue di opensearch-project/sql

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.