You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by im...@apache.org on 2018/05/31 21:43:44 UTC

[19/43] asterixdb git commit: [ASTERIXDB-2387][MTD] Prevent Dataset Primary Index Drop

[ASTERIXDB-2387][MTD] Prevent Dataset Primary Index Drop

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Ensure a dataset primary index cannot be dropped
  without dropping the dataset.
- Add test case.

Change-Id: Ic2256925d088fa5b5ba3b9623a29b6219b5a9b1e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2645
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: Till Westmann <ti...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/f02b43bc
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/f02b43bc
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/f02b43bc

Branch: refs/heads/release-0.9.4-pre-rc
Commit: f02b43bcff1c859b933f55df9654899d025b1ed3
Parents: 5c68793
Author: Murtadha Hubail <mh...@apache.org>
Authored: Thu May 17 01:33:02 2018 +0300
Committer: Murtadha Hubail <mh...@apache.org>
Committed: Wed May 16 19:22:29 2018 -0700

----------------------------------------------------------------------
 .../asterix/app/translator/QueryTranslator.java |  8 ++++++
 .../drop-primary-index.1.ddl.sqlpp              | 26 ++++++++++++++++++++
 .../drop-primary-index.2.ddl.sqlpp              | 19 ++++++++++++++
 .../resources/runtimets/testsuite_sqlpp.xml     |  6 +++++
 .../asterix/common/exceptions/ErrorCode.java    |  1 +
 .../main/resources/asx_errormsg/en.properties   |  1 +
 6 files changed, 61 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/f02b43bc/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
index 453bcb5..e983763 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
@@ -1468,6 +1468,7 @@ public class QueryTranslator extends AbstractLangTranslator implements IStatemen
                         throw new AlgebricksException("There is no index with this name " + indexName + ".");
                     }
                 }
+                ensureNonPrimaryIndexDrop(index);
                 // #. prepare a job to drop the index in NC.
                 jobsToExecute.add(IndexUtil.buildDropIndexJobSpec(index, metadataProvider, ds));
 
@@ -1509,6 +1510,7 @@ public class QueryTranslator extends AbstractLangTranslator implements IStatemen
                 } else if (ExternalIndexingOperations.isFileIndex(index)) {
                     throw new AlgebricksException("Dropping a dataset's files index is not allowed.");
                 }
+                ensureNonPrimaryIndexDrop(index);
                 // #. prepare a job to drop the index in NC.
                 jobsToExecute.add(IndexUtil.buildDropIndexJobSpec(index, metadataProvider, ds));
                 List<Index> datasetIndexes =
@@ -2812,4 +2814,10 @@ public class QueryTranslator extends AbstractLangTranslator implements IStatemen
         IStatementRewriter rewriter = rewriterFactory.createStatementRewriter();
         rewriter.rewrite(stmt);
     }
+
+    private void ensureNonPrimaryIndexDrop(Index index) throws AlgebricksException {
+        if (index.isPrimaryIndex()) {
+            throw new MetadataException(ErrorCode.CANNOT_DROP_INDEX, index.getIndexName(), index.getDatasetName());
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/f02b43bc/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-primary-index/drop-primary-index.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-primary-index/drop-primary-index.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-primary-index/drop-primary-index.1.ddl.sqlpp
new file mode 100644
index 0000000..2dfd4aa
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-primary-index/drop-primary-index.1.ddl.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.
+ */
+drop  dataverse test if exists;
+create  dataverse test;
+
+use test;
+
+create type aType as {id:int};
+create dataset ds(aType) primary key id;
+drop index ds.ds;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/f02b43bc/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-primary-index/drop-primary-index.2.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-primary-index/drop-primary-index.2.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-primary-index/drop-primary-index.2.ddl.sqlpp
new file mode 100644
index 0000000..8268a20
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-primary-index/drop-primary-index.2.ddl.sqlpp
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+drop  dataverse test if exists;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/f02b43bc/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
----------------------------------------------------------------------
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 3823234..2ee294a 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -1654,6 +1654,12 @@
         <expected-error>Syntax error: In line 53 >>create  primary index if exists sec_primary_idx1  on LineItem;&lt;&lt; Encountered "exists" at column 26.</expected-error>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="ddl">
+      <compilation-unit name="drop-primary-index">
+        <output-dir compare="Text">drop-primary-index</output-dir>
+        <expected-error>Cannot drop index "ds". Drop dataset "ds" to remove this index</expected-error>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="dml">
     <test-case FilePath="dml">

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/f02b43bc/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
index b9a5b29..bd84832 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
@@ -149,6 +149,7 @@ public class ErrorCode {
     public static final int CANNOT_SERIALIZE_A_VALUE = 1066;
     public static final int CANNOT_FIND_NON_MISSING_SELECT_OPERATOR = 1067;
     public static final int CANNOT_GET_CONDITIONAL_SPLIT_KEY_VARIABLE = 1068;
+    public static final int CANNOT_DROP_INDEX = 1069;
 
     // Feed errors
     public static final int DATAFLOW_ILLEGAL_STATE = 3001;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/f02b43bc/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
index 175f144..a0cebea 100644
--- a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
+++ b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
@@ -136,6 +136,7 @@
 1066 = Cannot serialize a value.
 1067 = Cannot find a non-missing SELECT operator in GROUP operator for a left-outer-join plan optimization.
 1068 = Cannot get the conditional split variable for the given UNNESTMAP operator.
+1069 = Cannot drop index \"%1$s\". Drop dataset \"%1$s\" to remove this index
 
 # Feed Errors
 3001 = Illegal state.