Dmitry Lychagin has submitted this change and it was merged. ( https://asterix-gerrit.ics.uci.edu/3420 )
Change subject: [NO ISSUE][SQLPP] Improve error message for unsupported EXPLAIN ...................................................................... [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 <[email protected]> Tested-by: Jenkins <[email protected]> Integration-Tests: Jenkins <[email protected]> Reviewed-by: Dmitry Lychagin <[email protected]> --- A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.1.ddl.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.2.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.3.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/explain/explain_negative/explain_negative.4.query.sqlpp M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml M asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/statement/Query.java M asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj 7 files changed, 153 insertions(+), 19 deletions(-) Approvals: Jenkins: Verified; No violations found; Verified Anon. E. Moose (1000171): Dmitry Lychagin: Looks good to me, approved 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,10 +30,14 @@ 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 @@ 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 @@ } { ( - (stmt = SingleStatement() + (stmt = ExplainStatement() { decls.add(stmt); } @@ -445,6 +445,27 @@ { return decls; } +} + +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: @@ -466,8 +487,7 @@ | stmt = UpsertStatement() | stmt = ConnectionStatement() | stmt = CompactStatement() - | stmt = ExplainStatement() - | stmt = Query(false) + | stmt = Query() | stmt = RefreshExternalDatasetStatement() ) { @@ -1090,7 +1110,7 @@ } { <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 @@ } { <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 @@ } } -Query ExplainStatement() throws ParseException: +Query Query() throws ParseException: { - Query query; -} -{ - <EXPLAIN> query = Query(true) - { - return query; - } -} - -Query Query(boolean explain) throws ParseException: -{ - Query query = new Query(explain); + Query query = new Query(); Expression expr; } { -- To view, visit https://asterix-gerrit.ics.uci.edu/3420 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-MessageType: merged Gerrit-Change-Id: Idd7844ca3d9e3c2c0de0b070e4a76282cb96e278 Gerrit-Change-Number: 3420 Gerrit-PatchSet: 4 Gerrit-Owner: Dmitry Lychagin <[email protected]> Gerrit-Reviewer: Ali Alsuliman <[email protected]> Gerrit-Reviewer: Anon. E. Moose (1000171) Gerrit-Reviewer: Dmitry Lychagin <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Till Westmann <[email protected]>
