tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject git commit: TAJO-755: ALTER TABLESPACE LOCATION support. (hyunsik)
Date Mon, 14 Apr 2014 02:58:54 GMT
Repository: tajo
Updated Branches:
  refs/heads/branch-0.8.0 a755f5108 -> 0a9f55b24


TAJO-755: ALTER TABLESPACE LOCATION support. (hyunsik)


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

Branch: refs/heads/branch-0.8.0
Commit: 0a9f55b2457b474de46e323d99ec699021421588
Parents: a755f51
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Mon Apr 14 10:19:05 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Mon Apr 14 11:51:04 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |   2 +
 .../apache/tajo/algebra/AlterTablespace.java    |  66 ++++++++++++
 .../tajo/algebra/AlterTablespaceSetType.java    |  22 ++++
 .../java/org/apache/tajo/algebra/OpType.java    |   1 +
 .../tajo/catalog/AbstractCatalogClient.java     |  30 ++++++
 .../org/apache/tajo/catalog/CatalogService.java |  17 +++
 .../src/main/proto/CatalogProtocol.proto        |   2 +
 .../src/main/proto/CatalogProtos.proto          |  23 +++++
 .../tajo/catalog/store/HCatalogStore.java       |  42 ++++++--
 .../org/apache/tajo/catalog/CatalogServer.java  |  55 ++++++++++
 .../tajo/catalog/store/AbstractDBStore.java     |  60 +++++++++++
 .../apache/tajo/catalog/store/CatalogStore.java |   6 ++
 .../org/apache/tajo/catalog/store/MemStore.java |  31 ++++++
 .../org/apache/tajo/catalog/TestCatalog.java    |  75 ++++++++++++++
 .../org/apache/tajo/engine/parser/SQLParser.g4  |   5 +
 .../apache/tajo/engine/parser/SQLAnalyzer.java  |  10 +-
 .../tajo/engine/planner/AlgebraVisitor.java     |   3 +-
 .../engine/planner/AlterTablespaceNode.java     | 103 +++++++++++++++++++
 .../tajo/engine/planner/BaseAlgebraVisitor.java |  12 ++-
 .../engine/planner/BasicLogicalPlanVisitor.java |  10 ++
 .../engine/planner/LogicalPlanPreprocessor.java |   7 ++
 .../tajo/engine/planner/LogicalPlanVisitor.java |   5 +-
 .../tajo/engine/planner/LogicalPlanner.java     |  11 +-
 .../apache/tajo/engine/planner/PlannerUtil.java |   4 +-
 .../tajo/engine/planner/logical/NodeType.java   |   3 +
 .../org/apache/tajo/master/GlobalEngine.java    |  39 ++++++-
 .../tajo/engine/query/TestAlterTable.java       |   1 -
 .../tajo/engine/query/TestAlterTablespace.java  |  63 ++++++++++++
 28 files changed, 688 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 670721d..4dbcf0d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -143,6 +143,8 @@ Release 0.8.0 - unreleased
 
   IMPROVEMENTS
 
+    TAJO-755: ALTER TABLESPACE LOCATION support. (hyunsilk)
+    
     TAJO-732: Support executing LINUX shell command and HDFS command.
     (hyoungjun kim via hyunsik)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTablespace.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTablespace.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTablespace.java
