tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [2/2] git commit: TAJO-480: Umbrella Jira for adding ALTER TABLE statement. (Alvin Henrick via hyunsik)
Date Mon, 31 Mar 2014 15:46:48 GMT
TAJO-480: Umbrella Jira for adding ALTER TABLE statement. (Alvin Henrick via hyunsik)


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

Branch: refs/heads/branch-0.8.0
Commit: f75c2e59b52fe089af9d30dd8b6a8cdccd646294
Parents: ae6e2d1
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Tue Apr 1 00:12:39 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Tue Apr 1 00:41:37 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |   3 +
 .../org/apache/tajo/algebra/AlterTable.java     | 111 ++++++++
 .../apache/tajo/algebra/AlterTableOpType.java   |  22 ++
 .../apache/tajo/algebra/ColumnDefinition.java   |  59 ++++
 .../org/apache/tajo/algebra/CreateTable.java    |  41 ---
 .../java/org/apache/tajo/algebra/OpType.java    |   1 +
 .../tajo/catalog/AbstractCatalogClient.java     |  18 +-
 .../org/apache/tajo/catalog/CatalogService.java |   7 +
 .../src/main/proto/CatalogProtocol.proto        |   2 +
 .../org/apache/tajo/catalog/AlterTableDesc.java | 150 ++++++++++
 .../org/apache/tajo/catalog/AlterTableType.java |  22 ++
 .../org/apache/tajo/catalog/CatalogUtil.java    |  25 ++
 .../ColumnNameAlreadyExistException.java        |  31 +++
 .../src/main/proto/CatalogProtos.proto          |  18 ++
 .../tajo/catalog/store/HCatalogStore.java       | 147 +++++++++-
 .../org/apache/tajo/catalog/CatalogServer.java  |  25 +-
 .../tajo/catalog/store/AbstractDBStore.java     | 277 ++++++++++++++++---
 .../apache/tajo/catalog/store/CatalogStore.java |   3 +-
 .../org/apache/tajo/catalog/store/MemStore.java |  74 ++++-
 .../org/apache/tajo/catalog/TestCatalog.java    |  49 ++++
 .../org/apache/tajo/engine/parser/SQLLexer.g4   |   4 +
 .../org/apache/tajo/engine/parser/SQLParser.g4  |  17 ++
 .../tajo/engine/parser/HiveQLAnalyzer.java      |   4 +-
 .../apache/tajo/engine/parser/SQLAnalyzer.java  | 223 ++++++++++-----
 .../tajo/engine/planner/AlgebraVisitor.java     |   3 +-
 .../tajo/engine/planner/BaseAlgebraVisitor.java |   8 +
 .../engine/planner/BasicLogicalPlanVisitor.java |   8 +
 .../engine/planner/LogicalPlanPreprocessor.java |   7 +
 .../tajo/engine/planner/LogicalPlanVisitor.java |   3 +
 .../tajo/engine/planner/LogicalPlanner.java     |  24 +-
 .../apache/tajo/engine/planner/PlannerUtil.java | 105 +++----
 .../engine/planner/SimpleAlgebraVisitor.java    |   7 +-
 .../engine/planner/logical/AlterTableNode.java  | 134 +++++++++
 .../tajo/engine/planner/logical/NodeType.java   |   5 +-
 .../org/apache/tajo/master/GlobalEngine.java    |  94 ++++++-
 .../java/org/apache/tajo/QueryTestCaseBase.java |  26 +-
 .../tajo/engine/query/TestAlterTable.java       |  53 ++++
 .../apache/tajo/engine/query/TestCTASQuery.java |  18 +-
 .../tajo/engine/query/TestCreateTable.java      |  59 ++++
 .../apache/tajo/engine/query/TestDropTable.java |  39 +++
 .../apache/tajo/engine/query/TestNetTypes.java  |  99 +++----
 .../resources/dataset/TestAlterTable/table1.tbl |   3 +
 .../resources/dataset/TestDropTable/table1.tbl  |   3 +
 .../alter_table_add_new_column_ddl.sql          |   1 +
 .../alter_table_rename_column_ddl.sql           |   1 +
 .../alter_table_rename_table_ddl.sql            |   1 +
 .../queries/TestAlterTable/table1_ddl.sql       |   1 +
 .../queries/TestDropTable/drop_table_ddl.sql    |   1 +
 .../queries/TestDropTable/table1_ddl.sql        |   1 +
 .../queries/TestNetTypes/table1_ddl.sql         |   2 +-
 .../queries/TestNetTypes/table2_ddl.sql         |   2 +-
 .../functions/datetime_func_and_operators.rst   |  39 ++-
 52 files changed, 1795 insertions(+), 285 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 4c39d02..ec0b7f8 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,9 @@ Release 0.8.0 - unreleased
 
   NEW FEATURES
 
