TAJO-2170: Disable unsetting timezone property.
Closes #1045
Signed-off-by: Jinho Kim <jhkim@apache.org>
diff --git a/CHANGES b/CHANGES
index ec9320e..d7f7c20 100644
--- a/CHANGES
+++ b/CHANGES
@@ -21,6 +21,8 @@
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)
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 @@
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 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 @@
}
}
- 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 {
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 @@
void alterTable(CatalogProtos.AlterTableDescProto alterTableDescProto) throws UndefinedDatabaseException,
DuplicateTableException, DuplicateColumnException, DuplicatePartitionException, UndefinedPartitionException,
- UndefinedTableException, UndefinedColumnException, UndefinedPartitionMethodException, AmbiguousTableException;
+ UndefinedTableException, UndefinedColumnException, UndefinedPartitionMethodException, AmbiguousTableException,
+ UnremovableTablePropertyException;
List<TableDescriptorProto> getAllTables();
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 @@
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"));
}
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 @@
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);
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));
+ }
+}
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 @@
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