From f9a64f9138d084ceb55667657a0d52338da595f8 Mon Sep 17 00:00:00 2001 From: chloe-zh Date: Tue, 25 Feb 2020 17:02:08 -0800 Subject: [PATCH 01/10] Edit the wording of exception messages --- .../sql/domain/Condition.java | 5 ++-- .../sql/domain/SearchResult.java | 2 +- .../executor/GetIndexRequestRestListener.java | 2 +- .../sql/executor/multi/MinusExecutor.java | 7 ++--- .../multi/MultiRequestExecutorFactory.java | 6 +++-- .../sql/parser/ChildrenType.java | 2 +- .../sql/parser/ElasticSqlExprParser.java | 26 +++++++++---------- .../sql/parser/ElasticSqlSelectParser.java | 3 ++- .../sql/parser/FieldMaker.java | 9 ++++--- .../sql/parser/NestedType.java | 4 +-- .../sql/parser/SqlParser.java | 7 +++-- .../sql/query/DefaultQueryAction.java | 2 +- .../sql/query/maker/Maker.java | 5 ++-- .../sql/spatial/WktToGeoJsonConverter.java | 8 +++--- 14 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java index 3aee248189..90e9fb92d2 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java @@ -19,6 +19,7 @@ import com.amazon.opendistroforelasticsearch.sql.exception.SqlParseException; import com.amazon.opendistroforelasticsearch.sql.parser.ChildrenType; import com.amazon.opendistroforelasticsearch.sql.parser.NestedType; +import com.amazon.opendistroforelasticsearch.sql.utils.StringUtils; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; @@ -242,7 +243,7 @@ public Condition(CONN conn, String name, SQLExpr nameExpr, String oper, if (OPEAR.operStringToOpear.containsKey(oper)) { this.opear = OPEAR.operStringToOpear.get(oper); } else { - throw new SqlParseException(oper + " is not a supported operation"); + throw new SqlParseException("Unsupported operation: " + oper); } } @@ -309,7 +310,7 @@ public String getOpertatorSymbol() throws SqlParseException { case ISN: return "!="; default: - throw new SqlParseException(opear + " is err!"); + throw new SqlParseException(StringUtils.format("Failed to parse operator [%s]", opear)); } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/SearchResult.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/SearchResult.java index dbcb7d9aaf..94aae134e2 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/SearchResult.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/SearchResult.java @@ -135,7 +135,7 @@ private Object covenValue(Aggregation value) throws SqlParseException { } else if (value instanceof LongTerms) { return value; } else { - throw new SqlParseException("unknow this agg type " + value.getClass()); + throw new SqlParseException("Unknown aggregation value type: " + value.getClass()); } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/GetIndexRequestRestListener.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/GetIndexRequestRestListener.java index f2b90356b2..c823e6123f 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/GetIndexRequestRestListener.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/GetIndexRequestRestListener.java @@ -65,7 +65,7 @@ public RestResponse buildResponse(GetIndexResponse getIndexResponse, XContentBui writeSettings(getIndexResponse.settings().get(index), builder, channel.request()); break; default: - throw new IllegalStateException("feature [" + feature + "] is not valid"); + throw new IllegalStateException("Unsupported feature: " + feature); } } builder.endObject(); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MinusExecutor.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MinusExecutor.java index e9c27e3601..89f2be952a 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MinusExecutor.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MinusExecutor.java @@ -77,12 +77,13 @@ public MinusExecutor(Client client, MultiQueryRequestBuilder builder) { } @Override - public void run() throws IOException, SqlParseException { + public void run() throws SqlParseException { if (this.useTermsOptimization && this.fieldsOrderFirstTable.length != 1) { - throw new SqlParseException("terms optimization supports minus with only one field"); + throw new SqlParseException( + "Terms optimization failed: terms optimization for minus execution is supported with one field"); } if (this.useTermsOptimization && !this.useScrolling) { - throw new SqlParseException("terms optimization work only with scrolling add scrolling hint"); + throw new SqlParseException("Terms optimization failed: using scrolling is required for terms optimization"); } if (!this.useScrolling || !this.useTermsOptimization) { Set comperableHitResults; diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MultiRequestExecutorFactory.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MultiRequestExecutorFactory.java index d789bbb518..5d4263a8a3 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MultiRequestExecutorFactory.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MultiRequestExecutorFactory.java @@ -15,6 +15,7 @@ package com.amazon.opendistroforelasticsearch.sql.executor.multi; +import com.alibaba.druid.sql.ast.statement.SQLUnionOperator; import com.amazon.opendistroforelasticsearch.sql.exception.SqlParseException; import com.amazon.opendistroforelasticsearch.sql.executor.ElasticHitsExecutor; import com.amazon.opendistroforelasticsearch.sql.query.multi.MultiQueryRequestBuilder; @@ -26,14 +27,15 @@ public class MultiRequestExecutorFactory { public static ElasticHitsExecutor createExecutor(Client client, MultiQueryRequestBuilder builder) throws SqlParseException { - switch (builder.getRelation()) { + SQLUnionOperator relation = builder.getRelation(); + switch (relation) { case UNION_ALL: case UNION: return new UnionExecutor(client, builder); case MINUS: return new MinusExecutor(client, builder); default: - throw new SqlParseException("only supports union, and minus operations"); + throw new SqlParseException("Unsupported operator: " + relation); } } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ChildrenType.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ChildrenType.java index ccc777c8b1..289c242687 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ChildrenType.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ChildrenType.java @@ -66,7 +66,7 @@ public boolean tryFillFromExpr(SQLExpr expr) throws SqlParseException { Where where = Where.newInstance(); new WhereParser(new SqlParser()).parseWhere(secondParameter, where); if (where.getWheres().size() == 0) { - throw new SqlParseException("unable to parse filter where."); + throw new SqlParseException("Failed to parse filter condition"); } this.where = where; simple = false; diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java index 10a6afb957..b2be734782 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java @@ -120,7 +120,7 @@ protected SQLExpr methodRest(SQLExpr expr, boolean acceptLPAREN) { return primaryRest(methodInvokeExpr); } - throw new ParserException("not support token:" + lexer.token()); + throw new ParserException("Syntax error:" + lexer.token()); } @@ -283,7 +283,7 @@ public SQLExpr primary2() { case VALUES: lexer.nextToken(); if (lexer.token() != Token.LPAREN) { - throw new ParserException("syntax error, illegal values clause"); + throw new ParserException("Syntax error: " + lexer.token()); } return this.methodRest(new SQLIdentifierExpr("VALUES"), true); case BINARY: @@ -310,7 +310,7 @@ public SQLExpr primary2() { public final SQLExpr primaryRest(SQLExpr expr) { if (expr == null) { - throw new IllegalArgumentException("expr"); + throw new IllegalArgumentException("Illegal expression: NULL"); } if (lexer.token() == Token.LITERAL_CHARS) { @@ -363,7 +363,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { if ("USING".equalsIgnoreCase(lexer.stringVal())) { lexer.nextToken(); if (lexer.token() != Token.IDENTIFIER) { - throw new ParserException("syntax error, illegal hex"); + throw new ParserException("Syntax error: " + lexer.token()); } String charSet = lexer.stringVal(); lexer.nextToken(); @@ -379,7 +379,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { } if (lexer.token() != Token.IDENTIFIER) { - throw new ParserException("syntax error"); + throw new ParserException("Syntax error: " + lexer.token()); } String collate = lexer.stringVal(); @@ -394,7 +394,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { lexer.nextToken(); if (lexer.token() != Token.IDENTIFIER) { - throw new ParserException("syntax error"); + throw new ParserException("Syntax error: " + lexer.token()); } String collate = lexer.stringVal(); @@ -424,7 +424,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { lexer.nextToken(); if (lexer.token() != Token.IDENTIFIER) { - throw new ParserException("syntax error"); + throw new ParserException("Syntax error: " + lexer.token()); } String unitVal = lexer.stringVal(); @@ -467,7 +467,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { } else if (lexer.token() == Token.RPAREN) { break; } else { - throw new ParserException("syntax error"); + throw new ParserException("Syntax error: " + lexer.token()); } } @@ -544,10 +544,10 @@ public final SQLExpr primaryRest(SQLExpr expr) { acceptIdentifier("MODE"); matchAgainstExpr.setSearchModifier(MySqlMatchAgainstExpr.SearchModifier.IN_BOOLEAN_MODE); } else { - throw new ParserException("TODO"); + throw new ParserException("Syntax error: " + lexer.token()); } } else if (lexer.token() == Token.WITH) { - throw new ParserException("TODO"); + throw new ParserException("Syntax error: " + lexer.token()); } accept(Token.RPAREN); @@ -566,7 +566,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { if (identifierEquals("USING")) { lexer.nextToken(); if (lexer.token() != Token.IDENTIFIER) { - throw new ParserException("syntax error"); + throw new ParserException("Syntax error: " + lexer.token()); } String charset = lexer.stringVal(); lexer.nextToken(); @@ -651,7 +651,7 @@ protected SQLExpr bracketRest(SQLExpr expr) { index = lexer.integerValue(); lexer.nextToken(); } else { - throw new ParserException("error : " + lexer.stringVal()); + throw new ParserException("Syntax error : " + lexer.stringVal()); } if (expr instanceof SQLMethodInvokeExpr) { @@ -685,7 +685,7 @@ protected SQLExpr parseInterval() { SQLExpr value = expr(); if (lexer.token() != Token.IDENTIFIER) { - throw new ParserException("Syntax error"); + throw new ParserException("Syntax error: " + lexer.token()); } String unit = lexer.stringVal(); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlSelectParser.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlSelectParser.java index ca2153a7c2..7fa33d6e6b 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlSelectParser.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlSelectParser.java @@ -37,6 +37,7 @@ import com.alibaba.druid.sql.parser.SQLExprParser; import com.alibaba.druid.sql.parser.SQLSelectParser; import com.alibaba.druid.sql.parser.Token; +import com.amazon.opendistroforelasticsearch.sql.exception.SqlFeatureNotImplementedException; /** * Created by allwefantasy on 8/19/16. @@ -140,7 +141,7 @@ public SQLSelectQuery query() { if (lexer.token() == Token.PROCEDURE) { lexer.nextToken(); - throw new ParserException("TODO"); + throw new SqlFeatureNotImplementedException("Unsupported feature: " + Token.PROCEDURE.name); } parseInto(queryBlock); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/FieldMaker.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/FieldMaker.java index f149f99d54..42bc213170 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/FieldMaker.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/FieldMaker.java @@ -42,6 +42,7 @@ import com.amazon.opendistroforelasticsearch.sql.exception.SqlFeatureNotImplementedException; import com.amazon.opendistroforelasticsearch.sql.exception.SqlParseException; import com.amazon.opendistroforelasticsearch.sql.utils.SQLFunctions; +import com.amazon.opendistroforelasticsearch.sql.utils.StringUtils; import com.amazon.opendistroforelasticsearch.sql.utils.Util; import com.google.common.base.Strings; import org.elasticsearch.common.collect.Tuple; @@ -198,7 +199,7 @@ private static Field makeFilterMethodField(SQLMethodInvokeExpr filterMethod, Str Where where = Where.newInstance(); new WhereParser(new SqlParser()).parseWhere(exprToCheck, where); if (where.getWheres().size() == 0) { - throw new SqlParseException("unable to parse filter where."); + throw new SqlParseException("Failed to parse filter condition"); } List methodParameters = new ArrayList<>(); methodParameters.add(new KVValue("where", where)); @@ -250,7 +251,7 @@ public SQLMethodInvokeExpr makeBinaryMethodField(SQLBinaryOpExpr expr, String al case Subtract: return convertBinaryOperatorToMethod("subtract", expr); default: - throw new SqlParseException(expr.getOperator().getName() + " is not support"); + throw new SqlParseException("Unsupported operator: " + expr.getOperator().getName()); } } @@ -319,7 +320,7 @@ public MethodField makeMethodField(String name, List arguments, SQLAggr NestedType nestedType = new NestedType(); if (!nestedType.tryFillFromExpr(object)) { - throw new SqlParseException("failed parsing nested expr " + object); + throw new SqlParseException("Failed to parse nested expression: " + object); } // Fix bug: method name of reversed_nested() was set to "nested" wrongly @@ -328,7 +329,7 @@ public MethodField makeMethodField(String name, List arguments, SQLAggr ChildrenType childrenType = new ChildrenType(); if (!childrenType.tryFillFromExpr(object)) { - throw new SqlParseException("failed parsing children expr " + object); + throw new SqlParseException("Failed to parse children expression: " + object); } paramers.add(new KVValue("children", childrenType)); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java index 7fddf7ed2a..5d6f68eb9e 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java @@ -63,7 +63,7 @@ public boolean tryFillFromExpr(SQLExpr expr) throws SqlParseException { //calc path myself.. if (!field.contains(".")) { if (!reverse) { - throw new SqlParseException("nested should contain . on their field name"); + throw new IllegalArgumentException("Illegal nested field name: " + field); } else { this.path = null; this.simple = true; @@ -92,7 +92,7 @@ public boolean tryFillFromExpr(SQLExpr expr) throws SqlParseException { Where where = Where.newInstance(); new WhereParser(new SqlParser()).parseWhere(secondParameter, where); if (where.getWheres().size() == 0) { - throw new SqlParseException("unable to parse filter where."); + throw new SqlParseException("Failed to parse filter condition"); } this.where = where; simple = false; diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/SqlParser.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/SqlParser.java index ff3f450f2a..5cd8a087fb 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/SqlParser.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/SqlParser.java @@ -217,8 +217,8 @@ private String sameAliasWhere(Where where, String... aliases) throws SqlParseExc return alias; } } - throw new SqlParseException(String.format("fieldName : %s on codition:%s does not contain alias", fieldName, - condition.toString())); + throw new SqlParseException(String.format("Field [%s] with condition [%s] does not contain an alias", + fieldName, condition.toString())); } List sameAliases = new ArrayList<>(); if (where.getWheres() != null && where.getWheres().size() > 0) { @@ -486,8 +486,7 @@ private List getConnectedFields(List conditions, String alias) if (!((condition.getValue() instanceof SQLPropertyExpr) || (condition.getValue() instanceof SQLIdentifierExpr) || (condition.getValue() instanceof String))) { - throw new SqlParseException("conditions on join should be one side is firstTable second Other, " - + "condition was:" + condition.toString()); + throw new SqlParseException("Illegal condition content: " + condition.toString()); } String aliasDotValue = condition.getValue().toString(); int indexOfDot = aliasDotValue.indexOf("."); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/DefaultQueryAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/DefaultQueryAction.java index 90030d081d..a1a7d9e8cf 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/DefaultQueryAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/DefaultQueryAction.java @@ -291,7 +291,7 @@ private ScriptSortType getScriptSortType(Order order) { scriptSortType = ScriptSortType.NUMBER; break; default: - throw new RuntimeException("unknown"); + throw new IllegalStateException("Unknown type: " + scriptFunctionReturnType); } return scriptSortType; } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/Maker.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/Maker.java index 3a478a0194..db6bb599e0 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/Maker.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/Maker.java @@ -33,6 +33,7 @@ import com.amazon.opendistroforelasticsearch.sql.spatial.Point; import com.amazon.opendistroforelasticsearch.sql.spatial.PolygonFilterParams; import com.amazon.opendistroforelasticsearch.sql.spatial.WktToGeoJsonConverter; +import com.amazon.opendistroforelasticsearch.sql.utils.StringUtils; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import org.apache.lucene.search.join.ScoreMode; @@ -264,7 +265,7 @@ private ToXContent make(Condition cond, String name, Object value) throws SqlPar toXContent = QueryBuilders.geoShapeQuery(cond.getName(), shapeBuilder); } catch (IOException e) { e.printStackTrace(); - throw new SqlParseException("couldn't create shapeBuilder from wkt: " + wkt); + throw new SqlParseException(StringUtils.format("Failed to create shapeBuilder from [%s]", wkt)); } break; case GEO_BOUNDING_BOX: @@ -363,7 +364,7 @@ private ToXContent make(Condition cond, String name, Object value) throws SqlPar } break; default: - throw new SqlParseException("not define type " + cond.getName()); + throw new SqlParseException("Undefined condition: " + cond.getName()); } toXContent = applyNot(cond.getOpear(), toXContent); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java index a35c027032..7f435a0ae8 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java @@ -16,6 +16,7 @@ package com.amazon.opendistroforelasticsearch.sql.spatial; +import com.amazon.opendistroforelasticsearch.sql.utils.StringUtils; import com.google.common.base.Joiner; import java.util.ArrayList; @@ -29,7 +30,8 @@ public static String toGeoJson(String wkt) { wkt = wkt.toLowerCase(); int startOfCoordinates = wkt.indexOf("("); if (startOfCoordinates == -1) { - throw new IllegalArgumentException("not valid wkt"); + throw new IllegalArgumentException( + StringUtils.format("Failed to convert well-know-text [%s] to geometry type", wkt)); } String wktType = wkt.substring(0, startOfCoordinates).trim(); @@ -63,7 +65,7 @@ public static String toGeoJson(String wkt) { coordinates = multiLineStringCoordinatesFromWkt(wkt); break; default: - throw new IllegalArgumentException("not supported wkt type"); + throw new IllegalArgumentException("Unsupported well-known-text type: " + wktType); } @@ -169,7 +171,7 @@ private static String removeBrackets(String wkt, int num) { int lastClosingBrackets = result.lastIndexOf(")"); int firstOpenBrackets = result.indexOf("("); if (lastClosingBrackets == -1 || firstOpenBrackets == -1) { - throw new IllegalArgumentException("not enough brackets"); + throw new IllegalArgumentException("Illegal syntax: " + wkt); } result = result.substring(firstOpenBrackets + 1, lastClosingBrackets); } From d6e8f6dc4f446b1fb14baa4ecce54bbfea24bdd5 Mon Sep 17 00:00:00 2001 From: chloe-zh Date: Tue, 25 Feb 2020 17:41:45 -0800 Subject: [PATCH 02/10] Created troubleshooting page --- docs/user/dql/troubleshooting.rst | 82 +++++++++++++++++++++++++++++++ docs/user/index.rst | 4 ++ 2 files changed, 86 insertions(+) create mode 100644 docs/user/dql/troubleshooting.rst diff --git a/docs/user/dql/troubleshooting.rst b/docs/user/dql/troubleshooting.rst new file mode 100644 index 0000000000..9ec7fd0945 --- /dev/null +++ b/docs/user/dql/troubleshooting.rst @@ -0,0 +1,82 @@ + +=========== +Basic Query +=========== + +.. rubric:: Content + +.. contents:: + :local: + :depth: 2 + + +Narrative +========= + +SQL plugin is stateless for now so mostly the troubleshooting is mainly focused on why a single query fails. + + +Syntax Analysis / Semantic Analysis Exceptions +---------------------------------------------- + +* **Symptoms** + +When you end up with exceptions similar to as follows: + +Query:: + POST /_opendistro/_sql + { + "query" : "SELECT * FROM sample:data" + } + +Result:: + { + "reason": "Invalid SQL query", + "details": "Failed to parse query due to offending symbol [:] at: 'SELECT * FROM xxx WHERE xxx:' <--- HERE... More details: Expecting tokens in {, 'AND', 'BETWEEN', 'GROUP', 'HAVING', 'IN', 'IS', 'LIKE', 'LIMIT', + 'NOT', 'OR', 'ORDER', 'REGEXP', '*', '/', '%', '+', '-', 'DIV', 'MOD', '=', '>', '<', '!', '|', '&', '^', '.', DOT_ID}", + "type": "SyntaxAnalysisException" + } + +* **Workaround** + +You need to confirm if the syntax is not supported and disable query analysis if that's the case by the following steps: + +1. Identify syntax error in failed query, and correct the syntax if the query does not follow MySQL grammar. Go to step 2 if your query is correct in syntax but it still ends up syntax exception. + +1. Disable strict query analysis in new ANTLR parser with the following code block. + +1. Verify if the query can pass now. If the query fails as well, please create an issue in our `GitHub Issues `_ section to report bugs fixing or request new features. + +.. code-block:: JSON + + #Disable query analysis + curl -H 'Content-Type: application/json' -X PUT localhost:9200/_cluster/settings -d '{ + "persistent" : { + "opendistro.sql.query.analysis.enabled" : false + } + }' + + #Verify if the query can pass the verification now + curl -H 'Content-Type: application/json' -X POST localhost:9200/_opendistro/_sql -d '{ + "query" : "SELECT * FROM ..." + }' + + +Index Mapping Verification Exception +------------------------------------ + +* **Symptoms** +.. code-block:: JSON + + { + "error": { + "reason": "There was internal problem at backend", + "details": "When using multiple indices, the mappings must be identical.", + "type": "VerificationException" + }, + "status": 503 + } + +* **Workaround** + +If index in query is not an index pattern (index name ends with wildcard), check if the index has multiple types. If nothing works during your workaround, please create an issue in our `GitHub Issues `_ section so that we can provide you with our suggestions and help. \ No newline at end of file diff --git a/docs/user/index.rst b/docs/user/index.rst index 7d6c9616bb..04d3c05a8c 100644 --- a/docs/user/index.rst +++ b/docs/user/index.rst @@ -31,3 +31,7 @@ Open Distro for Elasticsearch SQL enables you to extract insights out of Elastic - TODO: Elasticsearch features +* **Troubleshooting** + + - `Troubleshooting `_ + From 14cccfc82cde036f5de4572c128af0d69341e5db Mon Sep 17 00:00:00 2001 From: chloe-zh Date: Tue, 25 Feb 2020 17:44:19 -0800 Subject: [PATCH 03/10] Revised troubleshooting page --- docs/user/dql/troubleshooting.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/user/dql/troubleshooting.rst b/docs/user/dql/troubleshooting.rst index 9ec7fd0945..7f73c34181 100644 --- a/docs/user/dql/troubleshooting.rst +++ b/docs/user/dql/troubleshooting.rst @@ -23,13 +23,19 @@ Syntax Analysis / Semantic Analysis Exceptions When you end up with exceptions similar to as follows: -Query:: +Query: + +.. code-block:: JSON + POST /_opendistro/_sql { "query" : "SELECT * FROM sample:data" } -Result:: +Result: + +.. code-block:: JSON + { "reason": "Invalid SQL query", "details": "Failed to parse query due to offending symbol [:] at: 'SELECT * FROM xxx WHERE xxx:' <--- HERE... More details: Expecting tokens in {, 'AND', 'BETWEEN', 'GROUP', 'HAVING', 'IN', 'IS', 'LIKE', 'LIMIT', From f98df42a0e74df5d4ee5969a4c026076798a665f Mon Sep 17 00:00:00 2001 From: chloe-zh Date: Tue, 25 Feb 2020 17:45:22 -0800 Subject: [PATCH 04/10] update --- docs/user/dql/troubleshooting.rst | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/user/dql/troubleshooting.rst b/docs/user/dql/troubleshooting.rst index 7f73c34181..3df8e7ba1f 100644 --- a/docs/user/dql/troubleshooting.rst +++ b/docs/user/dql/troubleshooting.rst @@ -3,8 +3,6 @@ Basic Query =========== -.. rubric:: Content - .. contents:: :local: :depth: 2 @@ -19,7 +17,7 @@ SQL plugin is stateless for now so mostly the troubleshooting is mainly focused Syntax Analysis / Semantic Analysis Exceptions ---------------------------------------------- -* **Symptoms** +**Symptoms** When you end up with exceptions similar to as follows: @@ -43,7 +41,7 @@ Result: "type": "SyntaxAnalysisException" } -* **Workaround** +**Workaround** You need to confirm if the syntax is not supported and disable query analysis if that's the case by the following steps: @@ -71,7 +69,7 @@ You need to confirm if the syntax is not supported and disable query analysis if Index Mapping Verification Exception ------------------------------------ -* **Symptoms** +**Symptoms** .. code-block:: JSON { @@ -83,6 +81,6 @@ Index Mapping Verification Exception "status": 503 } -* **Workaround** +**Workaround** If index in query is not an index pattern (index name ends with wildcard), check if the index has multiple types. If nothing works during your workaround, please create an issue in our `GitHub Issues `_ section so that we can provide you with our suggestions and help. \ No newline at end of file From ca13dd4deb8f6387a01c0fa82b0a5cb76d586d6f Mon Sep 17 00:00:00 2001 From: chloe-zh Date: Tue, 25 Feb 2020 17:53:08 -0800 Subject: [PATCH 05/10] update --- docs/user/dql/troubleshooting.rst | 13 ++++++++----- .../sql/executor/multi/MinusExecutor.java | 4 ++-- .../sql/parser/ElasticSqlSelectParser.java | 1 - .../sql/parser/FieldMaker.java | 1 - 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/user/dql/troubleshooting.rst b/docs/user/dql/troubleshooting.rst index 3df8e7ba1f..704fe9a4f2 100644 --- a/docs/user/dql/troubleshooting.rst +++ b/docs/user/dql/troubleshooting.rst @@ -1,7 +1,7 @@ -=========== -Basic Query -=========== +=============== +Troubleshooting +=============== .. contents:: :local: @@ -36,8 +36,10 @@ Result: { "reason": "Invalid SQL query", - "details": "Failed to parse query due to offending symbol [:] at: 'SELECT * FROM xxx WHERE xxx:' <--- HERE... More details: Expecting tokens in {, 'AND', 'BETWEEN', 'GROUP', 'HAVING', 'IN', 'IS', 'LIKE', 'LIMIT', - 'NOT', 'OR', 'ORDER', 'REGEXP', '*', '/', '%', '+', '-', 'DIV', 'MOD', '=', '>', '<', '!', '|', '&', '^', '.', DOT_ID}", + "details": "Failed to parse query due to offending symbol [:] at: 'SELECT * FROM xxx WHERE xxx:' <--- HERE... + More details: Expecting tokens in {, 'AND', 'BETWEEN', 'GROUP', 'HAVING', 'IN', 'IS', 'LIKE', 'LIMIT', + 'NOT', 'OR', 'ORDER', 'REGEXP', '*', '/', '%', '+', '-', 'DIV', 'MOD', '=', '>', '<', '!', + '|', '&', '^', '.', DOT_ID}", "type": "SyntaxAnalysisException" } @@ -70,6 +72,7 @@ Index Mapping Verification Exception ------------------------------------ **Symptoms** + .. code-block:: JSON { diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MinusExecutor.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MinusExecutor.java index 89f2be952a..cd387b8740 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MinusExecutor.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MinusExecutor.java @@ -37,7 +37,6 @@ import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; -import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -83,7 +82,8 @@ public void run() throws SqlParseException { "Terms optimization failed: terms optimization for minus execution is supported with one field"); } if (this.useTermsOptimization && !this.useScrolling) { - throw new SqlParseException("Terms optimization failed: using scrolling is required for terms optimization"); + throw new SqlParseException( + "Terms optimization failed: using scrolling is required for terms optimization"); } if (!this.useScrolling || !this.useTermsOptimization) { Set comperableHitResults; diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlSelectParser.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlSelectParser.java index 7fa33d6e6b..e763e7facb 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlSelectParser.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlSelectParser.java @@ -33,7 +33,6 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectGroupBy; import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery; -import com.alibaba.druid.sql.parser.ParserException; import com.alibaba.druid.sql.parser.SQLExprParser; import com.alibaba.druid.sql.parser.SQLSelectParser; import com.alibaba.druid.sql.parser.Token; diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/FieldMaker.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/FieldMaker.java index e66c4d86c7..2439b77976 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/FieldMaker.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/FieldMaker.java @@ -42,7 +42,6 @@ import com.amazon.opendistroforelasticsearch.sql.exception.SqlFeatureNotImplementedException; import com.amazon.opendistroforelasticsearch.sql.exception.SqlParseException; import com.amazon.opendistroforelasticsearch.sql.utils.SQLFunctions; -import com.amazon.opendistroforelasticsearch.sql.utils.StringUtils; import com.amazon.opendistroforelasticsearch.sql.utils.Util; import com.google.common.base.Strings; import org.elasticsearch.common.collect.Tuple; From 8b98cf1a696e6fb63c93854064dfa0e0cd9a0d9c Mon Sep 17 00:00:00 2001 From: chloe-zh Date: Mon, 2 Mar 2020 09:55:38 -0800 Subject: [PATCH 06/10] addressed comments --- docs/user/dql/troubleshooting.rst | 6 +++--- .../sql/spatial/WktToGeoJsonConverter.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/user/dql/troubleshooting.rst b/docs/user/dql/troubleshooting.rst index 704fe9a4f2..f4000de881 100644 --- a/docs/user/dql/troubleshooting.rst +++ b/docs/user/dql/troubleshooting.rst @@ -11,7 +11,7 @@ Troubleshooting Narrative ========= -SQL plugin is stateless for now so mostly the troubleshooting is mainly focused on why a single query fails. +SQL plugin is stateless for now so mostly the troubleshooting is focused on why a single query fails. Syntax Analysis / Semantic Analysis Exceptions @@ -49,9 +49,9 @@ You need to confirm if the syntax is not supported and disable query analysis if 1. Identify syntax error in failed query, and correct the syntax if the query does not follow MySQL grammar. Go to step 2 if your query is correct in syntax but it still ends up syntax exception. -1. Disable strict query analysis in new ANTLR parser with the following code block. +#. Disable strict query analysis in new ANTLR parser with the following code block. -1. Verify if the query can pass now. If the query fails as well, please create an issue in our `GitHub Issues `_ section to report bugs fixing or request new features. +#. Verify if the query can pass now. If the query fails as well, please create an issue in our `GitHub Issues `_ section to report bugs fixing or request new features. .. code-block:: JSON diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java index 7f435a0ae8..3741af009b 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java @@ -31,7 +31,7 @@ public static String toGeoJson(String wkt) { int startOfCoordinates = wkt.indexOf("("); if (startOfCoordinates == -1) { throw new IllegalArgumentException( - StringUtils.format("Failed to convert well-know-text [%s] to geometry type", wkt)); + StringUtils.format("Failed to convert well-known-text [%s] to geometry type", wkt)); } String wktType = wkt.substring(0, startOfCoordinates).trim(); From 6024b679c618f156b6611e7cddf0c98949206dca Mon Sep 17 00:00:00 2001 From: chloe-zh Date: Sun, 15 Mar 2020 20:37:31 -0700 Subject: [PATCH 07/10] addressed comments --- .../sql/domain/Condition.java | 70 ++++++++++--------- .../sql/domain/Having.java | 4 +- .../sql/domain/SearchResult.java | 2 +- .../executor/GetIndexRequestRestListener.java | 3 +- .../join/NestedLoopsElasticExecutor.java | 4 +- .../sql/executor/multi/MinusExecutor.java | 2 +- .../multi/MultiRequestExecutorFactory.java | 7 +- .../sql/parser/CaseWhenParser.java | 2 +- .../sql/parser/ElasticSqlExprParser.java | 33 ++++----- .../sql/parser/NestedType.java | 3 +- .../sql/parser/WhereParser.java | 6 +- .../sql/query/join/ESHashJoinQueryAction.java | 4 +- .../query/join/ESJoinQueryActionFactory.java | 2 +- .../sql/query/maker/Maker.java | 22 +++--- .../sql/query/maker/QueryMaker.java | 2 +- .../sql/spatial/WktToGeoJsonConverter.java | 3 +- .../sql/unittest/parser/SqlParserTest.java | 21 +++--- 17 files changed, 97 insertions(+), 93 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java index 90e9fb92d2..2e7e34ea56 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java @@ -16,6 +16,8 @@ package com.amazon.opendistroforelasticsearch.sql.domain; import com.alibaba.druid.sql.ast.SQLExpr; +import com.amazon.opendistroforelasticsearch.sql.antlr.semantic.SemanticAnalysisException; +import com.amazon.opendistroforelasticsearch.sql.antlr.syntax.SyntaxAnalysisException; import com.amazon.opendistroforelasticsearch.sql.exception.SqlParseException; import com.amazon.opendistroforelasticsearch.sql.parser.ChildrenType; import com.amazon.opendistroforelasticsearch.sql.parser.NestedType; @@ -34,7 +36,7 @@ */ public class Condition extends Where { - public enum OPEAR { + public enum OPERATOR { EQ, GT, @@ -65,15 +67,15 @@ public enum OPEAR { NIN_TERMS, NTERM; - public static Map methodNameToOpear; + public static Map methodNameToOpear; - public static Map operStringToOpear; + public static Map operStringToOpear; - public static Map simpleOperStringToOpear; + public static Map simpleOperStringToOpear; - private static BiMap negatives; + private static BiMap negatives; - private static BiMap simpleReverses; + private static BiMap simpleReverses; static { methodNameToOpear = new HashMap<>(); @@ -146,20 +148,20 @@ public enum OPEAR { simpleReverses.put(N, N); } - public OPEAR negative() throws SqlParseException { - OPEAR negative = negatives.get(this); + public OPERATOR negative() { + OPERATOR negative = negatives.get(this); negative = negative != null ? negative : negatives.inverse().get(this); if (negative == null) { - throw new SqlParseException("OPEAR negative not supported: " + this); + throw new SemanticAnalysisException(StringUtils.format("Negative operator [%s] is not supported.", this.name())); } return negative; } - public OPEAR simpleReverse() throws SqlParseException { - OPEAR reverse = simpleReverses.get(this); + public OPERATOR simpleReverse() { + OPERATOR reverse = simpleReverses.get(this); reverse = reverse != null ? reverse : simpleReverses.inverse().get(this); if (reverse == null) { - throw new SqlParseException("OPEAR simple negative not supported: " + this); + throw new SemanticAnalysisException(StringUtils.format("Simple reverse operator [%s] is not supported.", this.name())); } return reverse; } @@ -185,7 +187,7 @@ public SQLExpr getValueExpr() { private SQLExpr valueExpr; - private OPEAR opear; + private OPERATOR OPERATOR; private Object relationshipType; @@ -200,7 +202,7 @@ public Condition(CONN conn, String field, SQLExpr nameExpr, String condition, Ob this(conn, field, nameExpr, condition, obj, valueExpr, null); } - public Condition(CONN conn, String field, SQLExpr nameExpr, OPEAR condition, Object obj, SQLExpr valueExpr) + public Condition(CONN conn, String field, SQLExpr nameExpr, OPERATOR condition, Object obj, SQLExpr valueExpr) throws SqlParseException { this(conn, field, nameExpr, condition, obj, valueExpr, null); } @@ -209,7 +211,7 @@ public Condition(CONN conn, String name, SQLExpr nameExpr, String oper, Object value, SQLExpr valueExpr, Object relationshipType) throws SqlParseException { super(conn); - this.opear = null; + this.OPERATOR = null; this.name = name; this.value = value; this.nameExpr = nameExpr; @@ -240,10 +242,10 @@ public Condition(CONN conn, String name, SQLExpr nameExpr, String oper, this.childType = ""; } - if (OPEAR.operStringToOpear.containsKey(oper)) { - this.opear = OPEAR.operStringToOpear.get(oper); + if (OPERATOR.operStringToOpear.containsKey(oper)) { + this.OPERATOR = OPERATOR.operStringToOpear.get(oper); } else { - throw new SqlParseException("Unsupported operation: " + oper); + throw new SemanticAnalysisException("Unsupported operation: " + oper); } } @@ -251,19 +253,19 @@ public Condition(CONN conn, String name, SQLExpr nameExpr, String oper, public Condition(CONN conn, String name, SQLExpr nameExpr, - OPEAR oper, + OPERATOR oper, Object value, SQLExpr valueExpr, Object relationshipType ) throws SqlParseException { super(conn); - this.opear = null; + this.OPERATOR = null; this.nameExpr = nameExpr; this.valueExpr = valueExpr; this.name = name; this.value = value; - this.opear = oper; + this.OPERATOR = oper; this.relationshipType = relationshipType; if (this.relationshipType != null) { @@ -290,8 +292,8 @@ public Condition(CONN conn, } } - public String getOpertatorSymbol() throws SqlParseException { - switch (opear) { + public String getOpertatorSymbol() { + switch (OPERATOR) { case EQ: return "=="; case GT: @@ -310,7 +312,7 @@ public String getOpertatorSymbol() throws SqlParseException { case ISN: return "!="; default: - throw new SqlParseException(StringUtils.format("Failed to parse operator [%s]", opear)); + throw new SyntaxAnalysisException(StringUtils.format("Failed to parse operator [%s]", OPERATOR)); } } @@ -331,12 +333,12 @@ public void setValue(Object value) { this.value = value; } - public OPEAR getOpear() { - return opear; + public OPERATOR getOPERATOR() { + return OPERATOR; } - public void setOpear(OPEAR opear) { - this.opear = opear; + public void setOPERATOR(OPERATOR OPERATOR) { + this.OPERATOR = OPERATOR; } public Object getRelationshipType() { @@ -380,12 +382,12 @@ public void setChildType(String childType) { } /** - * Return true if the opear is {@link OPEAR#NESTED_COMPLEX} - * For example, the opear is {@link OPEAR#NESTED_COMPLEX} when condition is + * Return true if the opear is {@link OPERATOR#NESTED_COMPLEX} + * For example, the opear is {@link OPERATOR#NESTED_COMPLEX} when condition is * nested('projects', projects.started_year > 2000 OR projects.name LIKE '%security%') */ public boolean isNestedComplex() { - return OPEAR.NESTED_COMPLEX == opear; + return OPERATOR.NESTED_COMPLEX == OPERATOR; } @Override @@ -406,9 +408,9 @@ public String toString() { } if (value instanceof Object[]) { - result += this.conn + " " + this.name + " " + this.opear + " " + Arrays.toString((Object[]) value); + result += this.conn + " " + this.name + " " + this.OPERATOR + " " + Arrays.toString((Object[]) value); } else { - result += this.conn + " " + this.name + " " + this.opear + " " + this.value; + result += this.conn + " " + this.name + " " + this.OPERATOR + " " + this.value; } return result; @@ -418,7 +420,7 @@ public String toString() { public Object clone() throws CloneNotSupportedException { try { return new Condition(this.getConn(), this.getName(), this.getNameExpr(), - this.getOpear(), this.getValue(), this.getValueExpr(), this.getRelationshipType()); + this.getOPERATOR(), this.getValue(), this.getValueExpr(), this.getRelationshipType()); } catch (SqlParseException e) { } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Having.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Having.java index 5d3e0fcbeb..e8ff690a54 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Having.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Having.java @@ -178,7 +178,7 @@ private String doExplain(List wheres) throws SqlParseException { private String createScript(Condition cond) throws SqlParseException { String name = cond.getName(); Object value = cond.getValue(); - switch (cond.getOpear()) { + switch (cond.getOPERATOR()) { case EQ: case GT: case LT: @@ -206,7 +206,7 @@ private String createScript(Condition cond) throws SqlParseException { map(val -> expr(name, "!=", val)). collect(joining(AND)); default: - throw new SqlParseException("Unsupported operation in HAVING clause: " + cond.getOpear()); + throw new SqlParseException("Unsupported operation in HAVING clause: " + cond.getOPERATOR()); } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/SearchResult.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/SearchResult.java index 94aae134e2..2222fac52d 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/SearchResult.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/SearchResult.java @@ -135,7 +135,7 @@ private Object covenValue(Aggregation value) throws SqlParseException { } else if (value instanceof LongTerms) { return value; } else { - throw new SqlParseException("Unknown aggregation value type: " + value.getClass()); + throw new SqlParseException("Unknown aggregation value type: " + value.getClass().getSimpleName()); } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/GetIndexRequestRestListener.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/GetIndexRequestRestListener.java index c823e6123f..a81bcf9429 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/GetIndexRequestRestListener.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/GetIndexRequestRestListener.java @@ -15,6 +15,7 @@ package com.amazon.opendistroforelasticsearch.sql.executor; +import com.amazon.opendistroforelasticsearch.sql.antlr.semantic.SemanticAnalysisException; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.elasticsearch.action.admin.indices.get.GetIndexRequest; import org.elasticsearch.action.admin.indices.get.GetIndexResponse; @@ -65,7 +66,7 @@ public RestResponse buildResponse(GetIndexResponse getIndexResponse, XContentBui writeSettings(getIndexResponse.settings().get(index), builder, channel.request()); break; default: - throw new IllegalStateException("Unsupported feature: " + feature); + throw new SemanticAnalysisException("Unsupported feature: " + feature); } } builder.endObject(); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/join/NestedLoopsElasticExecutor.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/join/NestedLoopsElasticExecutor.java index 23f7026b85..badf5642fc 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/join/NestedLoopsElasticExecutor.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/join/NestedLoopsElasticExecutor.java @@ -307,11 +307,11 @@ private void orderConditionRecursive(String t1Alias, String t2Alias, Where where private Boolean shouldReverse(Condition cond, String t1Alias, String t2Alias) { return cond.getName().startsWith(t1Alias + ".") && cond.getValue().toString().startsWith(t2Alias + ".") - && cond.getOpear().isSimpleOperator(); + && cond.getOPERATOR().isSimpleOperator(); } private void reverseOrderOfCondition(Condition cond, String t1Alias, String t2Alias) throws SqlParseException { - cond.setOpear(cond.getOpear().simpleReverse()); + cond.setOPERATOR(cond.getOPERATOR().simpleReverse()); String name = cond.getName(); cond.setName(cond.getValue().toString().replaceFirst(t2Alias + ".", "")); cond.setValue(name.replaceFirst(t1Alias + ".", "")); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MinusExecutor.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MinusExecutor.java index cd387b8740..6441024f70 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MinusExecutor.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MinusExecutor.java @@ -368,7 +368,7 @@ private Where createWhereWithOrigianlAndTermsFilter(String secondFieldName, Wher } private Where buildTermsFilterFromResults(Set results, String fieldName) throws SqlParseException { - return new Condition(Where.CONN.AND, fieldName, null, Condition.OPEAR.IN_TERMS, results.toArray(), null); + return new Condition(Where.CONN.AND, fieldName, null, Condition.OPERATOR.IN_TERMS, results.toArray(), null); } private Object getFieldValue(SearchHit hit, String fieldName) { diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MultiRequestExecutorFactory.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MultiRequestExecutorFactory.java index 5d4263a8a3..3d52d9bf80 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MultiRequestExecutorFactory.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/multi/MultiRequestExecutorFactory.java @@ -16,7 +16,7 @@ package com.amazon.opendistroforelasticsearch.sql.executor.multi; import com.alibaba.druid.sql.ast.statement.SQLUnionOperator; -import com.amazon.opendistroforelasticsearch.sql.exception.SqlParseException; +import com.amazon.opendistroforelasticsearch.sql.antlr.semantic.SemanticAnalysisException; import com.amazon.opendistroforelasticsearch.sql.executor.ElasticHitsExecutor; import com.amazon.opendistroforelasticsearch.sql.query.multi.MultiQueryRequestBuilder; import org.elasticsearch.client.Client; @@ -25,8 +25,7 @@ * Created by Eliran on 21/8/2016. */ public class MultiRequestExecutorFactory { - public static ElasticHitsExecutor createExecutor(Client client, MultiQueryRequestBuilder builder) - throws SqlParseException { + public static ElasticHitsExecutor createExecutor(Client client, MultiQueryRequestBuilder builder) { SQLUnionOperator relation = builder.getRelation(); switch (relation) { case UNION_ALL: @@ -35,7 +34,7 @@ public static ElasticHitsExecutor createExecutor(Client client, MultiQueryReques case MINUS: return new MinusExecutor(client, builder); default: - throw new SqlParseException("Unsupported operator: " + relation); + throw new SemanticAnalysisException("Unsupported operator: " + relation); } } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/CaseWhenParser.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/CaseWhenParser.java index 4633799d77..13d2ee2793 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/CaseWhenParser.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/CaseWhenParser.java @@ -102,7 +102,7 @@ private void explainWhere(List codes, Where where) throws SqlParseExcept if (condition.getValue() instanceof ScriptFilter) { codes.add("(" + ((ScriptFilter) condition.getValue()).getScript() + ")"); - } else if (condition.getOpear() == Condition.OPEAR.BETWEEN) { + } else if (condition.getOPERATOR() == Condition.OPERATOR.BETWEEN) { Object[] objs = (Object[]) condition.getValue(); codes.add("(" + "doc['" + condition.getName() + "'].value >= " + objs[0] + " && doc['" + condition.getName() + "'].value <=" + objs[1] + ")"); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java index b2be734782..6cb4302273 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java @@ -59,6 +59,7 @@ import com.alibaba.druid.sql.parser.Token; import com.alibaba.druid.util.JdbcConstants; +import com.amazon.opendistroforelasticsearch.sql.antlr.syntax.SyntaxAnalysisException; import java.util.List; import static com.amazon.opendistroforelasticsearch.sql.utils.StringUtils.isQuoted; @@ -120,7 +121,7 @@ protected SQLExpr methodRest(SQLExpr expr, boolean acceptLPAREN) { return primaryRest(methodInvokeExpr); } - throw new ParserException("Syntax error:" + lexer.token()); + throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); } @@ -283,7 +284,7 @@ public SQLExpr primary2() { case VALUES: lexer.nextToken(); if (lexer.token() != Token.LPAREN) { - throw new ParserException("Syntax error: " + lexer.token()); + throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); } return this.methodRest(new SQLIdentifierExpr("VALUES"), true); case BINARY: @@ -363,7 +364,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { if ("USING".equalsIgnoreCase(lexer.stringVal())) { lexer.nextToken(); if (lexer.token() != Token.IDENTIFIER) { - throw new ParserException("Syntax error: " + lexer.token()); + throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); } String charSet = lexer.stringVal(); lexer.nextToken(); @@ -379,7 +380,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { } if (lexer.token() != Token.IDENTIFIER) { - throw new ParserException("Syntax error: " + lexer.token()); + throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); } String collate = lexer.stringVal(); @@ -394,7 +395,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { lexer.nextToken(); if (lexer.token() != Token.IDENTIFIER) { - throw new ParserException("Syntax error: " + lexer.token()); + throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); } String collate = lexer.stringVal(); @@ -424,7 +425,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { lexer.nextToken(); if (lexer.token() != Token.IDENTIFIER) { - throw new ParserException("Syntax error: " + lexer.token()); + throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); } String unitVal = lexer.stringVal(); @@ -467,7 +468,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { } else if (lexer.token() == Token.RPAREN) { break; } else { - throw new ParserException("Syntax error: " + lexer.token()); + throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); } } @@ -544,10 +545,10 @@ public final SQLExpr primaryRest(SQLExpr expr) { acceptIdentifier("MODE"); matchAgainstExpr.setSearchModifier(MySqlMatchAgainstExpr.SearchModifier.IN_BOOLEAN_MODE); } else { - throw new ParserException("Syntax error: " + lexer.token()); + throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); } } else if (lexer.token() == Token.WITH) { - throw new ParserException("Syntax error: " + lexer.token()); + throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); } accept(Token.RPAREN); @@ -566,7 +567,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { if (identifierEquals("USING")) { lexer.nextToken(); if (lexer.token() != Token.IDENTIFIER) { - throw new ParserException("Syntax error: " + lexer.token()); + throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); } String charset = lexer.stringVal(); lexer.nextToken(); @@ -620,7 +621,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { } if (lexer.token() == Token.ERROR) { - throw new ParserException("syntax error, token: " + lexer.token() + " " + lexer.stringVal() + ", pos : " + throw new SyntaxAnalysisException("Syntax error, token: " + lexer.token() + " " + lexer.stringVal() + ", pos: " + lexer.pos()); } @@ -651,7 +652,7 @@ protected SQLExpr bracketRest(SQLExpr expr) { index = lexer.integerValue(); lexer.nextToken(); } else { - throw new ParserException("Syntax error : " + lexer.stringVal()); + throw new SyntaxAnalysisException("Syntax error : " + lexer.stringVal()); } if (expr instanceof SQLMethodInvokeExpr) { @@ -685,7 +686,7 @@ protected SQLExpr parseInterval() { SQLExpr value = expr(); if (lexer.token() != Token.IDENTIFIER) { - throw new ParserException("Syntax error: " + lexer.token()); + throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); } String unit = lexer.stringVal(); @@ -728,7 +729,7 @@ public SQLColumnDefinition parseColumnRest(SQLColumnDefinition column) { } if (identifierEquals("PARTITION")) { - throw new ParserException("syntax error " + lexer.token() + " " + lexer.stringVal()); + throw new SyntaxAnalysisException("syntax error " + lexer.token() + " " + lexer.stringVal()); } if (identifierEquals("STORAGE")) { @@ -989,7 +990,7 @@ public MysqlForeignKey parseForeignKey() { } else if (lexer.token() == Token.UPDATE) { fk.setReferenceOn(MysqlForeignKey.On.UPDATE); } else { - throw new ParserException("syntax error, expect DELETE or UPDATE, actual " + lexer.token() + " " + throw new SyntaxAnalysisException("Syntax error, expect DELETE or UPDATE, actual " + lexer.token() + " " + lexer.stringVal()); } lexer.nextToken(); @@ -1006,7 +1007,7 @@ public MysqlForeignKey parseForeignKey() { if (identifierEquals("ACTION")) { fk.setReferenceOption(MysqlForeignKey.Option.NO_ACTION); } else { - throw new ParserException("syntax error, expect ACTION, actual " + lexer.token() + " " + throw new SyntaxAnalysisException("Syntax error, expect ACTION, actual " + lexer.token() + " " + lexer.stringVal()); } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java index 5d6f68eb9e..dd9fe1fb78 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java @@ -20,6 +20,7 @@ import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr; import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr; import com.alibaba.druid.sql.ast.expr.SQLTextLiteralExpr; +import com.amazon.opendistroforelasticsearch.sql.antlr.semantic.SemanticAnalysisException; import com.amazon.opendistroforelasticsearch.sql.domain.Where; import com.amazon.opendistroforelasticsearch.sql.domain.bucketpath.BucketPath; import com.amazon.opendistroforelasticsearch.sql.domain.bucketpath.Path; @@ -53,7 +54,7 @@ public boolean tryFillFromExpr(SQLExpr expr) throws SqlParseException { List parameters = method.getParameters(); if (parameters.size() != 2 && parameters.size() != 1) { - throw new SqlParseException("on nested object only allowed 2 parameters (field,path)/(path,conditions..) " + throw new SemanticAnalysisException("on nested object only allowed 2 parameters (field,path)/(path,conditions..) " + "or 1 parameter (field) "); } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/WhereParser.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/WhereParser.java index 762c3a2c80..dccfdcaee5 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/WhereParser.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/WhereParser.java @@ -125,7 +125,7 @@ private void negateWhere(Where where) throws SqlParseException { for (Where sub : where.getWheres()) { if (sub instanceof Condition) { Condition cond = (Condition) sub; - cond.setOpear(cond.getOpear().negative()); + cond.setOPERATOR(cond.getOPERATOR().negative()); } else { negateWhere(sub); } @@ -255,12 +255,12 @@ private void explainCond(String opear, SQLExpr expr, Where where) throws SqlPars SQLMethodInvokeExpr method = (SQLMethodInvokeExpr) soExpr.getRight(); String methodName = method.getMethodName().toLowerCase(); - if (Condition.OPEAR.methodNameToOpear.containsKey(methodName)) { + if (Condition.OPERATOR.methodNameToOpear.containsKey(methodName)) { Object[] methodParametersValue = getMethodValuesWithSubQueries(method); final Condition condition; // fix OPEAR - Condition.OPEAR oper = Condition.OPEAR.methodNameToOpear.get(methodName); + Condition.OPERATOR oper = Condition.OPERATOR.methodNameToOpear.get(methodName); if (soExpr.getOperator() == SQLBinaryOperator.LessThanOrGreater || soExpr.getOperator() == SQLBinaryOperator.NotEqual) { oper = oper.negative(); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/join/ESHashJoinQueryAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/join/ESHashJoinQueryAction.java index d96aac9c27..12a8f3969d 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/join/ESHashJoinQueryAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/join/ESHashJoinQueryAction.java @@ -86,10 +86,10 @@ private List> getComparisonFields(String t1Alias, String List> comparisonFields = new ArrayList<>(); for (Condition condition : connectedConditions) { - if (condition.getOpear() != Condition.OPEAR.EQ) { + if (condition.getOPERATOR() != Condition.OPERATOR.EQ) { throw new SqlParseException( String.format("HashJoin should only be with EQ conditions, got:%s on condition:%s", - condition.getOpear().name(), condition.toString())); + condition.getOPERATOR().name(), condition.toString())); } String firstField = condition.getName(); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/join/ESJoinQueryActionFactory.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/join/ESJoinQueryActionFactory.java index fbd67b3f65..67ac835cc1 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/join/ESJoinQueryActionFactory.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/join/ESJoinQueryActionFactory.java @@ -32,7 +32,7 @@ public static QueryAction createJoinAction(Client client, JoinSelect joinSelect) List connectedConditions = joinSelect.getConnectedConditions(); boolean allEqual = true; for (Condition condition : connectedConditions) { - if (condition.getOpear() != Condition.OPEAR.EQ) { + if (condition.getOPERATOR() != Condition.OPERATOR.EQ) { allEqual = false; break; } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/Maker.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/Maker.java index db6bb599e0..a362610827 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/Maker.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/Maker.java @@ -87,10 +87,10 @@ public abstract class Maker { "matchphrasequery", "match_phrase", "matchphrase" // match-phrase ); - private static final Set NOT_OPEAR_SET = ImmutableSet.of( - Condition.OPEAR.N, Condition.OPEAR.NIN, Condition.OPEAR.ISN, Condition.OPEAR.NBETWEEN, - Condition.OPEAR.NLIKE, Condition.OPEAR.NIN_TERMS, Condition.OPEAR.NTERM, - Condition.OPEAR.NOT_EXISTS_NESTED_COMPLEX + private static final Set NOT_OPERATOR_SET = ImmutableSet.of( + Condition.OPERATOR.N, Condition.OPERATOR.NIN, Condition.OPERATOR.ISN, Condition.OPERATOR.NBETWEEN, + Condition.OPERATOR.NLIKE, Condition.OPERATOR.NIN_TERMS, Condition.OPERATOR.NTERM, + Condition.OPERATOR.NOT_EXISTS_NESTED_COMPLEX ); protected Maker(Boolean isQuery) { @@ -134,14 +134,14 @@ private ToXContent make(Condition cond, String name, SQLMethodInvokeExpr value) paramer = Paramer.parseParamer(value); QueryStringQueryBuilder queryString = QueryBuilders.queryStringQuery(paramer.value); bqb = Paramer.fullParamer(queryString, paramer); - bqb = applyNot(cond.getOpear(), bqb); + bqb = applyNot(cond.getOPERATOR(), bqb); break; case "matchquery": case "match_query": paramer = Paramer.parseParamer(value); MatchQueryBuilder matchQuery = QueryBuilders.matchQuery(name, paramer.value); bqb = Paramer.fullParamer(matchQuery, paramer); - bqb = applyNot(cond.getOpear(), bqb); + bqb = applyNot(cond.getOPERATOR(), bqb); break; case "score": case "scorequery": @@ -186,7 +186,7 @@ private ToXContent make(Condition cond, String name, SQLMethodInvokeExpr value) private ToXContent make(Condition cond, String name, Object value) throws SqlParseException { ToXContent toXContent = null; - switch (cond.getOpear()) { + switch (cond.getOPERATOR()) { case ISN: case IS: case N: @@ -367,7 +367,7 @@ private ToXContent make(Condition cond, String name, Object value) throws SqlPar throw new SqlParseException("Undefined condition: " + cond.getName()); } - toXContent = applyNot(cond.getOpear(), toXContent); + toXContent = applyNot(cond.getOPERATOR(), toXContent); return toXContent; } @@ -438,7 +438,7 @@ private ToXContent makeForDateFormat(SQLMethodInvokeExpr nameExpr, SQLCharExpr v throw new SqlParseException("date_format does not support the operation " + oper); } - toXContent = applyNot(Condition.OPEAR.operStringToOpear.get(oper), toXContent); + toXContent = applyNot(Condition.OPERATOR.operStringToOpear.get(oper), toXContent); return toXContent; } @@ -495,8 +495,8 @@ private String trimApostrophes(String str) { /** * Applies negation to query builder if the operation is a "not" operation. */ - private ToXContent applyNot(Condition.OPEAR opear, ToXContent bqb) { - if (NOT_OPEAR_SET.contains(opear)) { + private ToXContent applyNot(Condition.OPERATOR OPERATOR, ToXContent bqb) { + if (NOT_OPERATOR_SET.contains(OPERATOR)) { bqb = QueryBuilders.boolQuery().mustNot((QueryBuilder) bqb); } return bqb; diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/QueryMaker.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/QueryMaker.java index ef4512f548..f4de8f4e59 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/QueryMaker.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/QueryMaker.java @@ -80,7 +80,7 @@ private void addSubQuery(BoolQueryBuilder boolQuery, Where where, QueryBuilder s if (condition.isNested()) { // bugfix #628 if ("missing".equalsIgnoreCase(String.valueOf(condition.getValue())) - && (condition.getOpear() == Condition.OPEAR.IS || condition.getOpear() == Condition.OPEAR.EQ)) { + && (condition.getOPERATOR() == Condition.OPERATOR.IS || condition.getOPERATOR() == Condition.OPERATOR.EQ)) { boolQuery.mustNot(QueryBuilders.nestedQuery(condition.getNestedPath(), QueryBuilders.boolQuery().mustNot(subQuery), ScoreMode.None)); return; diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java index 3741af009b..046daa2fd8 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java @@ -16,6 +16,7 @@ package com.amazon.opendistroforelasticsearch.sql.spatial; +import com.amazon.opendistroforelasticsearch.sql.antlr.syntax.SyntaxAnalysisException; import com.amazon.opendistroforelasticsearch.sql.utils.StringUtils; import com.google.common.base.Joiner; @@ -171,7 +172,7 @@ private static String removeBrackets(String wkt, int num) { int lastClosingBrackets = result.lastIndexOf(")"); int firstOpenBrackets = result.indexOf("("); if (lastClosingBrackets == -1 || firstOpenBrackets == -1) { - throw new IllegalArgumentException("Illegal syntax: " + wkt); + throw new SyntaxAnalysisException("Illegal syntax: " + wkt); } result = result.substring(firstOpenBrackets + 1, lastClosingBrackets); } diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/sql/unittest/parser/SqlParserTest.java b/src/test/java/com/amazon/opendistroforelasticsearch/sql/unittest/parser/SqlParserTest.java index 9bf0d8ac4b..1a9cd9bd74 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/sql/unittest/parser/SqlParserTest.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/sql/unittest/parser/SqlParserTest.java @@ -61,7 +61,6 @@ import static com.amazon.opendistroforelasticsearch.sql.esintgtest.TestsConstants.TEST_INDEX_DOG; import static com.amazon.opendistroforelasticsearch.sql.esintgtest.TestsConstants.TEST_INDEX_GAME_OF_THRONES; import static com.amazon.opendistroforelasticsearch.sql.esintgtest.TestsConstants.TEST_INDEX_ODBC; -import static com.amazon.opendistroforelasticsearch.sql.util.CheckScriptContents.getScriptFieldFromQuery; import static com.amazon.opendistroforelasticsearch.sql.util.CheckScriptContents.scriptContainsString; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertTrue; @@ -307,7 +306,7 @@ public void joinParseConditionsTestOneCondition() throws SqlParseException { Assert.assertNotNull(conditions); Assert.assertEquals(1, conditions.size()); Assert.assertTrue("condition not exist: d.holdersName = a.firstname", - conditionExist(conditions, "d.holdersName", "a.firstname", Condition.OPEAR.EQ)); + conditionExist(conditions, "d.holdersName", "a.firstname", Condition.OPERATOR.EQ)); } @Test @@ -328,9 +327,9 @@ public void joinParseConditionsTestTwoConditions() throws SqlParseException { Assert.assertNotNull(conditions); Assert.assertEquals(2, conditions.size()); Assert.assertTrue("condition not exist: d.holdersName = a.firstname", - conditionExist(conditions, "d.holdersName", "a.firstname", Condition.OPEAR.EQ)); + conditionExist(conditions, "d.holdersName", "a.firstname", Condition.OPERATOR.EQ)); Assert.assertTrue("condition not exist: d.age < a.age", - conditionExist(conditions, "d.age", "a.age", Condition.OPEAR.LT)); + conditionExist(conditions, "d.age", "a.age", Condition.OPERATOR.LT)); } @@ -365,7 +364,7 @@ public void joinConditionWithComplexObjectComparisonRightSide() throws SqlParseE Assert.assertNotNull(conditions); Assert.assertEquals(1, conditions.size()); Assert.assertTrue("condition not exist: h.name = c.name.lastname", - conditionExist(conditions, "h.name", "c.name.lastname", Condition.OPEAR.EQ)); + conditionExist(conditions, "h.name", "c.name.lastname", Condition.OPERATOR.EQ)); } @Test @@ -380,7 +379,7 @@ public void joinConditionWithComplexObjectComparisonLeftSide() throws SqlParseEx Assert.assertNotNull(conditions); Assert.assertEquals(1, conditions.size()); Assert.assertTrue("condition not exist: c.name.lastname = h.name", - conditionExist(conditions, "c.name.lastname", "h.name", Condition.OPEAR.EQ)); + conditionExist(conditions, "c.name.lastname", "h.name", Condition.OPERATOR.EQ)); } @@ -941,7 +940,7 @@ public void complexNestedTest() throws SqlParseException { String query = "select * from x where nested('y',y.b = 'a' and y.c = 'd') "; Select select = parser.parseSelect((SQLQueryExpr) queryToExpr(query)); Condition condition = (Condition) select.getWhere().getWheres().get(0); - Assert.assertEquals(Condition.OPEAR.NESTED_COMPLEX, condition.getOpear()); + Assert.assertEquals(Condition.OPERATOR.NESTED_COMPLEX, condition.getOPERATOR()); Assert.assertEquals("y", condition.getName()); Assert.assertTrue(condition.getValue() instanceof Where); Where where = (Where) condition.getValue(); @@ -953,7 +952,7 @@ public void scriptOnFilterNoParams() throws SqlParseException { String query = "select * from x where script('doc[\\'field\\'].date.hourOfDay == 3') "; Select select = parser.parseSelect((SQLQueryExpr) queryToExpr(query)); Condition condition = (Condition) select.getWhere().getWheres().get(0); - Assert.assertEquals(Condition.OPEAR.SCRIPT, condition.getOpear()); + Assert.assertEquals(Condition.OPERATOR.SCRIPT, condition.getOPERATOR()); Assert.assertNull(condition.getName()); Assert.assertTrue(condition.getValue() instanceof ScriptFilter); ScriptFilter scriptFilter = (ScriptFilter) condition.getValue(); @@ -966,7 +965,7 @@ public void scriptOnFilterWithParams() throws SqlParseException { String query = "select * from x where script('doc[\\'field\\'].date.hourOfDay == x','x'=3) "; Select select = parser.parseSelect((SQLQueryExpr) queryToExpr(query)); Condition condition = (Condition) select.getWhere().getWheres().get(0); - Assert.assertEquals(Condition.OPEAR.SCRIPT, condition.getOpear()); + Assert.assertEquals(Condition.OPERATOR.SCRIPT, condition.getOPERATOR()); Assert.assertNull(condition.getName()); Assert.assertTrue(condition.getValue() instanceof ScriptFilter); ScriptFilter scriptFilter = (ScriptFilter) condition.getValue(); @@ -1414,12 +1413,12 @@ private SQLExpr queryToExpr(String query) { return new ElasticSqlExprParser(query).expr(); } - private boolean conditionExist(List conditions, String from, String to, Condition.OPEAR opear) { + private boolean conditionExist(List conditions, String from, String to, Condition.OPERATOR OPERATOR) { String[] aliasAndField = to.split("\\.", 2); String toAlias = aliasAndField[0]; String toField = aliasAndField[1]; for (Condition condition : conditions) { - if (condition.getOpear() != opear) continue; + if (condition.getOPERATOR() != OPERATOR) continue; boolean fromIsEqual = condition.getName().equals(from); if (!fromIsEqual) continue; From fa229dc88e33455002648449090a9b631c5de338 Mon Sep 17 00:00:00 2001 From: chloe-zh Date: Sun, 15 Mar 2020 20:43:39 -0700 Subject: [PATCH 08/10] update --- .../opendistroforelasticsearch/sql/domain/Condition.java | 6 ++++-- .../sql/parser/ElasticSqlExprParser.java | 4 ++-- .../opendistroforelasticsearch/sql/parser/NestedType.java | 4 ++-- .../sql/query/maker/QueryMaker.java | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java index 2e7e34ea56..36c4b35a78 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java @@ -152,7 +152,8 @@ public OPERATOR negative() { OPERATOR negative = negatives.get(this); negative = negative != null ? negative : negatives.inverse().get(this); if (negative == null) { - throw new SemanticAnalysisException(StringUtils.format("Negative operator [%s] is not supported.", this.name())); + throw new SemanticAnalysisException(StringUtils.format("Negative operator [%s] is not supported.", + this.name())); } return negative; } @@ -161,7 +162,8 @@ public OPERATOR simpleReverse() { OPERATOR reverse = simpleReverses.get(this); reverse = reverse != null ? reverse : simpleReverses.inverse().get(this); if (reverse == null) { - throw new SemanticAnalysisException(StringUtils.format("Simple reverse operator [%s] is not supported.", this.name())); + throw new SemanticAnalysisException(StringUtils.format("Simple reverse operator [%s] is not supported.", + this.name())); } return reverse; } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java index 6cb4302273..c11cea3c18 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java @@ -621,8 +621,8 @@ public final SQLExpr primaryRest(SQLExpr expr) { } if (lexer.token() == Token.ERROR) { - throw new SyntaxAnalysisException("Syntax error, token: " + lexer.token() + " " + lexer.stringVal() + ", pos: " - + lexer.pos()); + throw new SyntaxAnalysisException("Syntax error, token: " + lexer.token() + " " + lexer.stringVal() + + ", pos: " + lexer.pos()); } /** diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java index dd9fe1fb78..b06f70709e 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java @@ -54,8 +54,8 @@ public boolean tryFillFromExpr(SQLExpr expr) throws SqlParseException { List parameters = method.getParameters(); if (parameters.size() != 2 && parameters.size() != 1) { - throw new SemanticAnalysisException("on nested object only allowed 2 parameters (field,path)/(path,conditions..) " - + "or 1 parameter (field) "); + throw new SemanticAnalysisException("on nested object only allowed 2 parameters " + + "(field,path)/(path,conditions..) or 1 parameter (field) "); } String field = Util.extendedToString(parameters.get(0)); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/QueryMaker.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/QueryMaker.java index f4de8f4e59..78aa90fe1e 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/QueryMaker.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/QueryMaker.java @@ -80,7 +80,8 @@ private void addSubQuery(BoolQueryBuilder boolQuery, Where where, QueryBuilder s if (condition.isNested()) { // bugfix #628 if ("missing".equalsIgnoreCase(String.valueOf(condition.getValue())) - && (condition.getOPERATOR() == Condition.OPERATOR.IS || condition.getOPERATOR() == Condition.OPERATOR.EQ)) { + && (condition.getOPERATOR() == Condition.OPERATOR.IS + || condition.getOPERATOR() == Condition.OPERATOR.EQ)) { boolQuery.mustNot(QueryBuilders.nestedQuery(condition.getNestedPath(), QueryBuilders.boolQuery().mustNot(subQuery), ScoreMode.None)); return; From 77a685095116cf3d5becefb1551c2df6584e507d Mon Sep 17 00:00:00 2001 From: chloe-zh Date: Mon, 16 Mar 2020 16:09:54 -0700 Subject: [PATCH 09/10] update --- .../opendistroforelasticsearch/sql/parser/NestedType.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java index b06f70709e..b6f1638fd1 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java @@ -54,8 +54,8 @@ public boolean tryFillFromExpr(SQLExpr expr) throws SqlParseException { List parameters = method.getParameters(); if (parameters.size() != 2 && parameters.size() != 1) { - throw new SemanticAnalysisException("on nested object only allowed 2 parameters " + - "(field,path)/(path,conditions..) or 1 parameter (field) "); + throw new SemanticAnalysisException("on nested object only allowed 2 parameters " + + "(field,path)/(path,conditions..) or 1 parameter (field) "); } String field = Util.extendedToString(parameters.get(0)); From c32511705e71a0e1c51765b0cc34482deec0bc70 Mon Sep 17 00:00:00 2001 From: chloe-zh Date: Tue, 17 Mar 2020 13:23:07 -0700 Subject: [PATCH 10/10] update --- .../sql/domain/Condition.java | 18 +++++----- .../sql/parser/ElasticSqlExprParser.java | 33 +++++++++---------- .../sql/parser/NestedType.java | 3 +- .../sql/query/maker/Maker.java | 2 +- .../sql/query/maker/QueryMaker.java | 3 +- .../sql/spatial/WktToGeoJsonConverter.java | 4 +-- 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java index 2e7e34ea56..c450364d84 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/domain/Condition.java @@ -16,8 +16,6 @@ package com.amazon.opendistroforelasticsearch.sql.domain; import com.alibaba.druid.sql.ast.SQLExpr; -import com.amazon.opendistroforelasticsearch.sql.antlr.semantic.SemanticAnalysisException; -import com.amazon.opendistroforelasticsearch.sql.antlr.syntax.SyntaxAnalysisException; import com.amazon.opendistroforelasticsearch.sql.exception.SqlParseException; import com.amazon.opendistroforelasticsearch.sql.parser.ChildrenType; import com.amazon.opendistroforelasticsearch.sql.parser.NestedType; @@ -148,20 +146,22 @@ public enum OPERATOR { simpleReverses.put(N, N); } - public OPERATOR negative() { + public OPERATOR negative() throws SqlParseException { OPERATOR negative = negatives.get(this); negative = negative != null ? negative : negatives.inverse().get(this); if (negative == null) { - throw new SemanticAnalysisException(StringUtils.format("Negative operator [%s] is not supported.", this.name())); + throw new SqlParseException(StringUtils.format("Negative operator [%s] is not supported.", + this.name())); } return negative; } - public OPERATOR simpleReverse() { + public OPERATOR simpleReverse() throws SqlParseException { OPERATOR reverse = simpleReverses.get(this); reverse = reverse != null ? reverse : simpleReverses.inverse().get(this); if (reverse == null) { - throw new SemanticAnalysisException(StringUtils.format("Simple reverse operator [%s] is not supported.", this.name())); + throw new SqlParseException(StringUtils.format("Simple reverse operator [%s] is not supported.", + this.name())); } return reverse; } @@ -245,7 +245,7 @@ public Condition(CONN conn, String name, SQLExpr nameExpr, String oper, if (OPERATOR.operStringToOpear.containsKey(oper)) { this.OPERATOR = OPERATOR.operStringToOpear.get(oper); } else { - throw new SemanticAnalysisException("Unsupported operation: " + oper); + throw new SqlParseException("Unsupported operation: " + oper); } } @@ -292,7 +292,7 @@ public Condition(CONN conn, } } - public String getOpertatorSymbol() { + public String getOpertatorSymbol() throws SqlParseException { switch (OPERATOR) { case EQ: return "=="; @@ -312,7 +312,7 @@ public String getOpertatorSymbol() { case ISN: return "!="; default: - throw new SyntaxAnalysisException(StringUtils.format("Failed to parse operator [%s]", OPERATOR)); + throw new SqlParseException(StringUtils.format("Failed to parse operator [%s]", OPERATOR)); } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java index 6cb4302273..709b73fdb8 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/ElasticSqlExprParser.java @@ -59,7 +59,6 @@ import com.alibaba.druid.sql.parser.Token; import com.alibaba.druid.util.JdbcConstants; -import com.amazon.opendistroforelasticsearch.sql.antlr.syntax.SyntaxAnalysisException; import java.util.List; import static com.amazon.opendistroforelasticsearch.sql.utils.StringUtils.isQuoted; @@ -121,7 +120,7 @@ protected SQLExpr methodRest(SQLExpr expr, boolean acceptLPAREN) { return primaryRest(methodInvokeExpr); } - throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); + throw new ParserException("Syntax error: " + lexer.token()); } @@ -284,7 +283,7 @@ public SQLExpr primary2() { case VALUES: lexer.nextToken(); if (lexer.token() != Token.LPAREN) { - throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); + throw new ParserException("Syntax error: " + lexer.token()); } return this.methodRest(new SQLIdentifierExpr("VALUES"), true); case BINARY: @@ -364,7 +363,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { if ("USING".equalsIgnoreCase(lexer.stringVal())) { lexer.nextToken(); if (lexer.token() != Token.IDENTIFIER) { - throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); + throw new ParserException("Syntax error: " + lexer.token()); } String charSet = lexer.stringVal(); lexer.nextToken(); @@ -380,7 +379,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { } if (lexer.token() != Token.IDENTIFIER) { - throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); + throw new ParserException("Syntax error: " + lexer.token()); } String collate = lexer.stringVal(); @@ -395,7 +394,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { lexer.nextToken(); if (lexer.token() != Token.IDENTIFIER) { - throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); + throw new ParserException("Syntax error: " + lexer.token()); } String collate = lexer.stringVal(); @@ -425,7 +424,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { lexer.nextToken(); if (lexer.token() != Token.IDENTIFIER) { - throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); + throw new ParserException("Syntax error: " + lexer.token()); } String unitVal = lexer.stringVal(); @@ -468,7 +467,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { } else if (lexer.token() == Token.RPAREN) { break; } else { - throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); + throw new ParserException("Syntax error: " + lexer.token()); } } @@ -545,10 +544,10 @@ public final SQLExpr primaryRest(SQLExpr expr) { acceptIdentifier("MODE"); matchAgainstExpr.setSearchModifier(MySqlMatchAgainstExpr.SearchModifier.IN_BOOLEAN_MODE); } else { - throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); + throw new ParserException("Syntax error: " + lexer.token()); } } else if (lexer.token() == Token.WITH) { - throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); + throw new ParserException("Syntax error: " + lexer.token()); } accept(Token.RPAREN); @@ -567,7 +566,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { if (identifierEquals("USING")) { lexer.nextToken(); if (lexer.token() != Token.IDENTIFIER) { - throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); + throw new ParserException("Syntax error: " + lexer.token()); } String charset = lexer.stringVal(); lexer.nextToken(); @@ -621,7 +620,7 @@ public final SQLExpr primaryRest(SQLExpr expr) { } if (lexer.token() == Token.ERROR) { - throw new SyntaxAnalysisException("Syntax error, token: " + lexer.token() + " " + lexer.stringVal() + ", pos: " + throw new ParserException("Syntax error, token: " + lexer.token() + " " + lexer.stringVal() + ", pos: " + lexer.pos()); } @@ -652,7 +651,7 @@ protected SQLExpr bracketRest(SQLExpr expr) { index = lexer.integerValue(); lexer.nextToken(); } else { - throw new SyntaxAnalysisException("Syntax error : " + lexer.stringVal()); + throw new ParserException("Syntax error : " + lexer.stringVal()); } if (expr instanceof SQLMethodInvokeExpr) { @@ -686,7 +685,7 @@ protected SQLExpr parseInterval() { SQLExpr value = expr(); if (lexer.token() != Token.IDENTIFIER) { - throw new SyntaxAnalysisException("Syntax error: " + lexer.token()); + throw new ParserException("Syntax error: " + lexer.token()); } String unit = lexer.stringVal(); @@ -729,7 +728,7 @@ public SQLColumnDefinition parseColumnRest(SQLColumnDefinition column) { } if (identifierEquals("PARTITION")) { - throw new SyntaxAnalysisException("syntax error " + lexer.token() + " " + lexer.stringVal()); + throw new ParserException("syntax error " + lexer.token() + " " + lexer.stringVal()); } if (identifierEquals("STORAGE")) { @@ -990,7 +989,7 @@ public MysqlForeignKey parseForeignKey() { } else if (lexer.token() == Token.UPDATE) { fk.setReferenceOn(MysqlForeignKey.On.UPDATE); } else { - throw new SyntaxAnalysisException("Syntax error, expect DELETE or UPDATE, actual " + lexer.token() + " " + throw new ParserException("Syntax error, expect DELETE or UPDATE, actual " + lexer.token() + " " + lexer.stringVal()); } lexer.nextToken(); @@ -1007,7 +1006,7 @@ public MysqlForeignKey parseForeignKey() { if (identifierEquals("ACTION")) { fk.setReferenceOption(MysqlForeignKey.Option.NO_ACTION); } else { - throw new SyntaxAnalysisException("Syntax error, expect ACTION, actual " + lexer.token() + " " + throw new ParserException("Syntax error, expect ACTION, actual " + lexer.token() + " " + lexer.stringVal()); } } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java index dd9fe1fb78..083125fcad 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/parser/NestedType.java @@ -54,7 +54,8 @@ public boolean tryFillFromExpr(SQLExpr expr) throws SqlParseException { List parameters = method.getParameters(); if (parameters.size() != 2 && parameters.size() != 1) { - throw new SemanticAnalysisException("on nested object only allowed 2 parameters (field,path)/(path,conditions..) " + throw new SemanticAnalysisException( + "on nested object only allowed 2 parameters (field,path)/(path,conditions..) " + "or 1 parameter (field) "); } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/Maker.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/Maker.java index a362610827..7dd095a8be 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/Maker.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/Maker.java @@ -456,7 +456,7 @@ private String[] arrayOfObjectsToStringArray(Object[] values, int from, int to) return strings; } - private ShapeBuilder getShapeBuilderFromString(String str) throws IOException { + private ShapeBuilder getShapeBuilderFromString(String str) throws IOException, SqlParseException { String json; if (str.contains("{")) { json = fixJsonFromElastic(str); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/QueryMaker.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/QueryMaker.java index f4de8f4e59..78aa90fe1e 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/QueryMaker.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/query/maker/QueryMaker.java @@ -80,7 +80,8 @@ private void addSubQuery(BoolQueryBuilder boolQuery, Where where, QueryBuilder s if (condition.isNested()) { // bugfix #628 if ("missing".equalsIgnoreCase(String.valueOf(condition.getValue())) - && (condition.getOPERATOR() == Condition.OPERATOR.IS || condition.getOPERATOR() == Condition.OPERATOR.EQ)) { + && (condition.getOPERATOR() == Condition.OPERATOR.IS + || condition.getOPERATOR() == Condition.OPERATOR.EQ)) { boolQuery.mustNot(QueryBuilders.nestedQuery(condition.getNestedPath(), QueryBuilders.boolQuery().mustNot(subQuery), ScoreMode.None)); return; diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java index 046daa2fd8..aa2babaf0f 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/spatial/WktToGeoJsonConverter.java @@ -15,8 +15,6 @@ package com.amazon.opendistroforelasticsearch.sql.spatial; - -import com.amazon.opendistroforelasticsearch.sql.antlr.syntax.SyntaxAnalysisException; import com.amazon.opendistroforelasticsearch.sql.utils.StringUtils; import com.google.common.base.Joiner; @@ -172,7 +170,7 @@ private static String removeBrackets(String wkt, int num) { int lastClosingBrackets = result.lastIndexOf(")"); int firstOpenBrackets = result.indexOf("("); if (lastClosingBrackets == -1 || firstOpenBrackets == -1) { - throw new SyntaxAnalysisException("Illegal syntax: " + wkt); + throw new IllegalArgumentException("Illegal syntax: " + wkt); } result = result.substring(firstOpenBrackets + 1, lastClosingBrackets); }