new file mode 100644
index 0000000..ceec08b
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTablespace.java
@@ -0,0 +1,66 @@
+/**
+ * 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.algebra;
+
+
+import com.google.common.base.Objects;
+import org.apache.tajo.util.TUtil;
+
+public class AlterTablespace extends Expr {
+
+  private String tablespaceName;
+  private AlterTablespaceSetType setType;
+
+  private String uri;
+
+  public AlterTablespace(final String tablespaceName) {
+    super(OpType.AlterTablespace);
+    this.tablespaceName = tablespaceName;
+  }
+
+  public String getTablespaceName() {
+    return tablespaceName;
+  }
+
+  public AlterTablespaceSetType getSetType() {
+    return setType;
+  }
+
+  public String getLocation() {
+    return uri;
+  }
+
+  public void setLocation(String uri) {
+    this.setType = AlterTablespaceSetType.LOCATION;
+    this.uri = uri;
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hashCode(tablespaceName, setType);
+  }
+
+  @Override
+  boolean equalsTo(Expr expr) {
+    AlterTablespace another = (AlterTablespace) expr;
+    return tablespaceName.equals(another.tablespaceName) &&
+        TUtil.checkEquals(setType, another.setType) &&
+        TUtil.checkEquals(uri, another.uri);
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTablespaceSetType.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTablespaceSetType.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTablespaceSetType.java
new file mode 100644
index 0000000..aa5ad04
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTablespaceSetType.java
@@ -0,0 +1,22 @@
+/**
+ * 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.algebra;
+
+public enum AlterTablespaceSetType {
+  LOCATION
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java
index 0cb0527..a62ccfd 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java
@@ -47,6 +47,7 @@ public enum OpType {
   DropDatabase(DropDatabase.class),
   CreateTable(CreateTable.class),
   DropTable(DropTable.class),
+  AlterTablespace(AlterTablespace.class),
   AlterTable(AlterTable.class),
 
   // Insert or Update

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
index 60cce9a..542214b 100644
--- a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
+++ b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/AbstractCatalogClient.java
@@ -124,6 +124,36 @@ public abstract class AbstractCatalogClient implements CatalogService {
   }
 
   @Override
+  public TablespaceProto getTablespace(final String tablespaceName) {
+    try {
+      return new ServerCallable<TablespaceProto>(pool, catalogServerAddr, CatalogProtocol.class, false) {
+        public TablespaceProto call(NettyClientBase client) throws ServiceException {
+          CatalogProtocolService.BlockingInterface stub = getStub(client);
+          return stub.getTablespace(null, ProtoUtil.convertString(tablespaceName));
+        }
+      }.withRetries();
+    } catch (ServiceException e) {
+      LOG.error(e.getMessage(), e);
+      return null;
+    }
+  }
+
+  @Override
+  public Boolean alterTablespace(final AlterTablespaceProto alterTablespace) {
+    try {
+      return new ServerCallable<Boolean>(pool, catalogServerAddr, CatalogProtocol.class, false) {
+        public Boolean call(NettyClientBase client) throws ServiceException {
+          CatalogProtocolService.BlockingInterface stub = getStub(client);
+          return stub.alterTablespace(null, alterTablespace).getValue();
+        }
+      }.withRetries();
+    } catch (ServiceException e) {
+      LOG.error(e.getMessage(), e);
+      return false;
+    }
+  }
+
+  @Override
   public final Boolean createDatabase(final String databaseName, @Nullable final String tablespaceName) {
     try {
       return new ServerCallable<Boolean>(pool, catalogServerAddr, CatalogProtocol.class, false) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/CatalogService.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/CatalogService.java b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/CatalogService.java
index f68f11a..667ee88 100644
--- a/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/CatalogService.java
+++ b/tajo-catalog/tajo-catalog-client/src/main/java/org/apache/tajo/catalog/CatalogService.java
@@ -19,11 +19,14 @@
 package org.apache.tajo.catalog;
 
 import org.apache.tajo.catalog.partition.PartitionMethodDesc;
+import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.common.TajoDataTypes.DataType;
 
 import java.util.Collection;
 
+import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto;
 import static org.apache.tajo.catalog.proto.CatalogProtos.FunctionType;
+import static org.apache.tajo.catalog.proto.CatalogProtos.TablespaceProto;
 
 public interface CatalogService {
 
@@ -56,6 +59,20 @@ public interface CatalogService {
 
   /**
    *
+   * @param tablespaceName Tablespace name to get
+   * @return Tablespace description
+   */
+  TablespaceProto getTablespace(String tablespaceName);
+
+  /**
+   *
+   * @param alterTablespace AlterTablespace
+   * @return True if update is successfully.
+   */
+  Boolean alterTablespace(AlterTablespaceProto alterTablespace);
+
+  /**
+   *
    * @param databaseName Database name to be created
    * @return True if database is created successfully. Otherwise, it will return FALSE.
    */

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto b/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto
index 0f34f7c..c5cb528 100644
--- a/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto
+++ b/tajo-catalog/tajo-catalog-client/src/main/proto/CatalogProtocol.proto
@@ -30,6 +30,8 @@ service CatalogProtocolService {
   rpc dropTablespace(StringProto) returns (BoolProto);
   rpc existTablespace(StringProto) returns (BoolProto);
   rpc getAllTablespaceNames(NullProto) returns (StringListProto);
+  rpc getTablespace(StringProto) returns (TablespaceProto);
+  rpc alterTablespace(AlterTablespaceProto) returns (BoolProto);
   rpc alterTable(AlterTableDescProto) returns (BoolProto);
 
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto b/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto
index b985ba7..7ec68c5 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto
+++ b/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto
@@ -270,6 +270,29 @@ message PartitionDescProto {
   optional string path = 5;
 }
 
+message TablespaceProto {
+  required string spaceName = 1;
+  required string uri = 2;
+}
+
+message AlterTablespaceProto {
+  required string spaceName = 1;
+  repeated AlterTablespaceCommand command = 2;
+
+  enum AlterTablespaceType {
+    LOCATION = 0;
+  }
+
+  message SetLocation {
+    required string uri = 1;
+  }
+
+  message AlterTablespaceCommand {
+    required AlterTablespaceType type = 1;
+    optional SetLocation location = 2;
+  }
+}
+
 message AlterTableDescProto {
   required string tableName = 1;
   optional string newTableName = 2 ;

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/src/main/java/org/apache/tajo/catalog/store/HCatalogStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/src/main/java/org/apache/tajo/catalog/store/HCatalogStore.java b/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/src/main/java/org/apache/tajo/catalog/store/HCatalogStore.java
index 755fca6..0fe255c 100644
--- a/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/src/main/java/org/apache/tajo/catalog/store/HCatalogStore.java
+++ b/tajo-catalog/tajo-catalog-drivers/tajo-hcatalog/src/main/java/org/apache/tajo/catalog/store/HCatalogStore.java
@@ -51,6 +51,7 @@ import java.io.IOException;
 import java.util.*;
 
 import static org.apache.tajo.catalog.proto.CatalogProtos.PartitionType;
+import static org.apache.tajo.catalog.proto.CatalogProtos.TablespaceProto;
 
 public class HCatalogStore extends CatalogConstants implements CatalogStore {
   protected final Log LOG = LogFactory.getLog(getClass());
@@ -91,7 +92,9 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
         throw new CatalogException(e);
       }
     } finally {
-      client.release();
+      if (client != null) {
+        client.release();
+      }
     }
 
     return exist;
@@ -311,6 +314,23 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
   }
 
   @Override
+  public TablespaceProto getTablespace(String spaceName) throws CatalogException {
+    if (spaceName.equals(TajoConstants.DEFAULT_TABLESPACE_NAME)) {
+      TablespaceProto.Builder builder = TablespaceProto.newBuilder();
+      builder.setSpaceName(TajoConstants.DEFAULT_TABLESPACE_NAME);
+      builder.setUri(defaultTableSpaceUri);
+      return builder.build();
+    } else {
+      throw new CatalogException("tablespace concept is not supported in HCatalogStore");
+    }
+  }
+
+  @Override
+  public void alterTablespace(CatalogProtos.AlterTablespaceProto alterProto) throws CatalogException {
+    throw new CatalogException("tablespace concept is not supported in HCatalogStore");
+  }
+
+  @Override
   public void createDatabase(String databaseName, String tablespaceName) throws CatalogException {
     HCatalogStoreClientPool.HCatalogStoreClient client = null;
 
@@ -535,7 +555,9 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
     } catch (Exception e) {
       throw new CatalogException(e);
     } finally {
-      client.release();
+      if (client != null) {
+        client.release();
+      }
     }
   }
 
