Skip to content

Commit 2e3c8c5

Browse files
authored
Merge branch 'main' into remove-pagination-api-config
Signed-off-by: Tomoyuki MORITA <moritato@amazon.com>
2 parents ca18a9b + 3bab06d commit 2e3c8c5

File tree

24 files changed

+87
-550
lines changed

24 files changed

+87
-550
lines changed

DEVELOPER_GUIDE.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ For test cases, you can use the cases in the following checklist in case you mis
294294

295295
- *Other Statements*
296296

297-
- DELETE
298297
- SHOW
299298
- DESCRIBE
300299

common/src/main/java/org/opensearch/sql/common/antlr/SyntaxAnalysisErrorListener.java

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,26 @@
55

66
package org.opensearch.sql.common.antlr;
77

8+
import java.util.ArrayList;
9+
import java.util.List;
810
import java.util.Locale;
911
import org.antlr.v4.runtime.BaseErrorListener;
1012
import org.antlr.v4.runtime.CommonTokenStream;
1113
import org.antlr.v4.runtime.RecognitionException;
1214
import org.antlr.v4.runtime.Recognizer;
1315
import org.antlr.v4.runtime.Token;
16+
import org.antlr.v4.runtime.Vocabulary;
1417
import org.antlr.v4.runtime.misc.IntervalSet;
1518