+    TAJO-480: Umbrella Jira for adding ALTER TABLE statement.
+    (Alvin Henrick via hyunsik)
+
     TAJO-378: Implement concat_ws function. (Seungun Choe via jaehwa)
 
     TAJO-377: Implement concat function (Seungun Choe via jaehwa)

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTable.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTable.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTable.java
new file mode 100644
index 0000000..4bb0ed2
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTable.java
@@ -0,0 +1,111 @@
+/**
+ * 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 AlterTable extends Expr {
+
+  private String tableName;
+  private String newTableName;
+  private String columnName;
+  private String newColumnName;
+  private ColumnDefinition addNewColumn;
+  private AlterTableOpType alterTableOpType;
+
+  public AlterTable(final String tableName) {
+    super(OpType.AlterTable);
+    this.tableName = tableName;
+  }
+
+
+  public String getTableName() {
+    return tableName;
+  }
+
+  public void setTableName(String tableName) {
+    this.tableName = tableName;
+  }
+
+  public String getNewTableName() {
+    return newTableName;
+  }
+
+  public void setNewTableName(String newTableName) {
+    this.newTableName = newTableName;
+  }
+
+  public String getColumnName() {
+    return columnName;
+  }
+
+  public void setColumnName(String columnName) {
+    this.columnName = columnName;
+  }
+
+  public String getNewColumnName() {
+    return newColumnName;
+  }
+
+  public void setNewColumnName(String newColumnName) {
+    this.newColumnName = newColumnName;
+  }
+
+  public ColumnDefinition getAddNewColumn() {
+    return addNewColumn;
+  }
+
+  public void setAddNewColumn(ColumnDefinition addNewColumn) {
+    this.addNewColumn = addNewColumn;
+  }
+
+  public AlterTableOpType getAlterTableOpType() {
+    return alterTableOpType;
+  }
+
+  public void setAlterTableOpType(AlterTableOpType alterTableOpType) {
+    this.alterTableOpType = alterTableOpType;
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hashCode(tableName,
+        null != newTableName ? Objects.hashCode(newTableName) : newTableName,
+        null != columnName ? Objects.hashCode(columnName) : columnName,
+        null != newColumnName ? Objects.hashCode(newColumnName) : newColumnName,
+        null != addNewColumn ? Objects.hashCode(addNewColumn) : addNewColumn,
+        null != alterTableOpType ? Objects.hashCode(alterTableOpType) : alterTableOpType);
+
+  }
+
+  @Override
+  boolean equalsTo(Expr expr) {
+    AlterTable another = (AlterTable) expr;
+    return tableName.equals(another.tableName) &&
+        TUtil.checkEquals(newTableName, another.newTableName) &&
+        TUtil.checkEquals(columnName, another.columnName) &&
+        TUtil.checkEquals(newColumnName, another.newColumnName) &&
+        TUtil.checkEquals(addNewColumn, another.addNewColumn) &&
+        TUtil.checkEquals(alterTableOpType, another.alterTableOpType);
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTableOpType.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTableOpType.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTableOpType.java
new file mode 100644
index 0000000..67b28a2
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/AlterTableOpType.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 AlterTableOpType {
+  RENAME_TABLE, RENAME_COLUMN, ADD_COLUMN
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnDefinition.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnDefinition.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnDefinition.java
new file mode 100644
index 0000000..ce935dd
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnDefinition.java
@@ -0,0 +1,59 @@
+/**
+ * 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  class ColumnDefinition extends DataTypeExpr {
+  String col_name;
+
+  public ColumnDefinition(String columnName, String dataType) {
+    super(dataType);
+    this.col_name = columnName;
+  }
+
+  public ColumnDefinition(String columnName, DataTypeExpr dataType) {
+    super(dataType.getTypeName());
+    if (dataType.hasLengthOrPrecision()) {
+      setLengthOrPrecision(dataType.lengthOrPrecision);
+      if (dataType.hasScale()) {
+        setScale(dataType.scale);
+      }
+    }
+    this.col_name = columnName;
+  }
+
+  public String getColumnName() {
+    return this.col_name;
+  }
+
+  @Override
+  public int hashCode() {
+    int hash = super.hashCode();
+    return hash * 89 * col_name.hashCode();
+
+  }
+
+  @Override
+  public boolean equalsTo(Expr expr) {
+    if (expr instanceof ColumnDefinition) {
+      ColumnDefinition another = (ColumnDefinition) expr;
+      return col_name.equals(another.col_name) && super.equalsTo(another);
+    }
+
+    return false;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateTable.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateTable.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateTable.java
index eb11ed0..63ca364 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateTable.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CreateTable.java
@@ -155,47 +155,6 @@ public class CreateTable extends Expr {
         ifNotExists == another.ifNotExists;
   }
 
-  public static class ColumnDefinition extends DataTypeExpr {
-    String col_name;
-
-    public ColumnDefinition(String columnName, String dataType) {
-      super(dataType);
-      this.col_name = columnName;
-    }
-
-    public ColumnDefinition(String columnName, DataTypeExpr dataType) {
-      super(dataType.getTypeName());
-      if (dataType.hasLengthOrPrecision()) {
-        setLengthOrPrecision(dataType.lengthOrPrecision);
-        if (dataType.hasScale()) {
-          setScale(dataType.scale);
-        }
-      }
-      this.col_name = columnName;
-    }
-
-    public String getColumnName() {
-      return this.col_name;
-    }
-
-    @Override
-    public int hashCode() {
-      int hash = super.hashCode();
-      return hash * 89 * col_name.hashCode();
-
-    }
-
-    @Override
-    public boolean equalsTo(Expr expr) {
-      if (expr instanceof ColumnDefinition) {
-        ColumnDefinition another = (ColumnDefinition) expr;
-        return col_name.equals(another.col_name) && super.equalsTo(another);
-      }
-
-      return false;
-    }
-  }
-
   public static enum PartitionType {
     RANGE,
     HASH,

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/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 c4a007a..a4fb617 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
@@ -46,6 +46,7 @@ public enum OpType {
   DropDatabase(DropDatabase.class),
   CreateTable(CreateTable.class),
   DropTable(DropTable.class),
+  AlterTable(AlterTable.class),
 
   // Insert or Update
   Insert(Insert.class),

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/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 6fb385e..60cce9a 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
@@ -360,7 +360,7 @@ public abstract class AbstractCatalogClient implements CatalogService {
       return false;
     }
   }
-
+  @Override
   public final boolean existsTable(final String tableName) {
     String [] splitted = CatalogUtil.splitFQTableName(tableName);
     return existsTable(splitted[0], splitted[1]);
@@ -595,4 +595,20 @@ public abstract class AbstractCatalogClient implements CatalogService {
       return false;
     }
   }
+
+  @Override
+  public final boolean alterTable(final AlterTableDesc desc) {
+    try {
+      return new ServerCallable<Boolean>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
+        public Boolean call(NettyClientBase client) throws ServiceException {
+          CatalogProtocolService.BlockingInterface stub = getStub(client);
+          return stub.alterTable(null, desc.getProto()).getValue();
+        }
+      }.withRetries();
+    } catch (ServiceException e) {
+      LOG.error(e.getMessage(), e);
+      return false;
+    }
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/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 d69ed7e..f68f11a 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
@@ -157,4 +157,11 @@ public interface CatalogService {
   boolean containFunction(String signature, DataType... paramTypes);
 
   boolean containFunction(String signature, FunctionType funcType, DataType... paramTypes);
+
+  /**
+  * Add a table via table description
+  * @see AlterTableDesc
+  * @throws Throwable
+  */
+  boolean alterTable(AlterTableDesc desc);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/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 06b69c1..0f34f7c 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 alterTable(AlterTableDescProto) returns (BoolProto);
+
 
   rpc createDatabase(CreateDatabaseRequest) returns (BoolProto);
   rpc dropDatabase(StringProto) returns (BoolProto);

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableDesc.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableDesc.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableDesc.java
new file mode 100644
index 0000000..d69330d
--- /dev/null
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableDesc.java
@@ -0,0 +1,150 @@
+/**
+ * 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.catalog;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.annotations.Expose;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tajo.catalog.json.CatalogGsonHelper;
+import org.apache.tajo.catalog.proto.CatalogProtos;
+import org.apache.tajo.common.ProtoObject;
+import org.apache.tajo.json.GsonObject;
+
+
+public class AlterTableDesc implements ProtoObject<CatalogProtos.AlterTableDescProto>, GsonObject, Cloneable {
+  private final Log LOG = LogFactory.getLog(AlterTableDesc.class);
+
+  protected CatalogProtos.AlterTableDescProto.Builder builder = null;
+
+  @Expose
+  protected String tableName;  // required
+  @Expose
+  protected String newTableName;  // optional
+  @Expose
+  protected String columnName;   //optional
+  @Expose
+  protected String newColumnName; //optional
+  @Expose
+  protected Column addColumn = null; //optiona
+  @Expose
+  protected AlterTableType alterTableType; //required
+
+  public AlterTableDesc() {
+    builder = CatalogProtos.AlterTableDescProto.newBuilder();
+  }
+
+
+  public String getTableName() {
+    return tableName;
+  }
+
+  public void setTableName(String tableName) {
+    this.tableName = tableName;
+  }
+
+  public String getNewTableName() {
+    return newTableName;
+  }
+
+  public void setNewTableName(String newTableName) {
+    this.newTableName = newTableName;
+  }
+
+  public String getColumnName() {
+    return columnName;
+  }
+
+  public void setColumnName(String columnName) {
+    this.columnName = columnName;
+  }
+
+  public String getNewColumnName() {
+    return newColumnName;
+  }
+
+  public void setNewColumnName(String newColumnName) {
+    this.newColumnName = newColumnName;
+  }
+
+  public Column getAddColumn() {
+    return addColumn;
+  }
+
+  public void setAddColumn(Column addColumn) {
+    this.addColumn = addColumn;
+  }
+
+  public AlterTableType getAlterTableType() {
+    return alterTableType;
+  }
+
+  public void setAlterTableType(AlterTableType alterTableType) {
+    this.alterTableType = alterTableType;
+  }
+
+  @Override
+  public String toString() {
+    Gson gson = new GsonBuilder().setPrettyPrinting().
+        excludeFieldsWithoutExposeAnnotation().create();
+    return gson.toJson(this);
+  }
+
+  @Override
+  public String toJson() {
+    return CatalogGsonHelper.toJson(this, AlterTableDesc.class);
+  }
+
+  @Override
+  public CatalogProtos.AlterTableDescProto getProto() {
+    if (null == builder) {
+      builder = CatalogProtos.AlterTableDescProto.newBuilder();
+    }
+    if (null != this.tableName) {
+      builder.setTableName(this.tableName);
+    }
+    if (null != this.newTableName) {
+      builder.setNewTableName(this.newTableName);
+    }
+    if (null != this.columnName && null != this.newColumnName) {
+      final CatalogProtos.AlterColumnProto.Builder alterColumnBuilder = CatalogProtos.AlterColumnProto.newBuilder();
+      alterColumnBuilder.setOldColumnName(this.columnName);
+      alterColumnBuilder.setNewColumnName(this.newColumnName);
+      builder.setAlterColumnName(alterColumnBuilder.build());
+    }
+    if (null != this.addColumn) {
+      builder.setAddColumn(addColumn.getProto());
+    }
+
+    switch (alterTableType) {
+      case RENAME_TABLE:
+        builder.setAlterTableType(CatalogProtos.AlterTableType.RENAME_TABLE);
+        break;
+      case RENAME_COLUMN:
+        builder.setAlterTableType(CatalogProtos.AlterTableType.RENAME_COLUMN);
+        break;
+      case ADD_COLUMN:
+        builder.setAlterTableType(CatalogProtos.AlterTableType.ADD_COLUMN);
+        break;
+      default:
+    }
+    return builder.build();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableType.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableType.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableType.java
new file mode 100644
index 0000000..0b7639c
--- /dev/null
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/AlterTableType.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.catalog;
+
+public enum AlterTableType {
+    RENAME_TABLE, RENAME_COLUMN, ADD_COLUMN
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
index 9078e60..22f54ca 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
@@ -441,4 +441,29 @@ public class CatalogUtil {
       RESERVED_KEYWORDS_SET.add(keyword);
     }
   }
+
+  public static AlterTableDesc renameColumn(String tableName, String oldColumName, String newColumName, AlterTableType alterTableType) {
+    final AlterTableDesc alterTableDesc = new AlterTableDesc();
+    alterTableDesc.setTableName(tableName);
+    alterTableDesc.setColumnName(oldColumName);
+    alterTableDesc.setNewColumnName(newColumName);
+    alterTableDesc.setAlterTableType(alterTableType);
+    return alterTableDesc;
+  }
+
+  public static AlterTableDesc renameTable(String tableName, String newTableName, AlterTableType alterTableType) {
+    final AlterTableDesc alterTableDesc = new AlterTableDesc();
+    alterTableDesc.setTableName(tableName);
+    alterTableDesc.setNewTableName(newTableName);
+    alterTableDesc.setAlterTableType(alterTableType);
+    return alterTableDesc;
+  }
+
+  public static AlterTableDesc addNewColumn(String tableName, Column column, AlterTableType alterTableType) {
+    final AlterTableDesc alterTableDesc = new AlterTableDesc();
+    alterTableDesc.setTableName(tableName);
+    alterTableDesc.setAddColumn(column);
+    alterTableDesc.setAlterTableType(alterTableType);
+    return alterTableDesc;
+  }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/ColumnNameAlreadyExistException.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/ColumnNameAlreadyExistException.java b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/ColumnNameAlreadyExistException.java
new file mode 100644
index 0000000..1c026d7
--- /dev/null
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/exception/ColumnNameAlreadyExistException.java
@@ -0,0 +1,31 @@
+/**
+ * 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.catalog.exception;
+
+
+public class ColumnNameAlreadyExistException extends CatalogException {
+
+  private static final long serialVersionUID = -4863862140874083282L;
+
+  public ColumnNameAlreadyExistException() {
+  }
+
+  public ColumnNameAlreadyExistException(String columnName) {
+    super("Column already exists : " + columnName);
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/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 06ffcfd..d3abc70 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto
+++ b/tajo-catalog/tajo-catalog-common/src/main/proto/CatalogProtos.proto
@@ -48,6 +48,12 @@ enum PartitionType {
     COLUMN = 3;
 }
 
+enum AlterTableType {
+  RENAME_TABLE = 0;
+  RENAME_COLUMN = 1;
+  ADD_COLUMN = 2;
+}
+
 message ColumnProto {
 	required string name = 1;
 	required DataType dataType = 3;
@@ -263,3 +269,15 @@ message PartitionDescProto {
   optional string path = 5;
 }
 
+message AlterTableDescProto {
+  required string tableName = 1;
+  optional string newTableName = 2 ;
+  optional ColumnProto addColumn = 3;
+  optional AlterColumnProto alterColumnName = 4;
+  required AlterTableType alterTableType = 5;
+}
+
+message AlterColumnProto {
+  required string oldColumnName = 1;
+  required string newColumnName = 2;
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/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 6ef255f..a4bdb28 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
@@ -36,9 +36,7 @@ import org.apache.hcatalog.data.schema.HCatSchema;
 import org.apache.tajo.TajoConstants;
 import org.apache.tajo.catalog.*;
 import org.apache.tajo.catalog.Schema;
-import org.apache.tajo.catalog.exception.AlreadyExistsDatabaseException;
-import org.apache.tajo.catalog.exception.CatalogException;
-import org.apache.tajo.catalog.exception.NoSuchDatabaseException;
+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;
@@ -135,7 +133,7 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
         isPartitionKey = false;
 
         if (table.getPartitionKeys() != null) {
-          for(FieldSchema partitionKey: table.getPartitionKeys()) {
+          for (FieldSchema partitionKey : table.getPartitionKeys()) {
             if (partitionKey.getName().equals(eachField.getName())) {
               isPartitionKey = true;
             }
@@ -198,7 +196,7 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
 
         // set data size
         long totalSize = 0;
-        if(properties.getProperty("totalSize") != null) {
+        if (properties.getProperty("totalSize") != null) {
           totalSize = Long.parseLong(properties.getProperty("totalSize"));
         } else {
           try {
@@ -219,7 +217,7 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
         StringBuilder sb = new StringBuilder();
         if (table.getPartitionKeys().size() > 0) {
           List<FieldSchema> partitionKeys = table.getPartitionKeys();
-          for(int i = 0; i < partitionKeys.size(); i++) {
+          for (int i = 0; i < partitionKeys.size(); i++) {
             FieldSchema fieldSchema = partitionKeys.get(i);
             TajoDataTypes.Type dataType = HCatalogUtil.getTajoFieldType(fieldSchema.getType().toString());
             String fieldName = databaseName + CatalogUtil.IDENTIFIER_DELIMITER + tableName +
@@ -377,7 +375,7 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
     HCatalogStoreClientPool.HCatalogStoreClient client = null;
 
     TableDesc tableDesc = new TableDesc(tableDescProto);
-    String [] splitted = CatalogUtil.splitFQTableName(tableDesc.getName());
+    String[] splitted = CatalogUtil.splitFQTableName(tableDesc.getName());
     String databaseName = splitted[0];
     String tableName = splitted[1];
 
@@ -425,8 +423,8 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
       // set partition keys
       if (tableDesc.hasPartition() && tableDesc.getPartitionMethod().getPartitionType().equals(PartitionType.COLUMN)) {
         List<FieldSchema> partitionKeys = new ArrayList<FieldSchema>();
-        for(Column eachPartitionKey: tableDesc.getPartitionMethod().getExpressionSchema().getColumns()) {
-          partitionKeys.add(new FieldSchema( eachPartitionKey.getSimpleName(),
+        for (Column eachPartitionKey : tableDesc.getPartitionMethod().getExpressionSchema().getColumns()) {
+          partitionKeys.add(new FieldSchema(eachPartitionKey.getSimpleName(),
               HCatalogUtil.getHiveFieldType(eachPartitionKey.getDataType()), ""));
         }
         table.setPartitionKeys(partitionKeys);
@@ -500,6 +498,110 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
     }
   }
 
+
+  @Override
+  public void alterTable(final CatalogProtos.AlterTableDescProto alterTableDescProto) throws CatalogException {
+
+    HCatalogStoreClientPool.HCatalogStoreClient client = clientPool.getClient();
+
+    final String[] split = CatalogUtil.splitFQTableName(alterTableDescProto.getTableName());
+
+    if (split.length == 1) {
+      throw new IllegalArgumentException("alterTable() requires a qualified table name, but it is \""
+          + alterTableDescProto.getTableName() + "\".");
+    }
+
+    final String databaseName = split[0];
+    final String tableName = split[1];
+
+
+    switch (alterTableDescProto.getAlterTableType()) {
+      case RENAME_TABLE:
+        if (existTable(databaseName,alterTableDescProto.getNewTableName().toLowerCase())) {
+          throw new AlreadyExistsTableException(alterTableDescProto.getNewTableName());
+        }
+        renameTable(databaseName, tableName, alterTableDescProto.getNewTableName().toLowerCase());
+        break;
+      case RENAME_COLUMN:
+        if (existColumn(databaseName,tableName, alterTableDescProto.getAlterColumnName().getNewColumnName())) {
+          throw new ColumnNameAlreadyExistException(alterTableDescProto.getAlterColumnName().getNewColumnName());
+        }
+        renameColumn(databaseName, tableName, alterTableDescProto.getAlterColumnName());
+        break;
+      case ADD_COLUMN:
+        if (existColumn(databaseName,tableName, alterTableDescProto.getAddColumn().getName())) {
+          throw new ColumnNameAlreadyExistException(alterTableDescProto.getAddColumn().getName());
+        }
+        addNewColumn(databaseName, tableName, alterTableDescProto.getAddColumn());
+        break;
+      default:
+        //TODO
+    }
+
+
+  }
+
+
+  private void renameTable(String databaseName, String tableName, String newTableName) {
+    HCatalogStoreClientPool.HCatalogStoreClient client = null;
+    try {
+      client = clientPool.getClient();
+      Table newTable = client.getHiveClient().getTable(databaseName, tableName);
+      newTable.setTableName(newTableName);
+      client.getHiveClient().alter_table(databaseName, tableName, newTable);
+
+    } catch (NoSuchObjectException nsoe) {
+    } catch (Exception e) {
+      throw new CatalogException(e);
+    } finally {
+      client.release();
+    }
+  }
+
+  private void renameColumn(String databaseName, String tableName, CatalogProtos.AlterColumnProto alterColumnProto) {
+    HCatalogStoreClientPool.HCatalogStoreClient client = null;
+    try {
+
+      client = clientPool.getClient();
+      Table table = client.getHiveClient().getTable(databaseName, tableName);
+      List<FieldSchema> columns = table.getSd().getCols();
+
+      for (final FieldSchema currentColumn : columns) {
+        if (currentColumn.getName().equalsIgnoreCase(alterColumnProto.getOldColumnName())) {
+          currentColumn.setName(alterColumnProto.getNewColumnName());
+        }
+      }
+      client.getHiveClient().alter_table(databaseName, tableName, table);
+
+    } catch (NoSuchObjectException nsoe) {
+    } catch (Exception e) {
+      throw new CatalogException(e);
+    } finally {
+      client.release();
+    }
+  }
+
+
+  private void addNewColumn(String databaseName, String tableName, CatalogProtos.ColumnProto columnProto) {
+    HCatalogStoreClientPool.HCatalogStoreClient client = null;
+    try {
+
+      client = clientPool.getClient();
+      Table table = client.getHiveClient().getTable(databaseName, tableName);
+      List<FieldSchema> columns = table.getSd().getCols();
+      columns.add(new FieldSchema(columnProto.getName(),
+          HCatalogUtil.getHiveFieldType(columnProto.getDataType()), ""));
+      client.getHiveClient().alter_table(databaseName, tableName, table);
+
+
+    } catch (NoSuchObjectException nsoe) {
+    } catch (Exception e) {
+      throw new CatalogException(e);
+    } finally {
+      client.release();
+    }
+  }
+
   @Override
   public void addPartitionMethod(CatalogProtos.PartitionMethodProto partitionMethodProto) throws CatalogException {
     // TODO - not implemented yet
@@ -618,4 +720,31 @@ public class HCatalogStore extends CatalogConstants implements CatalogStore {
   public final void close() {
     clientPool.close();
   }
+
+  private boolean existColumn(final String databaseName ,final String tableName , final String columnName) throws CatalogException {
+    boolean exist = false;
+    HCatalogStoreClientPool.HCatalogStoreClient client = null;
+
+    try {
+
+      client = clientPool.getClient();
+      Table table = client.getHiveClient().getTable(databaseName, tableName);
+      List<FieldSchema> columns = table.getSd().getCols();
+
+      for (final FieldSchema currentColumn : columns) {
+        if (currentColumn.getName().equalsIgnoreCase(columnName)) {
+          exist = true;
+        }
+      }
+      client.getHiveClient().alter_table(databaseName, tableName, table);
+
+    } catch (NoSuchObjectException nsoe) {
+    } catch (Exception e) {
+      throw new CatalogException(e);
+    } finally {
+      client.release();
+    }
+
+    return exist;
+  }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/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 16a82dc..19574bc 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
@@ -102,7 +102,7 @@ public class CatalogServer extends AbstractService {
     this.builtingFuncs = sqlFuncs;
   }
 
-  @Override
+  
   public void serviceInit(Configuration conf) throws Exception {
 
     Constructor<?> cons;
@@ -301,6 +301,26 @@ public class CatalogServer extends AbstractService {
     }
 
     @Override
+    public BoolProto alterTable(RpcController controller, AlterTableDescProto proto) throws ServiceException {
+      wlock.lock();
+      try {
+        String [] split = CatalogUtil.splitTableName(proto.getTableName());
+        if (!store.existTable(split[0], split[1])) {
+          throw new NoSuchTableException(proto.getTableName());
+        }
+        store.alterTable(proto);
+      } catch (Exception e) {
+        LOG.error(e.getMessage(), e);
+        return BOOL_FALSE;
+      } finally {
+        wlock.unlock();
+        LOG.info("Table " + proto.getTableName() + " is altered in the catalog ("
+            + bindAddressStr + ")");
+      }
+      return BOOL_TRUE;
+    }
+
+    @Override
     public BoolProto dropDatabase(RpcController controller, StringProto request) throws ServiceException {
       String databaseName = request.getValue();
 
@@ -588,7 +608,6 @@ public class CatalogServer extends AbstractService {
 
     @Override
     public BoolProto addPartitions(RpcController controller, PartitionsProto request) throws ServiceException {
-
       return ProtoUtil.TRUE;
     }
 
@@ -809,7 +828,7 @@ public class CatalogServer extends AbstractService {
       return BOOL_TRUE;
     }
 
-    @Override
+     @Override
     public BoolProto dropFunction(RpcController controller, UnregisterFunctionRequest request)
         throws ServiceException {
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/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 d10f545..b1efc7f 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
@@ -29,10 +29,7 @@ import org.apache.tajo.annotation.Nullable;
 import org.apache.tajo.catalog.CatalogConstants;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.FunctionDesc;
-import org.apache.tajo.catalog.exception.CatalogException;
-import org.apache.tajo.catalog.exception.NoSuchDatabaseException;
-import org.apache.tajo.catalog.exception.NoSuchTableException;
-import org.apache.tajo.catalog.exception.NoSuchTablespaceException;
+import org.apache.tajo.catalog.exception.*;
 import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.catalog.proto.CatalogProtos.*;
 import org.apache.tajo.common.TajoDataTypes.Type;
@@ -73,7 +70,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
     this.conf = conf;
 
-    if(conf.get(CatalogConstants.DEPRECATED_CATALOG_URI) != null) {
+    if (conf.get(CatalogConstants.DEPRECATED_CATALOG_URI) != null) {
       LOG.warn("Configuration parameter " + CatalogConstants.DEPRECATED_CATALOG_URI + " " +
           "is deprecated. Use " + CatalogConstants.CATALOG_URI + " instead.");
       this.catalogUri = conf.get(CatalogConstants.DEPRECATED_CATALOG_URI);
@@ -81,7 +78,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       this.catalogUri = conf.get(CatalogConstants.CATALOG_URI);
     }
 
-    if(conf.get(CatalogConstants.DEPRECATED_CONNECTION_ID) != null) {
+    if (conf.get(CatalogConstants.DEPRECATED_CONNECTION_ID) != null) {
       LOG.warn("Configuration parameter " + CatalogConstants.DEPRECATED_CONNECTION_ID + " " +
           "is deprecated. Use " + CatalogConstants.CONNECTION_ID + " instead.");
       this.connectionId = conf.get(CatalogConstants.DEPRECATED_CONNECTION_ID);
@@ -89,7 +86,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       this.connectionId = conf.get(CatalogConstants.CONNECTION_ID);
     }
 
-    if(conf.get(CatalogConstants.DEPRECATED_CONNECTION_PASSWORD) != null) {
+    if (conf.get(CatalogConstants.DEPRECATED_CONNECTION_PASSWORD) != null) {
       LOG.warn("Configuration parameter " + CatalogConstants.DEPRECATED_CONNECTION_PASSWORD + " " +
           "is deprecated. Use " + CatalogConstants.CONNECTION_PASSWORD + " instead.");
       this.connectionPassword = conf.get(CatalogConstants.DEPRECATED_CONNECTION_PASSWORD);
@@ -146,7 +143,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
     }
   }
 
-  protected String getCatalogUri(){
+  protected String getCatalogUri() {
     return catalogUri;
   }
 
@@ -180,7 +177,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
       boolean noVersion = !result.next();
 
-      int schemaVersion =  result.getInt(1);
+      int schemaVersion = result.getInt(1);
       if (noVersion || schemaVersion != getDriverVersion()) {
         LOG.error(String.format("Catalog version (%d) and current driver version (%d) are mismatch to each other",
             schemaVersion, getDriverVersion()));
@@ -266,7 +263,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
     try {
       StringBuilder sql = new StringBuilder();
-      sql.append("SELECT SPACE_NAME FROM " + TB_SPACES +" WHERE SPACE_NAME = ?");
+      sql.append("SELECT SPACE_NAME FROM " + TB_SPACES + " WHERE SPACE_NAME = ?");
       if (LOG.isDebugEnabled()) {
         LOG.debug(sql.toString());
       }
@@ -302,7 +299,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         dropDatabase(databaseName);
       }
 
-      String sql = "DELETE FROM " + TB_SPACES + " WHERE " + COL_TABLESPACE_PK +"= ?";
+      String sql = "DELETE FROM " + TB_SPACES + " WHERE " + COL_TABLESPACE_PK + "= ?";
       pstmt = conn.prepareStatement(sql);
       pstmt.setInt(1, tableSpace.getSpaceId());
       pstmt.executeUpdate();
@@ -326,7 +323,6 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
     return getAllTablespaceNamesInternal(null);
   }
 
-
   private Collection<String> getAllTablespaceNamesInternal(@Nullable String whereCondition) throws CatalogException {
     Connection conn = null;
     PreparedStatement pstmt = null;
@@ -344,7 +340,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       conn = getConnection();
       pstmt = conn.prepareStatement(sql);
       resultSet = pstmt.executeQuery();
-      while(resultSet.next()) {
+      while (resultSet.next()) {
         tablespaceNames.add(resultSet.getString(1));
       }
     } catch (SQLException se) {
@@ -476,7 +472,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       conn = getConnection();
       pstmt = conn.prepareStatement(sql);
       resultSet = pstmt.executeQuery();
-      while(resultSet.next()) {
+      while (resultSet.next()) {
         databaseNames.add(resultSet.getString(1));
       }
     } catch (SQLException se) {
@@ -572,7 +568,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       conn = getConnection();
       conn.setAutoCommit(false);
 
-      String [] splitted = CatalogUtil.splitTableName(table.getTableName());
+      String[] splitted = CatalogUtil.splitTableName(table.getTableName());
       if (splitted.length == 1) {
         throw new IllegalArgumentException("createTable() requires a qualified table name, but it is \""
             + table.getTableName() + "\".");
@@ -636,7 +632,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       }
 
       pstmt = conn.prepareStatement(colSql);
-      for(int i = 0; i < table.getSchema().getFieldsCount(); i++) {
+      for (int i = 0; i < table.getSchema().getFieldsCount(); i++) {
         ColumnProto col = table.getSchema().getFields(i);
         pstmt.setInt(1, tableId);
         pstmt.setString(2, CatalogUtil.extractSimpleName(col.getName()));
@@ -649,7 +645,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       pstmt.executeBatch();
       pstmt.close();
 
-      if(table.getMeta().hasParams()) {
+      if (table.getMeta().hasParams()) {
         String propSQL = "INSERT INTO " + TB_OPTIONS + "(TID, KEY_, VALUE_) VALUES(?, ?, ?)";
 
         if (LOG.isDebugEnabled()) {
@@ -684,7 +680,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
         pstmt.close();
       }
 
-      if(table.hasPartition()) {
+      if (table.hasPartition()) {
         String partSql =
             "INSERT INTO PARTITION_METHODS (TID, PARTITION_TYPE, EXPRESSION, EXPRESSION_SCHEMA) VALUES(?, ?, ?, ?)";
 
@@ -716,6 +712,183 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
     }
   }
 
+  @Override
+  public void alterTable(CatalogProtos.AlterTableDescProto alterTableDescProto) throws CatalogException {
+
+    String[] splitted = CatalogUtil.splitTableName(alterTableDescProto.getTableName());
+    if (splitted.length == 1) {
+      throw new IllegalArgumentException("alterTable() requires a qualified table name, but it is \""
+          + alterTableDescProto.getTableName() + "\".");
+    }
+    String databaseName = splitted[0];
+    String tableName = splitted[1];
+
+    try {
+
+      int databaseId = getDatabaseId(databaseName);
+      int tableId = getTableId(databaseId, databaseName, tableName);
+
+      switch (alterTableDescProto.getAlterTableType()) {
+        case RENAME_TABLE:
+          if (existTable(databaseName,alterTableDescProto.getNewTableName())) {
+            throw new AlreadyExistsTableException(alterTableDescProto.getNewTableName());
+          }
+          renameTable(tableId, alterTableDescProto.getNewTableName());
+          break;
+        case RENAME_COLUMN:
+          if (existColumn(tableId, alterTableDescProto.getAlterColumnName().getNewColumnName())) {
+            throw new ColumnNameAlreadyExistException(alterTableDescProto.getAlterColumnName().getNewColumnName());
+          }
+          renameColumn(tableId, alterTableDescProto.getAlterColumnName());
+          break;
+        case ADD_COLUMN:
+          if (existColumn(tableId, alterTableDescProto.getAddColumn().getName())) {
+            throw new ColumnNameAlreadyExistException(alterTableDescProto.getAddColumn().getName());
+          }
+          addNewColumn(tableId, alterTableDescProto.getAddColumn());
+          break;
+        default:
+      }
+    } catch (SQLException sqlException) {
+      throw new CatalogException(sqlException);
+    }
+
+  }
+
+  private void renameTable(final int tableId, final String tableName) throws CatalogException {
+
+    final String updtaeRenameTableSql = "UPDATE " + TB_TABLES + " SET " + COL_TABLES_NAME + " = ? " + " WHERE TID = ?";
+
+    if (LOG.isDebugEnabled()) {
+      LOG.debug(updtaeRenameTableSql);
+    }
+
+    Connection conn;
+    PreparedStatement pstmt = null;
+
+    try {
+
+      conn = getConnection();
+      pstmt = conn.prepareStatement(updtaeRenameTableSql);
+      pstmt.setString(1, tableName);
+      pstmt.setInt(2, tableId);
+      pstmt.executeUpdate();
+
+    } catch (SQLException sqlException) {
+      throw new CatalogException(sqlException);
+    } finally {
+      CatalogUtil.closeQuietly(pstmt);
+    }
+  }
+
+  private void renameColumn(final int tableId, final CatalogProtos.AlterColumnProto alterColumnProto) throws CatalogException {
+
+    final String selectColumnSql = "SELECT COLUMN_NAME, DATA_TYPE, TYPE_LENGTH, ORDINAL_POSITION from " + TB_COLUMNS +" WHERE " + COL_TABLES_PK + " = ?" + " AND COLUMN_NAME = ?" ;
+    final String deleteColumnNameSql = "DELETE FROM " + TB_COLUMNS + " WHERE TID = ? AND COLUMN_NAME = ?";
+    final String insertNewColumnSql = "INSERT INTO " + TB_COLUMNS + " (TID, COLUMN_NAME, ORDINAL_POSITION, DATA_TYPE, TYPE_LENGTH) VALUES(?, ?, ?, ?, ?) ";
+
+    if (LOG.isDebugEnabled()) {
+      LOG.debug(selectColumnSql);
+      LOG.debug(deleteColumnNameSql);
+      LOG.debug(insertNewColumnSql);
+    }
+
+    Connection conn;
+    PreparedStatement pstmt = null;
+    ResultSet resultSet = null;
+
+    try {
+
+      conn = getConnection();
+      conn.setAutoCommit(false);
+
+      //SELECT COLUMN
+      pstmt = conn.prepareStatement(selectColumnSql);
+      pstmt.setInt(1, tableId);
+      pstmt.setString(2, alterColumnProto.getOldColumnName());
+      resultSet = pstmt.executeQuery();
+
+      CatalogProtos.ColumnProto columnProto = null;
+      int ordinalPostion = -1;
+
+      if (resultSet.next()) {
+        columnProto = resultToColumnProto(resultSet);
+        //NOTE ==> Setting new column Name
+        columnProto = columnProto.toBuilder().setName(alterColumnProto.getNewColumnName()).build();
+        ordinalPostion = resultSet.getInt("ORDINAL_POSITION");
+      }
+
+      resultSet.close();
+      pstmt.close();
+      resultSet = null;
+
+      //DELETE COLUMN
+      pstmt = conn.prepareStatement(deleteColumnNameSql);
+      pstmt.setInt(1, tableId);
+      pstmt.setString(2, alterColumnProto.getOldColumnName());
+      pstmt.executeUpdate();
+      pstmt.close();
+
+      //INSERT COLUMN
+      pstmt = conn.prepareStatement(insertNewColumnSql);
+      pstmt.setInt(1, tableId);
+      pstmt.setString(2, CatalogUtil.extractSimpleName(columnProto.getName()));
+      pstmt.setInt(3, ordinalPostion);
+      pstmt.setString(4, columnProto.getDataType().getType().name());
+      pstmt.setInt(5, (columnProto.getDataType().hasLength() ? columnProto.getDataType().getLength() : 0));
+      pstmt.executeUpdate();
+
+      conn.commit();
+
+
+    } catch (SQLException sqlException) {
+      throw new CatalogException(sqlException);
+    } finally {
+      CatalogUtil.closeQuietly(pstmt,resultSet);
+    }
+  }
+
+  private void addNewColumn(int tableId, CatalogProtos.ColumnProto columnProto) throws CatalogException {
+
+    final String insertNewColumnSql = "INSERT INTO " + TB_COLUMNS + " (TID, COLUMN_NAME, ORDINAL_POSITION, DATA_TYPE, TYPE_LENGTH) VALUES(?, ?, ?, ?, ?) ";
+    final String columnCountSql = "SELECT COLUMN_NAME, MAX(ORDINAL_POSITION) AS POSITION FROM " + TB_COLUMNS + " WHERE TID = ? GROUP BY COLUMN_NAME";
+
+    if (LOG.isDebugEnabled()) {
+      LOG.debug(insertNewColumnSql);
+      LOG.debug(columnCountSql);
+    }
+
+    Connection conn;
+    PreparedStatement pstmt = null;
+    ResultSet resultSet = null;
+
+    try {
+      conn = getConnection();
+      pstmt = conn.prepareStatement(columnCountSql);
+      pstmt.setInt(1 , tableId);
+      resultSet =  pstmt.executeQuery();
+
+      int position = resultSet.next() ? resultSet.getInt("POSITION") : 0;
+
+      resultSet.close();
+      pstmt.close();
+      resultSet = null;
+
+      pstmt = conn.prepareStatement(insertNewColumnSql);
+      pstmt.setInt(1, tableId);
+      pstmt.setString(2, CatalogUtil.extractSimpleName(columnProto.getName()));
+      pstmt.setInt(3, position + 1);
+      pstmt.setString(4, columnProto.getDataType().getType().name());
+      pstmt.setInt(5, (columnProto.getDataType().hasLength() ? columnProto.getDataType().getLength() : 0));
+      pstmt.executeUpdate();
+
+    } catch (SQLException sqlException) {
+      throw new CatalogException(sqlException);
+    } finally {
+      CatalogUtil.closeQuietly(pstmt,resultSet);
+    }
+  }
+
   private int getDatabaseId(String databaseName) throws SQLException {
     String sql = String.format("SELECT DB_ID from %s WHERE DB_NAME = ?", TB_DATABASES);
 
@@ -986,7 +1159,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       //////////////////////////////////////////
       CatalogProtos.TableProto.Builder metaBuilder = CatalogProtos.TableProto.newBuilder();
       metaBuilder.setStoreType(storeType);
-      sql = "SELECT key_, value_ FROM " + TB_OPTIONS +" WHERE " + COL_TABLES_PK + " = ?";
+      sql = "SELECT key_, value_ FROM " + TB_OPTIONS + " WHERE " + COL_TABLES_PK + " = ?";
 
       if (LOG.isDebugEnabled()) {
         LOG.debug(sql);
@@ -1136,12 +1309,12 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
   private static void addPartitionInternal(PreparedStatement pstmt, int tableId, PartitionDescProto partition) throws
       SQLException {
-      pstmt.setInt(1, tableId);
-      pstmt.setString(2, partition.getPartitionName());
-      pstmt.setInt(3, partition.getOrdinalPosition());
-      pstmt.setString(4, partition.getPath());
-      pstmt.addBatch();
-      pstmt.clearParameters();
+    pstmt.setInt(1, tableId);
+    pstmt.setString(2, partition.getPartitionName());
+    pstmt.setInt(3, partition.getOrdinalPosition());
+    pstmt.setString(4, partition.getPath());
+    pstmt.addBatch();
+    pstmt.clearParameters();
   }
 
   @Override
@@ -1151,7 +1324,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
     try {
       String sql = "INSERT INTO " + TB_PARTITION_METHODS + " (TID, PARTITION_TYPE,  EXPRESSION, EXPRESSION_SCHEMA) " +
-              "VALUES (?,?,?,?)";
+          "VALUES (?,?,?,?)";
 
       if (LOG.isDebugEnabled()) {
         LOG.debug(sql);
@@ -1209,7 +1382,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
     try {
       String sql = "SELECT partition_type, expression, expression_schema FROM " + TB_PARTITION_METHODS +
-      " WHERE " + COL_TABLES_NAME + " = ? ";
+          " WHERE " + COL_TABLES_NAME + " = ? ";
 
       if (LOG.isDebugEnabled()) {
         LOG.debug(sql);
@@ -1242,7 +1415,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
     try {
       String sql = "SELECT partition_type, expression, expression_schema FROM " + TB_PARTITION_METHODS +
-      " WHERE " + COL_TABLES_NAME + "= ?";
+          " WHERE " + COL_TABLES_NAME + "= ?";
 
       if (LOG.isDebugEnabled()) {
         LOG.debug(sql);
@@ -1256,7 +1429,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       exist = res.next();
     } catch (SQLException se) {
       throw new CatalogException(se);
-    } finally {                           
+    } finally {
       CatalogUtil.closeQuietly(pstmt, res);
     }
     return exist;
@@ -1362,7 +1535,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
       int tableId = getTableId(databaseId, databaseName, tableName);
 
       String sql = "INSERT INTO " + TB_INDEXES +
-        " (" + COL_DATABASES_PK + ", " + COL_TABLES_PK + ", INDEX_NAME, " +
+          " (" + COL_DATABASES_PK + ", " + COL_TABLES_PK + ", INDEX_NAME, " +
           "COLUMN_NAME, DATA_TYPE, INDEX_TYPE, IS_UNIQUE, IS_CLUSTERED, IS_ASCENDING) VALUES (?,?,?,?,?,?,?,?,?)";
 
       if (LOG.isDebugEnabled()) {
@@ -1422,7 +1595,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
     try {
       pstmt =
-          conn.prepareStatement("SELECT " + COL_TABLES_NAME + " FROM " + TB_TABLES + " WHERE " + COL_TABLES_PK +"=?");
+          conn.prepareStatement("SELECT " + COL_TABLES_NAME + " FROM " + TB_TABLES + " WHERE " + COL_TABLES_PK + "=?");
       pstmt.setInt(1, tableId);
       res = pstmt.executeQuery();
       if (!res.next()) {
@@ -1435,9 +1608,10 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
   }
 
   final static String GET_INDEXES_SQL =
-      "SELECT " + COL_TABLES_PK + ", INDEX_NAME, COLUMN_NAME, DATA_TYPE, INDEX_TYPE, IS_UNIQUE, "+
+      "SELECT " + COL_TABLES_PK + ", INDEX_NAME, COLUMN_NAME, DATA_TYPE, INDEX_TYPE, IS_UNIQUE, " +
           "IS_CLUSTERED, IS_ASCENDING FROM " + TB_INDEXES;
 
+
   @Override
   public IndexDescProto getIndexByName(String databaseName, final String indexName)
       throws CatalogException {
@@ -1497,7 +1671,8 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
       conn = getConnection();
       pstmt = conn.prepareStatement(sql);
-      pstmt.setInt(1, databaseId);;
+      pstmt.setInt(1, databaseId);
+      ;
       pstmt.setString(2, columnName);
       res = pstmt.executeQuery();
       if (!res.next()) {
@@ -1625,7 +1800,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
   }
 
   private void resultToIndexDescProtoBuilder(IndexDescProto.Builder builder,
-                                                final ResultSet res) throws SQLException {
+                                             final ResultSet res) throws SQLException {
     builder.setIndexName(res.getString("index_name"));
     builder.setColumn(indexResultToColumnProto(res));
     builder.setIndexMethod(getIndexMethod(res.getString("index_type").trim()));
@@ -1653,7 +1828,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
 
     Type type = getDataType(res.getString("data_type").trim());
     int typeLength = res.getInt("type_length");
-    if(typeLength > 0 ) {
+    if (typeLength > 0) {
       builder.setDataType(CatalogUtil.newDataTypeWithLen(type, typeLength));
     } else {
       builder.setDataType(CatalogUtil.newSimpleDataType(type));
@@ -1696,7 +1871,7 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
     return partBuilder.build();
   }
 
-  @Override
+
   public void close() {
     CatalogUtil.closeQuietly(conn);
     LOG.info("Shutdown database (" + catalogUri + ")");
@@ -1722,4 +1897,34 @@ public abstract class AbstractDBStore extends CatalogConstants implements Catalo
     // TODO - not implemented yet
     return null;
   }
+
+  private boolean existColumn(final int tableId, final String columnName) throws CatalogException {
+    Connection conn ;
+    PreparedStatement pstmt = null;
+    ResultSet res = null;
+    boolean exist = false;
+
+    try {
+
+      String sql = "SELECT COLUMN_NAME FROM " + TB_COLUMNS + " WHERE TID = ? AND COLUMN_NAME = ?";
+
+      if (LOG.isDebugEnabled()) {
+        LOG.debug(sql.toString());
+      }
+
+      conn = getConnection();
+      pstmt = conn.prepareStatement(sql.toString());
+
+      pstmt.setInt(1, tableId);
+      pstmt.setString(2, columnName);
+      res = pstmt.executeQuery();
+      exist = res.next();
+    } catch (SQLException se) {
+      throw new CatalogException(se);
+    } finally {
+      CatalogUtil.closeQuietly(pstmt, res);
+    }
+
+    return exist;
+  }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/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 3f8686d..e0c5a9d 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
@@ -60,8 +60,9 @@ public interface CatalogStore extends Closeable {
   
   List<String> getAllTableNames(String databaseName) throws CatalogException;
 
+  void alterTable(CatalogProtos.AlterTableDescProto alterTableDescProto) throws CatalogException;
 
-  /************************ PARTITION METHOD **************************/
+    /************************ PARTITION METHOD **************************/
   void addPartitionMethod(PartitionMethodProto partitionMethodProto) throws CatalogException;
 
   PartitionMethodProto getPartitionMethod(String databaseName, String tableName)

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/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 ef98ee2..ca29a6b 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
@@ -23,6 +23,8 @@ package org.apache.tajo.catalog.store;
 
 import com.google.common.collect.Maps;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.tajo.TajoConstants;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.FunctionDesc;
 import org.apache.tajo.catalog.exception.*;