@@ -590,7 +612,9 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
     } catch (Exception e) {
       throw new CatalogException(e);
     } finally {
-      client.release();
+      if (client != null) {
+        client.release();
+      }
     }
   }
 
@@ -613,7 +637,9 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
     } catch (Exception e) {
       throw new CatalogException(e);
     } finally {
-      client.release();
+      if (client != null) {
+        client.release();
+      }
     }
   }
 
@@ -634,7 +660,9 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
     } catch (Exception e) {
       throw new CatalogException(e);
     } finally {
-      client.release();
+      if (client != null) {
+        client.release();
+      }
     }
   }
 
@@ -778,7 +806,9 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
     } catch (Exception e) {
       throw new CatalogException(e);
     } finally {
-      client.release();
+      if (client != null) {
+        client.release();
+      }
     }
 
     return exist;

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
index 4ae91b4..b4bc12e 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/CatalogServer.java
@@ -19,15 +19,18 @@
 package org.apache.tajo.catalog;
 
 import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
 import com.google.protobuf.RpcController;
 import com.google.protobuf.ServiceException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.service.AbstractService;
+import org.apache.tajo.TajoConstants;
 import org.apache.tajo.annotation.ThreadSafe;
 import org.apache.tajo.catalog.CatalogProtocol.CatalogProtocolService;
 import org.apache.tajo.catalog.exception.*;
+import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.catalog.proto.CatalogProtos.*;
 import org.apache.tajo.catalog.store.CatalogStore;
 import org.apache.tajo.catalog.store.DerbyStore;
@@ -36,6 +39,7 @@ import org.apache.tajo.common.TajoDataTypes.DataType;
 import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.conf.TajoConf.ConfVars;
 import org.apache.tajo.rpc.BlockingRpcServer;
+import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos;
 import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.BoolProto;
 import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.NullProto;
 import org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.StringProto;
@@ -46,11 +50,13 @@ import org.apache.tajo.util.TUtil;
 import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.net.InetSocketAddress;
+import java.net.URI;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
+import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto.AlterTablespaceCommand;
 import static org.apache.tajo.catalog.proto.CatalogProtos.FunctionType.*;
 import static org.apache.tajo.common.TajoDataTypes.Type;
 import static org.apache.tajo.rpc.protocolrecords.PrimitiveProtos.StringListProto;