1619
/**
1720
* Syntax analysis error listener that handles any syntax error by throwing exception with useful
1821
* information.
1922
*/
2023
public class SyntaxAnalysisErrorListener extends BaseErrorListener {
24+
// Show up to this many characters before the offending token in the query.
25+
private static final int CONTEXT_TRUNCATION_THRESHOLD = 20;
26+
// Avoid presenting too many alternatives when many are available.
27+
private static final int SUGGESTION_TRUNCATION_THRESHOLD = 5;
2128

2229
@Override
2330
public void syntaxError(
@@ -35,8 +42,7 @@ public void syntaxError(
3542
throw new SyntaxCheckException(
3643
String.format(
3744
Locale.ROOT,
38-
"Failed to parse query due to offending symbol [%s] "
39-
+ "at: '%s' <--- HERE... More details: %s",
45+
"[%s] is not a valid term at this part of the query: '%s' <-- HERE. %s",
4046
getOffendingText(offendingToken),
4147
truncateQueryAtOffendingToken(query, offendingToken),
4248
getDetails(recognizer, msg, e)));
@@ -47,21 +53,47 @@ private String getOffendingText(Token offendingToken) {
4753
}
4854

4955
private String truncateQueryAtOffendingToken(String query, Token offendingToken) {
50-
return query.substring(0, offendingToken.getStopIndex() + 1);
56+
int contextStartIndex = offendingToken.getStartIndex() - CONTEXT_TRUNCATION_THRESHOLD;
57+
if (contextStartIndex < 3) { // The ellipses won't save us anything below the first 4 characters
58+
return query.substring(0, offendingToken.getStopIndex() + 1);
59+
}
60+
return "..." + query.substring(contextStartIndex, offendingToken.getStopIndex() + 1);
61+
}
62+
63+
private List<String> topSuggestions(Recognizer<?, ?> recognizer, IntervalSet continuations) {
64+
Vocabulary vocab = recognizer.getVocabulary();
65+
List<String> tokenNames = new ArrayList<>(SUGGESTION_TRUNCATION_THRESHOLD);
66+
for (int tokenType :
67+
continuations
68+
.toList()
69+
.subList(0, Math.min(continuations.size(), SUGGESTION_TRUNCATION_THRESHOLD))) {
70+
tokenNames.add(vocab.getDisplayName(tokenType));
71+
}
72+
return tokenNames;
5173
}
5274

53-
/**
54-
* As official JavaDoc says, e=null means parser was able to recover from the error. In other
55-
* words, "msg" argument includes the information we want.
56-
*/
57-
private String getDetails(Recognizer<?, ?> recognizer, String msg, RecognitionException e) {
58-
String details;
59-
if (e == null) {
60-
details = msg;
75+
private String getDetails(Recognizer<?, ?> recognizer, String msg, RecognitionException ex) {
76+
if (ex == null) {
77+
// According to the ANTLR docs, ex == null means the parser was able to recover from the
78+
// error.
79+
// In such cases, `msg` includes the raw error information we care about.
80+
return msg;
81+
}
82+
83+
IntervalSet possibleContinuations = ex.getExpectedTokens();
84+
List<String> suggestions = topSuggestions(recognizer, possibleContinuations);
85+
86+
StringBuilder details = new StringBuilder("Expecting ");
87+
if (possibleContinuations.size() > SUGGESTION_TRUNCATION_THRESHOLD) {
88+
details
89+
.append("one of ")
90+
.append(possibleContinuations.size())
91+
.append(" possible tokens. Some examples: ")
92+
.append(String.join(", ", suggestions))
93+
.append(", ...");
6194
} else {
62-
IntervalSet followSet = e.getExpectedTokens();
63-
details = "Expecting tokens in " + followSet.toString(recognizer.getVocabulary());
95+
details.append("tokens: ").append(String.join(", ", suggestions));
6496
}
65-
return details;
97+
return details.toString();
6698
}
6799
}

common/src/main/java/org/opensearch/sql/common/setting/Settings.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public enum Key {
2222
SQL_ENABLED("plugins.sql.enabled"),
2323
SQL_SLOWLOG("plugins.sql.slowlog"),
2424
SQL_CURSOR_KEEP_ALIVE("plugins.sql.cursor.keep_alive"),
25-
SQL_DELETE_ENABLED("plugins.sql.delete.enabled"),
2625

2726
/** PPL Settings. */
2827
PPL_ENABLED("plugins.ppl.enabled"),

docs/user/admin/settings.rst

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -216,61 +216,6 @@ Result set::
216216
"transient": {}
217217
}
218218

219-
plugins.sql.delete.enabled
220-
======================
221-
222-
Description
223-
-----------
224-
225-
By default, DELETE clause disabled. You can enable DELETE clause by this setting.
226-
227-
1. The default value is false.
228-
2. This setting is node scope.
229-
3. This setting can be updated dynamically.
230-
231-
232-
Example 1
233-
---------
234-
235-
You can update the setting with a new value like this.
236-
237-
SQL query::
238-
239-
sh$ curl -sS -H 'Content-Type: application/json' -X PUT localhost:9200/_plugins/_query/settings \
240-
... -d '{"transient":{"plugins.sql.delete.enabled":"false"}}'
241-
{
242-
"acknowledged": true,
243-
"persistent": {},
244-
"transient": {
245-
"plugins": {
246-
"sql": {
247-
"delete": {
248-
"enabled": "false"
249-
}
250-
}
251-
}
252-
}
253-
}
254-
255-
Example 2
256-
---------
257-
258-
Query result after the setting updated is like:
259-
260-
SQL query::
261-
262-
sh$ curl -sS -H 'Content-Type: application/json' -X POST localhost:9200/_plugins/_sql \
263-
... -d '{"query" : "DELETE * FROM accounts"}'
264-
{
265-
"error": {
266-
"reason": "Invalid SQL query",
267-
"details": "DELETE clause is disabled by default and will be deprecated. Using the plugins.sql.delete.enabled setting to enable it",
268-
"type": "SQLFeatureDisabledException"
269-
},
270-
"status": 400
271-
}
272-
273-
274219
plugins.query.executionengine.spark.session.limit
275220
==================================================
276221

docs/user/dml/delete.rst

Lines changed: 0 additions & 87 deletions
This file was deleted.

docs/user/dql/basics.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,6 @@ Description
374374

375375
For ``LIKE`` and other full text search topics, please refer to Full Text Search documentation.
376376

377-
Besides SQL query, WHERE clause can also be used in SQL statement such as ``DELETE``. Please refer to Data Manipulation Language documentation for details.
378-
379377
Example 1: Comparison Operators
380378
-------------------------------
381379

docs/user/dql/troubleshooting.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ Query:
2525

2626
.. code-block:: JSON
2727
28-
POST /_plugins/_sql
28+
POST /_plugins/_ppl
2929
{
30-
"query" : "SELECT * FROM sample:data"
30+
"query" : "SOURCE = test_index | where a > 0)"
3131
}
3232
3333
Result:
3434

3535
.. code-block:: JSON
3636
3737
{
38-
"reason": "Invalid SQL query",
39-
"details": "Failed to parse query due to offending symbol [:] at: 'SELECT * FROM xxx WHERE xxx:' <--- HERE...
40-
More details: Expecting tokens in {<EOF>, 'AND', 'BETWEEN', 'GROUP', 'HAVING', 'IN', 'IS', 'LIKE', 'LIMIT',
41-
'NOT', 'OR', 'ORDER', 'REGEXP', '*', '/', '%', '+', '-', 'DIV', 'MOD', '=', '>', '<', '!',
42-
'|', '&', '^', '.', DOT_ID}",
43-
"type": "SyntaxAnalysisException"
38+
"error": {
39+
"reason": "Invalid Query",
40+
"details": "[)] is not a valid term at this part of the query: '..._index | where a > 0)' <-- HERE. extraneous input ')' expecting <EOF>",
41+
"type": "SyntaxCheckException"
42+
},
43+
"status": 400
4444
}
4545
4646
**Workaround**

docs/user/index.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ OpenSearch SQL enables you to extract insights out of OpenSearch using the famil
4343

4444
- `Window Functions <dql/window.rst>`_
4545

46-
* **Data Manipulation Language**
47-
48-
- `DELETE Statement <dml/delete.rst>`_
49-
5046
* **Beyond SQL**
5147

5248
- `PartiQL (JSON) Support <beyond/partiql.rst>`_

0 commit comments

Comments
 (0)