tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject tajo git commit: TAJO-2170: Disable unsetting timezone property.
Date Sun, 28 Aug 2016 07:40:13 GMT
Repository: tajo
Updated Branches:
  refs/heads/master d5ffbe645 -> 1858c968c


TAJO-2170: Disable unsetting timezone property.

Closes #1045

Signed-off-by: Jinho Kim <jhkim@apache.org>


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

Branch: refs/heads/master
Commit: 1858c968c6376ea312fcd6459a080e29a9f1641a
Parents: d5ffbe6
Author: Lee Dongjin <dongjin@apache.org>
Authored: Sun Aug 28 16:37:11 2016 +0900
Committer: Jinho Kim <jhkim@apache.org>
Committed: Sun Aug 28 16:37:11 2016 +0900

----------------------------------------------------------------------
 CHANGES                                         |  2 ++
 .../tajo/catalog/store/AbstractDBStore.java     | 15 +++++++--
 .../apache/tajo/catalog/store/CatalogStore.java |  3 +-
 .../org/apache/tajo/catalog/TestCatalog.java    |  4 +--
 .../apache/tajo/exception/ErrorMessages.java    |  1 +
 .../UnremovableTablePropertyException.java      | 33 ++++++++++++++++++++
 tajo-common/src/main/proto/errors.proto         |  1 +
 7 files changed, 54 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/1858c968/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index ec9320e..d7f7c20 100644
--- a/CHANGES
+++ b/CHANGES
@@ -21,6 +21,8 @@ Release 0.12.0 - unreleased
 
   IMPROVEMENT
 
+    TAJO-2170: Disable unsetting timezone property. (Lee Dongjin via jinho)
+
     TAJO-2175: Fix some glitches in source code. (Lee Dongjin via jihoon)
 
     TAJO-2146: Fragment interface cleanup. (jihoon)

http://git-wip-us.apache.org/repos/asf/tajo/blob/1858c968/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
index c37889a..023dfca 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
@@ -21,7 +21,9 @@
  */
 package org.apache.tajo.catalog.store;
 
+import com.google.common.collect.Sets;
 import com.google.protobuf.InvalidProtocolBufferException;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
@@ -62,6 +64,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements
Catalo
   protected final String connectionPassword;
   protected final String catalogUri;
 
+  protected final Set<String> unremovablePropertySet = Sets.newHashSet("timezone");
   protected final String insertPartitionSql = "INSERT INTO " + TB_PARTTIONS
     + "(" + COL_TABLES_PK + ", PARTITION_NAME, PATH, " + COL_PARTITION_BYTES
     + ") VALUES (?, ? , ?, ?)";
@@ -978,7 +981,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements
Catalo
   public void alterTable(CatalogProtos.AlterTableDescProto alterTableDescProto)
       throws UndefinedDatabaseException, DuplicateTableException, DuplicateColumnException,
       DuplicatePartitionException, UndefinedPartitionException, UndefinedColumnException,