@@ -42,11 +44,11 @@ public class MemStore implements CatalogStore {
   private final Map<String, CatalogProtos.FunctionDescProto> functions = Maps.newHashMap();
   private final Map<String, Map<String, IndexDescProto>> indexes = Maps.newHashMap();
   private final Map<String, Map<String, IndexDescProto>> indexesByColumn = Maps.newHashMap();
-  
+
   public MemStore(Configuration conf) {
   }
 
-  @Override
+  
   public void close() throws IOException {
     databases.clear();
     functions.clear();
@@ -157,6 +159,74 @@ public class MemStore implements CatalogStore {
   }
 
   /* (non-Javadoc)
+   * @see CatalogStore#alterTable(AlterTableDesc)
+   */
+  @Override
+  public void alterTable(CatalogProtos.AlterTableDescProto alterTableDescProto) throws CatalogException {
+
+    String[] split = CatalogUtil.splitTableName(alterTableDescProto.getTableName());
+    if (split.length == 1) {
+      throw new IllegalArgumentException("alterTable() requires a qualified table name, but it is \""
+          + alterTableDescProto.getTableName() + "\".");
+    }
+    String databaseName = split[0];
+    String tableName = split[1];
+
+    final Map<String, CatalogProtos.TableDescProto> database = checkAndGetDatabaseNS(databases, databaseName);
+
+    final CatalogProtos.TableDescProto tableDescProto = database.get(tableName);
+    CatalogProtos.TableDescProto newTableDescProto;
+    CatalogProtos.SchemaProto schemaProto;
+
+    switch (alterTableDescProto.getAlterTableType()) {
+      case RENAME_TABLE:
+        if (database.containsKey(alterTableDescProto.getNewTableName())) {
+          throw new AlreadyExistsTableException(alterTableDescProto.getNewTableName());
+        }
+        // Currently, we only use the default table space (i.e., WAREHOUSE directory).
+        String spaceUri = tablespaces.get(TajoConstants.DEFAULT_TABLESPACE_NAME);
+        // Create a new table directory.
+        String newPath = new Path(spaceUri, new Path(databaseName, alterTableDescProto.getNewTableName())).toString();
+        newTableDescProto = tableDescProto.toBuilder()
+            .setTableName(alterTableDescProto.getNewTableName())
+            .setPath(newPath).build();
+        database.remove(tableName);
+        database.put(alterTableDescProto.getNewTableName(), newTableDescProto);
+        break;
+      case RENAME_COLUMN:
+        schemaProto = tableDescProto.getSchema();
+        final int index = getIndexOfColumnToBeRenamed(schemaProto.getFieldsList(),
+            alterTableDescProto.getAlterColumnName().getOldColumnName());
+        final CatalogProtos.ColumnProto columnProto = schemaProto.getFields(index);
+        final CatalogProtos.ColumnProto newcolumnProto =
+            columnProto.toBuilder().setName(alterTableDescProto.getAlterColumnName().getNewColumnName()).build();
+        newTableDescProto = tableDescProto.toBuilder().setSchema(schemaProto.toBuilder().
+            setFields(index, newcolumnProto).build()).build();
+        database.put(tableName, newTableDescProto);
+        break;
+      case ADD_COLUMN:
+        schemaProto = tableDescProto.getSchema();
+        CatalogProtos.SchemaProto newSchemaProto =
+            schemaProto.toBuilder().addFields(alterTableDescProto.getAddColumn()).build();
+        newTableDescProto = tableDescProto.toBuilder().setSchema(newSchemaProto).build();
+        database.put(tableName, newTableDescProto);
+        break;
+      default:
+        //TODO
+    }
+  }
+
+  private int getIndexOfColumnToBeRenamed(List<CatalogProtos.ColumnProto> fieldList, String columnName) {
+    int fieldCount = fieldList.size();
+    for (int index = 0; index < fieldCount; index++) {
+      CatalogProtos.ColumnProto columnProto = fieldList.get(index);
+      if (null != columnProto && columnProto.getName().equalsIgnoreCase(columnName)) {
+        return index;
+      }
+    }
+    return -1;
+  }
+  /* (non-Javadoc)
    * @see CatalogStore#getTable(java.lang.String)
    */
   @Override

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/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 36c6b6b..22ab552 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
@@ -667,4 +667,53 @@ public class TestCatalog {
     catalog.dropTable(tableName);
     assertFalse(catalog.existsTable(tableName));
   }
+
+  @Test
+  public void testAlterTableName () throws Exception {
+
+    //CREATE_TABLE
+    TableDesc tableRenameTestDesc = createMockupTable("default", "mycooltable") ;
+    catalog.createTable(tableRenameTestDesc);
+
+    //RENAME_TABLE
+    catalog.alterTable(createMockAlterTableName());
+    assertTrue(catalog.existsTable("default", "mynewcooltable"));
+
+    //RENAME_COLUMN
+    catalog.alterTable(createMockAlterTableRenameColumn());
+    TableDesc columnRenameDesc = catalog.getTableDesc("default","mynewcooltable");
+    assertTrue(columnRenameDesc.getSchema().containsByName("ren"+FieldName1));
+
+    //ADD_COLUMN
+    catalog.alterTable(createMockAlterTableAddColumn());
+    TableDesc addColumnDesc = catalog.getTableDesc("default","mynewcooltable");
+    assertTrue(addColumnDesc.getSchema().containsByName("mynewcol"));
+
+  }
+
+  private AlterTableDesc createMockAlterTableName(){
+    AlterTableDesc alterTableDesc = new AlterTableDesc();
+    alterTableDesc.setTableName("default.mycooltable");
+    alterTableDesc.setNewTableName("mynewcooltable");
+    alterTableDesc.setAlterTableType(AlterTableType.RENAME_TABLE);
+    return alterTableDesc;
+  }
+
+  private AlterTableDesc createMockAlterTableRenameColumn(){
+    AlterTableDesc alterTableDesc = new AlterTableDesc();
+    alterTableDesc.setTableName("default.mynewcooltable");
+    alterTableDesc.setColumnName(FieldName1);
+    alterTableDesc.setNewColumnName("ren" + FieldName1);
+    alterTableDesc.setAlterTableType(AlterTableType.RENAME_COLUMN);
+    return alterTableDesc;
+  }
+
+  private AlterTableDesc createMockAlterTableAddColumn(){
+    AlterTableDesc alterTableDesc = new AlterTableDesc();
+    alterTableDesc.setTableName("default.mynewcooltable");
+    alterTableDesc.setAddColumn(new Column("mynewcol", Type.TEXT));
+    alterTableDesc.setAlterTableType(AlterTableType.ADD_COLUMN);
+    return alterTableDesc;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLLexer.g4
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLLexer.g4 b/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLLexer.g4
index 6eccd12..3b8f9cf 100644
--- a/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLLexer.g4
+++ b/tajo-core/tajo-core-backend/src/main/antlr4/org/apache/tajo/engine/parser/SQLLexer.g4
@@ -121,6 +121,7 @@ ANY : A N Y;
 ASYMMETRIC : A S Y M M E T R I C;
 ASC : A S C;
 
+
 BOTH : B O T H;
 
 CASE : C A S E;
@@ -189,6 +190,8 @@ WITH : W I T H;
 ===============================================================================
 */
 AVG : A V G;
+ADD: A D D;
+ALTER : A L T E R;
 
 BETWEEN : B E T W E E N;
 BY : B Y;
@@ -263,6 +266,7 @@ RANGE : R A N G E;
 REGEXP : R E G E X P;
 RLIKE : R L I K E;
 ROLLUP : R O L L U P;
+RENAME : R E N A M E;
 
 SECOND : S E C O N D;
 SET : S E T;

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/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 c0edf09..825969a 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
@@ -58,6 +58,7 @@ schema_statement
   | drop_database_statement
   | create_table_statement
   | drop_table_statement
+  | alter_table_statement
   ;
 
 index_statement
@@ -1059,6 +1060,10 @@ table_name
   : identifier (DOT identifier ( DOT identifier)? )?
   ;
 
+column_name
+  : identifier
+  ;
+
 query_specification
   : SELECT set_qualifier? select_list table_expression?
   ;
@@ -1366,3 +1371,15 @@ insert_statement
   : INSERT (OVERWRITE)? INTO table_name (LEFT_PAREN column_name_list RIGHT_PAREN)? query_expression
   | INSERT (OVERWRITE)? INTO LOCATION path=Character_String_Literal (USING file_type=identifier (param_clause)?)? query_expression
   ;
+
+/*
+===============================================================================
+  <alter table>
+===============================================================================
+*/
+
+alter_table_statement
+  : ALTER TABLE table_name RENAME TO table_name
+  | ALTER TABLE table_name RENAME COLUMN column_name TO column_name
+  | ALTER TABLE table_name ADD COLUMN field_element
+  ;

http://git-wip-us.apache.org/repos/asf/tajo/blob/f75c2e59/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/HiveQLAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/HiveQLAnalyzer.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/HiveQLAnalyzer.java
index afd0ce9..c734583 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/HiveQLAnalyzer.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/parser/HiveQLAnalyzer.java
@@ -1450,7 +1450,7 @@ public class HiveQLAnalyzer extends HiveQLParserBaseVisitor<Expr> {
       if (ctx.columnNameTypeList() != null) {
         List<HiveQLParser.ColumnNameTypeContext> list = ctx.columnNameTypeList().columnNameType();
 
-        CreateTable.ColumnDefinition[] columns = new CreateTable.ColumnDefinition[list.size()];
+        ColumnDefinition[] columns = new ColumnDefinition[list.size()];
 
         for (int i = 0; i < list.size(); i++) {
           HiveQLParser.ColumnNameTypeContext eachColumn = list.get(i);
@@ -1459,7 +1459,7 @@ public class HiveQLAnalyzer extends HiveQLParserBaseVisitor<Expr> {
             if (eachColumn.colType().type().primitiveType() != null) {
               HiveQLParser.PrimitiveTypeContext primitiveType = eachColumn.colType().type().primitiveType();
               type = getDataTypeExpr(primitiveType).getTypeName();
-              columns[i] = new CreateTable.ColumnDefinition(eachColumn.colName.Identifier().getText(), type);
+              columns[i] = new ColumnDefinition(eachColumn.colName.Identifier().getText(), type);
             }
           }
         }


Mime
View raw message