@@ -238,6 +244,10 @@ public class CatalogServer extends AbstractService {
 
       wlock.lock();
       try {
+        if (tablespaceName.equals(TajoConstants.DEFAULT_TABLESPACE_NAME)) {
+          throw new CatalogException("default tablespace cannot be dropped.");
+        }
+
         if (!store.existTablespace(tablespaceName)) {
           throw new NoSuchTablespaceException(tablespaceName);
         }
@@ -286,6 +296,51 @@ public class CatalogServer extends AbstractService {
     }
 
     @Override
+    public TablespaceProto getTablespace(RpcController controller, StringProto request) throws ServiceException {
+      rlock.lock();
+      try {
+        return store.getTablespace(request.getValue());
+      } catch (Exception e) {
+        LOG.error(e);
+        throw new ServiceException(e);
+      } finally {
+        rlock.unlock();
+      }
+    }
+
+    @Override
+    public BoolProto alterTablespace(RpcController controller, AlterTablespaceProto request) throws ServiceException {
+      wlock.lock();
+      try {
+        if (!store.existTablespace(request.getSpaceName())) {
+          throw new NoSuchTablespaceException(request.getSpaceName());
+        }
+
+        if (request.getCommandList().size() > 0) {
+          for (AlterTablespaceCommand command : request.getCommandList()) {
+            if (command.getType() == AlterTablespaceProto.AlterTablespaceType.LOCATION) {
+              try {
+                URI uri = URI.create(command.getLocation().getUri());
+                Preconditions.checkArgument(uri.getScheme() != null);
+              } catch (Exception e) {
+                throw new ServiceException("ALTER TABLESPACE's LOCATION must be a URI form (scheme:///.../), but "
+                    + command.getLocation().getUri());
+              }
+            }
+          }
+        }
+
+        store.alterTablespace(request);
+        return ProtoUtil.TRUE;
+      } catch (Exception e) {
+        LOG.error(e);
+        throw new ServiceException(e);
+      } finally {
+        wlock.unlock();
+      }
+    }
+
+    @Override
     public BoolProto createDatabase(RpcController controller, CreateDatabaseRequest request) throws ServiceException {
       String databaseName = request.getDatabaseName();
       String tablespaceName = request.getTablespaceName();

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/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 b1efc7f..5b26e14 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
@@ -45,6 +45,8 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.*;
 
+import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto.AlterTablespaceCommand;
+
 public abstract class AbstractDBStore extends CatalogConstants implements CatalogStore {
   protected final Log LOG = LogFactory.getLog(getClass());
   protected final Configuration conf;
@@ -353,6 +355,64 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
   }
 
   @Override
+  public TablespaceProto getTablespace(String spaceName) throws CatalogException {
+    Connection conn = null;
+    PreparedStatement pstmt = null;
+    ResultSet resultSet = null;
+
+    try {
+      String sql = "SELECT SPACE_NAME, SPACE_URI FROM " + TB_SPACES + " WHERE SPACE_NAME=?";
+      conn = getConnection();
+      pstmt = conn.prepareStatement(sql);
+      pstmt.setString(1, spaceName);
+      resultSet = pstmt.executeQuery();
+
+      if (!resultSet.next()) {
+        throw new NoSuchTablespaceException(spaceName);
+      }
+
+      String retrieveSpaceName = resultSet.getString("SPACE_NAME");
+      String uri = resultSet.getString("SPACE_URI");
+
+      TablespaceProto.Builder builder = TablespaceProto.newBuilder();
+      builder.setSpaceName(retrieveSpaceName);
+      builder.setUri(uri);
+      return builder.build();
+
+    } catch (SQLException se) {
+      throw new CatalogException(se);
+    } finally {
+      CatalogUtil.closeQuietly(pstmt, resultSet);
+    }
+  }
+
+  @Override
+  public void alterTablespace(AlterTablespaceProto alterProto) throws CatalogException {
+    Connection conn;
+    PreparedStatement pstmt = null;
+
+    if (alterProto.getCommandList().size() == 1) {
+      AlterTablespaceCommand command = alterProto.getCommand(0);
+      if (command.getType() == AlterTablespaceProto.AlterTablespaceType.LOCATION) {
+        AlterTablespaceProto.SetLocation setLocation = command.getLocation();
+        try {
+          String sql = "UPDATE " + TB_SPACES + " SET SPACE_URI=? WHERE SPACE_NAME=?";
+
+          conn = getConnection();
+          pstmt = conn.prepareStatement(sql);
+          pstmt.setString(1, setLocation.getUri());
+          pstmt.setString(2, alterProto.getSpaceName());
+          pstmt.executeUpdate();
+        } catch (SQLException se) {
+          throw new CatalogException(se);
+        } finally {
+          CatalogUtil.closeQuietly(pstmt);
+        }
+      }
+    }
+  }
+
+  @Override
   public void createDatabase(String databaseName, String tablespaceName) throws CatalogException {
     Connection conn = null;
     PreparedStatement pstmt = null;

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/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 e0c5a9d..5de9633 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
@@ -28,7 +28,9 @@ import org.apache.tajo.catalog.exception.CatalogException;
 import java.util.Collection;
 import java.util.List;
 
+import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto;
 import static org.apache.tajo.catalog.proto.CatalogProtos.PartitionMethodProto;
+import static org.apache.tajo.catalog.proto.CatalogProtos.TablespaceProto;
 
 public interface CatalogStore extends Closeable {
   /*************************** Tablespace ******************************/
@@ -40,6 +42,10 @@ public interface CatalogStore extends Closeable {
 
   Collection<String> getAllTablespaceNames() throws CatalogException;
 
+  TablespaceProto getTablespace(String spaceName) throws CatalogException;
+
+  void alterTablespace(AlterTablespaceProto alterProto) throws CatalogException;
+
   /*************************** Database ******************************/
   void createDatabase(String databaseName, String tablespaceName) throws CatalogException;
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
index ca29a6b..8940093 100644
--- a/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
+++ b/tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/MemStore.java
@@ -34,6 +34,9 @@ import org.apache.tajo.catalog.proto.CatalogProtos.IndexDescProto;
 import java.io.IOException;
 import java.util.*;
 
+import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto.AlterTablespaceType;
+import static org.apache.tajo.catalog.proto.CatalogProtos.TablespaceProto;
+
 /**
  * CatalogServer guarantees that all operations are thread-safe.
  * So, we don't need to consider concurrency problem here.
@@ -83,6 +86,34 @@ public class MemStore implements CatalogStore {
   }
 
   @Override
+  public TablespaceProto getTablespace(String spaceName) throws CatalogException {
+    if (!tablespaces.containsKey(spaceName)) {
+      throw new NoSuchTablespaceException(spaceName);
+    }
+
+    TablespaceProto.Builder builder = TablespaceProto.newBuilder();
+    builder.setSpaceName(spaceName);
+    builder.setUri(tablespaces.get(spaceName));
+    return builder.build();
+  }
+
+  @Override
+  public void alterTablespace(CatalogProtos.AlterTablespaceProto alterProto) throws CatalogException {
+    if (!tablespaces.containsKey(alterProto.getSpaceName())) {
+      throw new NoSuchTablespaceException(alterProto.getSpaceName());
+    }
+
+    if (alterProto.getCommandList().size() > 0) {
+      for (CatalogProtos.AlterTablespaceProto.AlterTablespaceCommand cmd : alterProto.getCommandList()) {
+        if(cmd.getType() == AlterTablespaceType.LOCATION) {
+          CatalogProtos.AlterTablespaceProto.SetLocation setLocation = cmd.getLocation();
+          tablespaces.put(alterProto.getSpaceName(), setLocation.getUri());
+        }
+      }
+    }
+  }
+
+  @Override
   public void createDatabase(String databaseName, String tablespaceName) throws CatalogException {
     if (databases.containsKey(databaseName)) {
       throw new AlreadyExistsDatabaseException(databaseName);

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/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 1eefe29..e60cc09 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
@@ -45,6 +45,10 @@ import java.util.*;
 
 import static org.apache.tajo.TajoConstants.DEFAULT_DATABASE_NAME;
 import static org.apache.tajo.catalog.CatalogConstants.CATALOG_URI;
+import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto;
+import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto.AlterTablespaceCommand;
+import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto.AlterTablespaceType;
+import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto.SetLocation;
 import static org.junit.Assert.*;
 import static org.junit.Assert.assertEquals;
 
@@ -116,6 +120,77 @@ public class TestCatalog {
 	}
 
   @Test
+  public void testGetTablespace() throws Exception {
+    //////////////////////////////////////////////////////////////////////////////
+    // Create two table spaces
+    //////////////////////////////////////////////////////////////////////////////
+
+    assertFalse(catalog.existTablespace("space1"));
+    assertTrue(catalog.createTablespace("space1", "hdfs://xxx.com/warehouse"));
+    assertTrue(catalog.existTablespace("space1"));
+
+    assertFalse(catalog.existTablespace("space2"));
+    assertTrue(catalog.createTablespace("space2", "hdfs://yyy.com/warehouse"));
+    assertTrue(catalog.existTablespace("space2"));
+
+    //////////////////////////////////////////////////////////////////////////////
+    // ALTER TABLESPACE space1
+    //////////////////////////////////////////////////////////////////////////////
+
+    // pre verification
+    CatalogProtos.TablespaceProto space1 = catalog.getTablespace("space1");
+    assertEquals("space1", space1.getSpaceName());
+    assertEquals("hdfs://xxx.com/warehouse", space1.getUri());
+
+    // ALTER TABLESPACE space1 LOCATION 'hdfs://zzz.com/warehouse';
+    AlterTablespaceProto.AlterTablespaceCommand.Builder commandBuilder =
+        AlterTablespaceProto.AlterTablespaceCommand.newBuilder();
+    commandBuilder.setType(AlterTablespaceType.LOCATION);
+    commandBuilder.setLocation(SetLocation.newBuilder().setUri("hdfs://zzz.com/warehouse"));
+    AlterTablespaceProto.Builder alter = AlterTablespaceProto.newBuilder();
+    alter.setSpaceName("space1");
+    alter.addCommand(commandBuilder.build());
+    catalog.alterTablespace(alter.build());
+
+    // Verify ALTER TABLESPACE space1
+    space1 = catalog.getTablespace("space1");
+    assertEquals("space1", space1.getSpaceName());
+    assertEquals("hdfs://zzz.com/warehouse", space1.getUri());
+
+    //////////////////////////////////////////////////////////////////////////////
+    // ALTER TABLESPACE space1
+    //////////////////////////////////////////////////////////////////////////////
+
+    // pre verification
+    CatalogProtos.TablespaceProto space2 = catalog.getTablespace("space2");
+    assertEquals("space2", space2.getSpaceName());
+    assertEquals("hdfs://yyy.com/warehouse", space2.getUri());
+
+    // ALTER TABLESPACE space1 LOCATION 'hdfs://zzz.com/warehouse';
+    commandBuilder = AlterTablespaceProto.AlterTablespaceCommand.newBuilder();
+    commandBuilder.setType(AlterTablespaceType.LOCATION);
+    commandBuilder.setLocation(SetLocation.newBuilder().setUri("hdfs://www.com/warehouse"));
+    alter = AlterTablespaceProto.newBuilder();
+    alter.setSpaceName("space2");
+    alter.addCommand(commandBuilder.build());
+    catalog.alterTablespace(alter.build());
+
+    // post verification
+    space1 = catalog.getTablespace("space2");
+    assertEquals("space2", space1.getSpaceName());
+    assertEquals("hdfs://www.com/warehouse", space1.getUri());
+
+
+    //////////////////////////////////////////////////////////////////////////////
+    // Clean up
+    //////////////////////////////////////////////////////////////////////////////
+    assertTrue(catalog.dropTablespace("space1"));
+    assertFalse(catalog.existTablespace("space1"));
+    assertTrue(catalog.dropTablespace("space2"));
+    assertFalse(catalog.existTablespace("space2"));
+  }
+
+  @Test
   public void testCreateAndDropDatabases() throws Exception {
     assertFalse(catalog.existDatabase("testCreateAndDropDatabases"));
     assertTrue(catalog.createDatabase("testCreateAndDropDatabases", TajoConstants.DEFAULT_TABLESPACE_NAME));

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4 b/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
index 1249d57..f6385eb 100644
--- a/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
+++ b/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLParser.g4
@@ -62,6 +62,7 @@ schema_statement
   | drop_database_statement
   | create_table_statement
   | drop_table_statement
+  | alter_tablespace_statement
   | alter_table_statement
   ;
 
@@ -1386,6 +1387,10 @@ insert_statement
 ===============================================================================
 */
 
+alter_tablespace_statement
+  : ALTER TABLESPACE space_name=identifier LOCATION uri=Character_String_Literal
+  ;
+
 alter_table_statement
   : ALTER TABLE table_name RENAME TO table_name
   | ALTER TABLE table_name RENAME COLUMN column_name TO column_name

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
index e95d5af..f28f7ca 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
@@ -32,6 +32,7 @@ import org.apache.tajo.catalog.CatalogConstants;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.engine.parser.SQLParser.*;
 
+import java.nio.charset.Charset;
 import java.util.*;
 
 import static org.apache.tajo.algebra.Aggregation.GroupElement;
@@ -1335,7 +1336,7 @@ public class SQLAnalyzer extends SQLParserBaseVisitor<Expr> {
   public static String escapeDelimiter(String value) {
     try {
       String delimiter = StringEscapeUtils.unescapeJava(value);
-      delimiter = new String(new byte[]{Byte.valueOf(delimiter).byteValue()});
+      delimiter = new String(new byte[]{Byte.valueOf(delimiter).byteValue()}, Charset.defaultCharset());
       return StringEscapeUtils.escapeJava(delimiter);
     } catch (NumberFormatException e) {
     }
@@ -1435,6 +1436,13 @@ public class SQLAnalyzer extends SQLParserBaseVisitor<Expr> {
   }
 
   @Override
+  public Expr visitAlter_tablespace_statement(@NotNull SQLParser.Alter_tablespace_statementContext ctx) {
+    AlterTablespace alter = new AlterTablespace(ctx.space_name.getText());
+    alter.setLocation(stripQuote(ctx.uri.getText()));
+    return alter;
+  }
+
+  @Override
   public Expr visitAlter_table_statement(SQLParser.Alter_table_statementContext ctx) {
 
     final List<Table_nameContext> tables = ctx.table_name();

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlgebraVisitor.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlgebraVisitor.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlgebraVisitor.java
index 6aa4830..aa94801 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlgebraVisitor.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlgebraVisitor.java
@@ -46,6 +46,7 @@ public interface AlgebraVisitor<CONTEXT, RESULT> {
   RESULT visitDropDatabase(CONTEXT ctx, Stack<Expr> stack, DropDatabase expr) throws PlanningException;
   RESULT visitCreateTable(CONTEXT ctx, Stack<Expr> stack, CreateTable expr) throws PlanningException;
   RESULT visitDropTable(CONTEXT ctx, Stack<Expr> stack, DropTable expr) throws PlanningException;
+  RESULT visitAlterTablespace(CONTEXT ctx, Stack<Expr> stack, AlterTablespace expr) throws PlanningException;
   RESULT visitAlterTable(CONTEXT ctx, Stack<Expr> stack, AlterTable expr) throws PlanningException;
 
     // Insert or Update
@@ -106,6 +107,4 @@ public interface AlgebraVisitor<CONTEXT, RESULT> {
   RESULT visitTimestampLiteral(CONTEXT ctx, Stack<Expr> stack, TimestampLiteral expr) throws PlanningException;
   RESULT visitTimeLiteral(CONTEXT ctx, Stack<Expr> stack, TimeLiteral expr) throws PlanningException;
   RESULT visitDateLiteral(CONTEXT ctx, Stack<Expr> stack, DateLiteral expr) throws PlanningException;
-
-
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlterTablespaceNode.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlterTablespaceNode.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlterTablespaceNode.java
new file mode 100644
index 0000000..d64a89d
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/AlterTablespaceNode.java
@@ -0,0 +1,103 @@
+/**
+ * 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.engine.planner;
+
+
+import com.google.common.base.Objects;
+import com.google.gson.annotations.Expose;
+import org.apache.tajo.algebra.AlterTablespaceSetType;
+import org.apache.tajo.engine.planner.logical.LogicalNode;
+import org.apache.tajo.engine.planner.logical.LogicalNodeVisitor;
+import org.apache.tajo.engine.planner.logical.NodeType;
+
+public class AlterTablespaceNode extends LogicalNode implements Cloneable {
+
+  @Expose private String tablespaceName;
+  @Expose private AlterTablespaceSetType setType;
+  @Expose private String uri;
+
+
+  public AlterTablespaceNode(int pid) {
+    super(pid, NodeType.ALTER_TABLESPACE);
+  }
+
+  public String getTablespaceName() {
+    return tablespaceName;
+  }
+
+  public void setTablespaceName(String tablespaceName) {
+    this.tablespaceName = tablespaceName;
+  }
+
+  public AlterTablespaceSetType getSetType() {
+    return setType;
+  }
+
+  public String getLocation() {
+    return uri;
+  }
+
+  public void setLocation(String uri) {
+    this.setType = AlterTablespaceSetType.LOCATION;
+    this.uri = uri;
+  }
+
+  @Override
+  public PlanString getPlanString() {
+    return new PlanString(this);
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (obj instanceof AlterTablespaceNode) {
+      AlterTablespaceNode other = (AlterTablespaceNode) obj;
+      return super.equals(other);
+    } else {
+      return false;
+    }
+  }
+
+  public int hashCode() {
+    return Objects.hashCode(tablespaceName, setType, uri);
+  }
+
+  @Override
+  public Object clone() throws CloneNotSupportedException {
+    AlterTablespaceNode alter = (AlterTablespaceNode) super.clone();
+    alter.tablespaceName = tablespaceName;
+    alter.setType = setType;
+    alter.uri = uri;
+    return alter;
+  }
+
+  @Override
+  public String toString() {
+    return "AlterTablespace (space=" + tablespaceName + ")";
+  }
+
+  @Override
+  public void preOrder(LogicalNodeVisitor visitor) {
+    visitor.visit(this);
+  }
+
+  @Override
+  public void postOrder(LogicalNodeVisitor visitor) {
+    visitor.visit(this);
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
index 44adf12..b8f3311 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BaseAlgebraVisitor.java
@@ -112,6 +112,9 @@ public class BaseAlgebraVisitor<CONTEXT, RESULT> implements AlgebraVisitor<CONTE
     case DropTable:
       current = visitDropTable(ctx, stack, (DropTable) expr);
       break;
+    case AlterTablespace:
+      current = visitAlterTablespace(ctx, stack, (AlterTablespace) expr);
+      break;
     case AlterTable:
       current = visitAlterTable(ctx, stack, (AlterTable) expr);
       break;
@@ -449,9 +452,14 @@ public class BaseAlgebraVisitor<CONTEXT, RESULT> implements AlgebraVisitor<CONTE
   }
 
   @Override
+  public RESULT visitAlterTablespace(CONTEXT ctx, Stack<Expr> stack, AlterTablespace expr) throws PlanningException {
+    return null;
+  }
+
+  @Override
   public RESULT visitAlterTable(CONTEXT ctx, Stack<Expr> stack, AlterTable expr) throws PlanningException {
-        return null;
-    }
+    return null;
+  }
 
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////
   // Insert or Update Section

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BasicLogicalPlanVisitor.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BasicLogicalPlanVisitor.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BasicLogicalPlanVisitor.java
index d569758..0f758bf 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BasicLogicalPlanVisitor.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/BasicLogicalPlanVisitor.java
@@ -116,6 +116,9 @@ public class BasicLogicalPlanVisitor<CONTEXT, RESULT> implements LogicalPlanVisi
       case DROP_TABLE:
         current = visitDropTable(context, plan, block, (DropTableNode) node, stack);
         break;
+      case ALTER_TABLESPACE:
+        current = visitAlterTablespace(context, plan, block, (AlterTablespaceNode) node, stack);
+        break;
       case ALTER_TABLE:
         current = visitAlterTable(context, plan, block, (AlterTableNode) node, stack);
         break;
@@ -301,6 +304,13 @@ public class BasicLogicalPlanVisitor<CONTEXT, RESULT> implements LogicalPlanVisi
                                Stack<LogicalNode> stack) {
     return null;
   }
+
+  @Override
+  public RESULT visitAlterTablespace(CONTEXT context, LogicalPlan plan, LogicalPlan.QueryBlock block,
+                                     AlterTablespaceNode node, Stack<LogicalNode> stack) throws PlanningException {
+    return null;
+  }
+
   @Override
   public RESULT visitAlterTable(CONTEXT context, LogicalPlan plan, LogicalPlan.QueryBlock block, AlterTableNode node,
                                  Stack<LogicalNode> stack) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanPreprocessor.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanPreprocessor.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanPreprocessor.java
index 540d45b..56863f7 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanPreprocessor.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanPreprocessor.java
@@ -414,6 +414,13 @@ class LogicalPlanPreprocessor extends BaseAlgebraVisitor<LogicalPlanPreprocessor
   }
 
   @Override
+  public LogicalNode visitAlterTablespace(PreprocessContext ctx, Stack<Expr> stack, AlterTablespace expr)
+      throws PlanningException {
+    AlterTablespaceNode alterTablespace = ctx.plan.createNode(AlterTablespaceNode.class);
+    return alterTablespace;
+  }
+
+  @Override
   public LogicalNode visitAlterTable(PreprocessContext ctx, Stack<Expr> stack, AlterTable expr)
       throws PlanningException {
     AlterTableNode alterTableNode = ctx.plan.createNode(AlterTableNode.class);

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanVisitor.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanVisitor.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanVisitor.java
index 7f38026..17b5d0a 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanVisitor.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanVisitor.java
@@ -83,6 +83,9 @@ public interface LogicalPlanVisitor<CONTEXT, RESULT> {
   RESULT visitDropTable(CONTEXT context, LogicalPlan plan, LogicalPlan.QueryBlock block, DropTableNode node,
                         Stack<LogicalNode> stack) throws PlanningException;
 
-  RESULT visitAlterTable(CONTEXT context, LogicalPlan plan, LogicalPlan.QueryBlock block, AlterTableNode node,
+  RESULT visitAlterTablespace(CONTEXT context, LogicalPlan plan, LogicalPlan.QueryBlock block, AlterTablespaceNode node,
                           Stack<LogicalNode> stack) throws PlanningException;
+
+  RESULT visitAlterTable(CONTEXT context, LogicalPlan plan, LogicalPlan.QueryBlock block, AlterTableNode node,
+                         Stack<LogicalNode> stack) throws PlanningException;
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
index 6336f50..8946c02 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
@@ -68,7 +68,7 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
     this.normalizer = new ExprNormalizer();
   }
 
-  public class PlanContext {
+  public static class PlanContext {
     Session session;
     LogicalPlan plan;
 
@@ -697,7 +697,7 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
     return groupingNode;
   }
 
-  public static final Column[] ALL= Lists.newArrayList().toArray(new Column[0]);
+  private static final Column[] ALL= Lists.newArrayList().toArray(new Column[0]);
 
   public static List<Column[]> generateCuboids(Column[] columns) {
     int numCuboids = (int) Math.pow(2, columns.length);
@@ -1471,6 +1471,13 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
     return dropTableNode;
   }
 
+  public LogicalNode visitAlterTablespace(PlanContext context, Stack<Expr> stack, AlterTablespace alterTablespace) {
+    AlterTablespaceNode alter = context.queryBlock.getNodeFromExpr(alterTablespace);
+    alter.setTablespaceName(alterTablespace.getTablespaceName());
+    alter.setLocation(alterTablespace.getLocation());
+    return alter;
+  }
+
   @Override
   public LogicalNode visitAlterTable(PlanContext context, Stack<Expr> stack, AlterTable alterTable) {
     AlterTableNode alterTableNode = context.queryBlock.getNodeFromExpr(alterTable);

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/PlannerUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/PlannerUtil.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/PlannerUtil.java
index 68578e8..5b43c5b 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/PlannerUtil.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/PlannerUtil.java
@@ -51,7 +51,9 @@ public class PlannerUtil {
         type == NodeType.CREATE_DATABASE ||
             type == NodeType.DROP_DATABASE ||
             (type == NodeType.CREATE_TABLE && !((CreateTableNode) baseNode).hasSubQuery()) ||
-            baseNode.getType() == NodeType.DROP_TABLE || baseNode.getType() == NodeType.ALTER_TABLE;
+            baseNode.getType() == NodeType.DROP_TABLE ||
+            baseNode.getType() == NodeType.ALTER_TABLESPACE ||
+            baseNode.getType() == NodeType.ALTER_TABLE;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/logical/NodeType.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/logical/NodeType.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/logical/NodeType.java
index 375926e..f498231 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/logical/NodeType.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/logical/NodeType.java
@@ -22,6 +22,8 @@
 package org.apache.tajo.engine.planner.logical;
 
 
+import org.apache.tajo.engine.planner.AlterTablespaceNode;
+
 /**
  * This indicates a logical node type.
  */
@@ -49,6 +51,7 @@ public enum NodeType {
   DROP_DATABASE(DropDatabaseNode.class),
   CREATE_TABLE(CreateTableNode.class),
   DROP_TABLE(DropTableNode.class),
+  ALTER_TABLESPACE (AlterTablespaceNode.class),
   ALTER_TABLE (AlterTableNode.class);
 
   private final Class<? extends LogicalNode> baseClass;

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalEngine.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalEngine.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalEngine.java
index cbb8f37..8acf2b2 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalEngine.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalEngine.java
@@ -28,11 +28,13 @@ import org.apache.hadoop.service.AbstractService;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.tajo.QueryId;
 import org.apache.tajo.QueryIdFactory;
+import org.apache.tajo.algebra.AlterTablespaceSetType;
 import org.apache.tajo.algebra.Expr;
 import org.apache.tajo.annotation.Nullable;
 import org.apache.tajo.catalog.*;
 import org.apache.tajo.catalog.exception.*;
 import org.apache.tajo.catalog.partition.PartitionMethodDesc;
+import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.catalog.statistics.TableStats;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.conf.TajoConf;
@@ -59,6 +61,8 @@ import java.util.List;
 
 import static org.apache.tajo.TajoConstants.DEFAULT_TABLESPACE_NAME;
 
+import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto;
+import static org.apache.tajo.catalog.proto.CatalogProtos.AlterTablespaceProto.AlterTablespaceCommand;
 import static org.apache.tajo.ipc.ClientProtos.SubmitQueryResponse;
 import static org.apache.tajo.ipc.ClientProtos.SubmitQueryResponse.SerializedResultSet;
 
@@ -263,8 +267,8 @@ public class GlobalEngine extends AbstractService {
           responseBuilder.setQueryMasterHost(queryInfo.getQueryMasterHost());
         }
         responseBuilder.setQueryMasterPort(queryInfo.getQueryMasterClientPort());
+        LOG.info("Query is forwarded to " + queryInfo.getQueryMasterHost() + ":" + queryInfo.getQueryMasterPort());
       }
-      LOG.info("Query is forwarded to " + queryInfo.getQueryMasterHost() + ":" + queryInfo.getQueryMasterPort());
     }
     SubmitQueryResponse response = responseBuilder.build();
     return response;
@@ -310,10 +314,14 @@ public class GlobalEngine extends AbstractService {
         DropTableNode dropTable = (DropTableNode) root;
         dropTable(session, dropTable.getTableName(), dropTable.isIfExists(), dropTable.isPurge());
         return true;
+      case ALTER_TABLESPACE:
+        AlterTablespaceNode alterTablespace = (AlterTablespaceNode) root;
+        alterTablespace(session, alterTablespace);
+        return true;
       case ALTER_TABLE:
-         AlterTableNode alterTable = (AlterTableNode) root;
-         alterTable(session,alterTable);
-         return true;
+        AlterTableNode alterTable = (AlterTableNode) root;
+        alterTable(session,alterTable);
+        return true;
       default:
         throw new InternalError("updateQuery cannot handle such query: \n" + root.toJson());
     }
@@ -356,6 +364,29 @@ public class GlobalEngine extends AbstractService {
   /**
    * Alter a given table
    */
+  public void alterTablespace(final Session session, final AlterTablespaceNode alterTablespace) {
+
+    final CatalogService catalog = context.getCatalog();
+    final String spaceName = alterTablespace.getTablespaceName();
+
+    AlterTablespaceProto.Builder builder = AlterTablespaceProto.newBuilder();
+    builder.setSpaceName(spaceName);
+    if (alterTablespace.getSetType() == AlterTablespaceSetType.LOCATION) {
+      AlterTablespaceCommand.Builder commandBuilder = AlterTablespaceCommand.newBuilder();
+      commandBuilder.setType(AlterTablespaceProto.AlterTablespaceType.LOCATION);
+      commandBuilder.setLocation(AlterTablespaceProto.SetLocation.newBuilder().setUri(alterTablespace.getLocation()));
+      commandBuilder.build();
+      builder.addCommand(commandBuilder);
+    } else {
+      throw new RuntimeException("This 'ALTER TABLESPACE' is not supported yet.");
+    }
+
+    catalog.alterTablespace(builder.build());
+  }
+
+  /**
+   * Alter a given table
+   */
   public void alterTable(final Session session, final AlterTableNode alterTable) throws IOException {
 
     final CatalogService catalog = context.getCatalog();

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestAlterTable.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestAlterTable.java b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestAlterTable.java
index 5779347..57d8b32 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestAlterTable.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestAlterTable.java
@@ -33,7 +33,6 @@ public class TestAlterTable extends QueryTestCaseBase {
     assertTableExists(createdNames.get(0));
     executeDDL("alter_table_rename_table_ddl.sql", null);
     assertTableExists("DEF");
-
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/tajo/blob/0a9f55b2/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestAlterTablespace.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestAlterTablespace.java b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestAlterTablespace.java
new file mode 100644
index 0000000..f827ab7
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestAlterTablespace.java
@@ -0,0 +1,63 @@
+/**
+ * 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.engine.query;
+
+import org.apache.tajo.IntegrationTest;
+import org.apache.tajo.QueryTestCaseBase;
+import org.apache.tajo.catalog.proto.CatalogProtos;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+@Category(IntegrationTest.class)
+public class TestAlterTablespace extends QueryTestCaseBase {
+
+  @Test
+  public final void testAlterLocation() throws Exception {
+    if (!testingCluster.isHCatalogStoreRunning()) {
+      //////////////////////////////////////////////////////////////////////////////
+      // Create two table spaces
+      //////////////////////////////////////////////////////////////////////////////
+
+      assertFalse(catalog.existTablespace("space1"));
+      assertTrue(catalog.createTablespace("space1", "hdfs://xxx.com/warehouse"));
+      assertTrue(catalog.existTablespace("space1"));
+
+      // pre verification
+      CatalogProtos.TablespaceProto space1 = catalog.getTablespace("space1");
+      assertEquals("space1", space1.getSpaceName());
+      assertEquals("hdfs://xxx.com/warehouse", space1.getUri());
+
+      executeString("ALTER TABLESPACE space1 LOCATION 'hdfs://yyy.com/warehouse';");
+
+      // Verify ALTER TABLESPACE space1
+      space1 = catalog.getTablespace("space1");
+      assertEquals("space1", space1.getSpaceName());
+      assertEquals("hdfs://yyy.com/warehouse", space1.getUri());
+
+      assertTrue(catalog.dropTablespace("space1"));
+      assertFalse(catalog.existTablespace("space1"));
+    }
+  }
+}


Mime
View raw message