UndefinedTableException,
-      UndefinedPartitionMethodException, AmbiguousTableException {
+      UndefinedPartitionMethodException, AmbiguousTableException, UnremovableTablePropertyException
{
 
     String[] splitted = IdentifierUtil.splitTableName(alterTableDescProto.getTableName());
     if (splitted.length == 1) {
@@ -1110,12 +1113,20 @@ public abstract class AbstractDBStore extends CatalogConstants implements
Catalo
     }
   }
 
-  private void unsetProperties(final int tableId, final PrimitiveProtos.StringListProto propertyKeys)
{
+  private void unsetProperties(final int tableId, final PrimitiveProtos.StringListProto propertyKeys)
+      throws UnremovableTablePropertyException {
     final String deleteSql = "DELETE FROM " + TB_OPTIONS + " WHERE TID=? AND KEY_=?";
 
     Connection conn;
     PreparedStatement pstmt = null;
 
+    Set<String> keys = Sets.newHashSet(propertyKeys.getValuesList());
+    Set<String> violations = Sets.intersection(keys, unremovablePropertySet);
+
+    if (!violations.isEmpty()) {
+      throw new UnremovableTablePropertyException(violations.toArray(new String[0]));
+    }
+
     Map<String, String> oldProperties = getTableOptions(tableId);
 
     try {

http://git-wip-us.apache.org/repos/asf/tajo/blob/1858c968/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/CatalogStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/CatalogStore.java
b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/CatalogStore.java
index 5288979..221fd6e 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/CatalogStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/CatalogStore.java
@@ -71,7 +71,8 @@ public interface CatalogStore extends Closeable {
 
   void alterTable(CatalogProtos.AlterTableDescProto alterTableDescProto) throws UndefinedDatabaseException,
       DuplicateTableException, DuplicateColumnException, DuplicatePartitionException, UndefinedPartitionException,
-      UndefinedTableException, UndefinedColumnException, UndefinedPartitionMethodException,
AmbiguousTableException;
+      UndefinedTableException, UndefinedColumnException, UndefinedPartitionMethodException,
AmbiguousTableException,
+      UnremovableTablePropertyException;
 
   List<TableDescriptorProto> getAllTables();
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/1858c968/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
b/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
index e385765..1b82e63 100644
--- a/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
+++ b/tajo-catalog/tajo-catalog-server/src/test/java/org/apache/tajo/catalog/TestCatalog.java
@@ -1003,9 +1003,9 @@ public class TestCatalog {
     assertEquals(newTimeZone, setPropertyDesc.getMeta().getProperty("timezone"));
 
     //UNSET_PROPERTY
-    catalog.alterTable(createMockAlterTableUnsetProperty(Sets.newHashSet("timezone", "dummy")));
+    catalog.alterTable(createMockAlterTableUnsetProperty(Sets.newHashSet("dummy")));
     setPropertyDesc = catalog.getTableDesc("default","mynewcooltable");
-    assertFalse(setPropertyDesc.getMeta().getPropertySet().containsKey("timezone"));
+    assertTrue(setPropertyDesc.getMeta().getPropertySet().containsKey("timezone"));
     assertFalse(setPropertyDesc.getMeta().getPropertySet().containsKey("dummy"));
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/1858c968/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java b/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java
index 8f45bdd..24aba52 100644
--- a/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/ErrorMessages.java
@@ -113,6 +113,7 @@ public class ErrorMessages {
     ADD_MESSAGE(INVALID_TABLE_PROPERTY, "invalid table property '%s': '%s'", 2);
     ADD_MESSAGE(MISSING_TABLE_PROPERTY, "table property '%s' required for '%s'", 2);
     ADD_MESSAGE(INVALID_TABLESPACE_URI, "Invalid tablespace '%s' for table '%s'", 2);
+    ADD_MESSAGE(UNREMOVABLE_TABLE_PROPERTY, "Removing following properties is disabled: %s",
1);
 
     ADD_MESSAGE(AMBIGUOUS_PARTITION_DIRECTORY, "There is a directory which is assumed to
be a partitioned directory" +
       " : '%s'", 1);

http://git-wip-us.apache.org/repos/asf/tajo/blob/1858c968/tajo-common/src/main/java/org/apache/tajo/exception/UnremovableTablePropertyException.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/exception/UnremovableTablePropertyException.java
b/tajo-common/src/main/java/org/apache/tajo/exception/UnremovableTablePropertyException.java
new file mode 100644
index 0000000..0a8a9dd
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/exception/UnremovableTablePropertyException.java
@@ -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.
+ */
+
+package org.apache.tajo.exception;
+
+import org.apache.tajo.error.Errors.ResultCode;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.ReturnState;
+
+public class UnremovableTablePropertyException extends TajoException {
+
+  public UnremovableTablePropertyException(ReturnState e) {
+    super(e);
+  }
+
+  public UnremovableTablePropertyException(String... keys) {
+    super(ResultCode.UNREMOVABLE_TABLE_PROPERTY, ErrorMessages.concat(keys));
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/1858c968/tajo-common/src/main/proto/errors.proto
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/proto/errors.proto b/tajo-common/src/main/proto/errors.proto
index cfb7242..2a7ec98 100644
--- a/tajo-common/src/main/proto/errors.proto
+++ b/tajo-common/src/main/proto/errors.proto
@@ -173,6 +173,7 @@ enum ResultCode {
   INVALID_TABLE_PROPERTY                = 1004; // SQLState: ? - Invalid Table Property
   MISSING_TABLE_PROPERTY                = 1005; // SQLState: ? - Missing table property
   INVALID_TABLESPACE_URI                = 1006;
+  UNREMOVABLE_TABLE_PROPERTY            = 1007;
 
   // Client Connection
   CLIENT_CONNECTION_EXCEPTION           = 1101; // SQLState: 08000 - Client connection error


Mime
View raw message