You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by dl...@apache.org on 2019/06/04 20:10:42 UTC

[asterixdb] branch master updated: [NO ISSUE][SQLPP] Improve error message for unsupported EXPLAIN

This is an automated email from the ASF dual-hosted git repository.

dlych pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new aebd031  [NO ISSUE][SQLPP] Improve error message for unsupported EXPLAIN
aebd031 is described below

commit aebd031b925a5a93729f0945d35c7f82c31d8d2e
Author: Dmitry Lychagin <dm...@couchbase.com>
AuthorDate: Tue Jun 4 08:55:39 2019 -0700

    [NO ISSUE][SQLPP] Improve error message for unsupported EXPLAIN
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    - Improve error message raised when EXPLAIN
      is not supported for a given statement
    
    Change-Id: Idd7844ca3d9e3c2c0de0b070e4a76282cb96e278
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3420
    Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Dmitry Lychagin <dm...@couchbase.com>
---
 .../explain_negative/explain_negative.1.ddl.sqlpp  | 33 ++++++++++++++++
 .../explain_negative.2.query.sqlpp                 | 24 ++++++++++++
 .../explain_negative.3.query.sqlpp                 | 26 +++++++++++++
 .../explain_negative.4.query.sqlpp                 | 26 +++++++++++++
 .../test/resources/runtimets/testsuite_sqlpp.xml   |  8 ++++
 .../asterix/lang/common/statement/Query.java       | 10 ++++-
 .../asterix-lang-sqlpp/src/main/javacc/SQLPP.jj    | 45 +++++++++++++---------
 7 files changed, 153 insertions(+), 19 deletions(-)

diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.1.ddl.sqlpp
new file mode 100644
index 0000000..741c9be
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.1.ddl.sqlpp
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description: EXPLAIN not supported for statement kind
+ */
+
+DROP DATAVERSE dvExplain IF EXISTS;
+CREATE DATAVERSE dvExplain;
+
+USE dvExplain;
+
+CREATE TYPE EmployeeType AS {
+  id : string,
+  x  : string
+};
+
+CREATE DATASET Employee(EmployeeType) PRIMARY KEY id;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.2.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.2.query.sqlpp
new file mode 100644
index 0000000..a309a92
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.2.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description  : EXPLAIN not supported for CREATE DATAVERSE
+ * Expected Res : Failure
+ */
+
+EXPLAIN CREATE DATAVERSE dvExplain2;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.3.query.sqlpp
new file mode 100644
index 0000000..11fe3d2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.3.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description  : EXPLAIN not supported for CREATE DATASET
+ * Expected Res : Failure
+ */
+
+USE dvExplain;
+
+EXPLAIN CREATE DATASET Employee2(EmployeeType) PRIMARY KEY id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.4.query.sqlpp
new file mode 100644
index 0000000..9f74ef8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.4.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description  : EXPLAIN not supported for CREATE INDEX
+ * Expected Res : Failure
+ */
+
+USE dvExplain;
+
+EXPLAIN CREATE INDEX idx1 on Employee(x) type btree;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index d1098dc..112277c 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -174,6 +174,14 @@
         <output-dir compare="Text">explain_field_access_closed</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="explain">
+      <compilation-unit name="explain_negative">
+        <output-dir compare="Text">explain_simple</output-dir>
+        <expected-error>ASX1001: Syntax error: EXPLAIN is not supported for this kind of statement</expected-error>
+        <expected-error>ASX1001: Syntax error: EXPLAIN is not supported for this kind of statement</expected-error>
+        <expected-error>ASX1001: Syntax error: EXPLAIN is not supported for this kind of statement</expected-error>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-case FilePath="flwor">
     <compilation-unit name="let33">
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/Query.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/Query.java
index 8b67556..7332c7d 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/Query.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/Query.java
@@ -30,11 +30,15 @@ import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
 
 public class Query extends AbstractStatement implements IReturningStatement {
-    private final boolean explain;
+    private boolean explain;
     private boolean topLevel = true;
     private Expression body;
     private int varCounter;
 
+    public Query() {
+        this(false);
+    }
+
     public Query(boolean explain) {
         this.explain = explain;
     }
@@ -80,6 +84,10 @@ public class Query extends AbstractStatement implements IReturningStatement {
         return topLevel;
     }
 
+    public void setExplain(boolean explain) {
+        this.explain = explain;
+    }
+
     public boolean isExplain() {
         return explain;
     }
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index 25ad2ab..6f63441 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -434,7 +434,7 @@ List<Statement> Statement() throws ParseException:
 }
 {
   (
-    (stmt = SingleStatement()
+    (stmt = ExplainStatement()
       {
         decls.add(stmt);
       }
@@ -447,6 +447,27 @@ List<Statement> Statement() throws ParseException:
   }
 }
 
+Statement ExplainStatement() throws ParseException:
+{
+  Statement stmt = null;
+  Token explainToken = null;
+}
+{
+   ( <EXPLAIN> { explainToken = token; } )?
+   stmt = SingleStatement()
+   {
+      if (explainToken != null) {
+        if (stmt.getKind() == Statement.Kind.QUERY) {
+          ((Query)stmt).setExplain(true);
+        } else {
+          throw new SqlppParseException(getSourceLocation(explainToken),
+            "EXPLAIN is not supported for this kind of statement");
+        }
+      }
+      return stmt;
+   }
+}
+
 Statement SingleStatement() throws ParseException:
 {
   Statement stmt = null;
@@ -466,8 +487,7 @@ Statement SingleStatement() throws ParseException:
     | stmt = UpsertStatement()
     | stmt = ConnectionStatement()
     | stmt = CompactStatement()
-    | stmt = ExplainStatement()
-    | stmt = Query(false)
+    | stmt = Query()
     | stmt = RefreshExternalDatasetStatement()
   )
   {
@@ -1090,7 +1110,7 @@ InsertStatement InsertStatement() throws ParseException:
 }
 {
   <INSERT> { startToken = token; } <INTO> nameComponents = QualifiedName() (<AS> var = Variable())?
-    query = Query(false)
+    query = Query()
     ( <RETURNING> returnExpression = Expression())?
     {
       if (var == null && returnExpression != null) {
@@ -1114,7 +1134,7 @@ UpsertStatement UpsertStatement() throws ParseException:
 }
 {
   <UPSERT> { startToken = token; } <INTO> nameComponents = QualifiedName() (<AS> var = Variable())?
-    query = Query(false)
+    query = Query()
     ( <RETURNING> returnExpression = Expression())?
     {
       if (var == null && returnExpression != null) {
@@ -1852,20 +1872,9 @@ FunctionDecl FunctionDeclaration() throws ParseException:
   }
 }
 
-Query ExplainStatement() throws ParseException:
-{
-  Query query;
-}
-{
-  <EXPLAIN> query = Query(true)
-  {
-    return query;
-  }
-}
-
-Query Query(boolean explain) throws ParseException:
+Query Query() throws ParseException:
 {
-  Query query = new Query(explain);
+  Query query = new Query();
   Expression expr;
 }
 {