tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [13/13] git commit: TAJO-87: Integration of tajo algebra module and SQL parser
Date Mon, 29 Jul 2013 04:03:42 GMT
TAJO-87: Integration of tajo algebra module and SQL parser


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

Branch: refs/heads/master
Commit: 00c3ee2bdb9dd047485ab6ec52cd2284f0b1980a
Parents: ed25aa8
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Fri Jul 26 18:33:54 2013 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Mon Jul 29 12:01:11 2013 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |    2 +
 pom.xml                                         |    7 +-
 .../org/apache/tajo/algebra/Aggregation.java    |   24 +-
 .../org/apache/tajo/algebra/BinaryOperator.java |    8 +-
 .../org/apache/tajo/algebra/CaseWhenExpr.java   |   88 --
 .../apache/tajo/algebra/CaseWhenPredicate.java  |   89 ++
 .../tajo/algebra/ColumnReferenceExpr.java       |   34 +-
 .../tajo/algebra/CountRowsFunctionExpr.java     |   21 +
 .../tajo/algebra/CountValueFunctionExpr.java    |   21 +
 .../org/apache/tajo/algebra/CreateTable.java    |   71 +-
 .../java/org/apache/tajo/algebra/DropTable.java |   41 +
 .../main/java/org/apache/tajo/algebra/Expr.java |   34 +-
 .../java/org/apache/tajo/algebra/ExprType.java  |   99 --
 .../org/apache/tajo/algebra/ExprVisitor.java    |   19 +
 .../org/apache/tajo/algebra/FunctionExpr.java   |   32 +-
 .../java/org/apache/tajo/algebra/Having.java    |   56 +
 .../org/apache/tajo/algebra/InPredicate.java    |   34 +
 .../apache/tajo/algebra/IsNullPredicate.java    |   44 +
 .../main/java/org/apache/tajo/algebra/Join.java |   44 +-
 .../org/apache/tajo/algebra/JsonHelper.java     |    2 +-
 .../java/org/apache/tajo/algebra/LikeExpr.java  |   51 -
 .../org/apache/tajo/algebra/LikePredicate.java  |   51 +
 .../java/org/apache/tajo/algebra/Limit.java     |   12 +-
 .../org/apache/tajo/algebra/LiteralExpr.java    |   53 -
 .../org/apache/tajo/algebra/LiteralValue.java   |   53 +
 .../java/org/apache/tajo/algebra/NotExpr.java   |   31 +
 .../java/org/apache/tajo/algebra/NullValue.java |   31 +
 .../java/org/apache/tajo/algebra/OpType.java    |  117 ++
 .../org/apache/tajo/algebra/Projection.java     |   20 +-
 .../java/org/apache/tajo/algebra/Relation.java  |   18 +-
 .../org/apache/tajo/algebra/RelationList.java   |   62 +
 .../org/apache/tajo/algebra/ScalarSubQuery.java |    3 +-
 .../java/org/apache/tajo/algebra/Selection.java |   17 +-
 .../org/apache/tajo/algebra/SetOperation.java   |    9 +-
 .../main/java/org/apache/tajo/algebra/Sort.java |   26 +-
 .../org/apache/tajo/algebra/TableSubQuery.java  |   15 +-
 .../java/org/apache/tajo/algebra/Target.java    |   15 +-
 .../org/apache/tajo/algebra/UnaryOperator.java  |    6 +-
 .../org/apache/tajo/algebra/ValueListExpr.java  |   40 +
 .../java/org/apache/tajo/algebra/TestExpr.java  |   86 +-
 .../java/org/apache/tajo/catalog/Options.java   |    6 +
 .../java/org/apache/tajo/catalog/Schema.java    |    2 +-
 .../org/apache/tajo/catalog/CatalogServer.java  |   10 +-
 .../apache/tajo/annotation/NotThreadSafe.java   |   30 +
 .../org/apache/tajo/annotation/ThreadSafe.java  |   30 +
 .../main/java/org/apache/tajo/util/TUtil.java   |   33 +-
 tajo-core/tajo-core-backend/pom.xml             |   20 +-
 .../org/apache/tajo/engine/parser/SQLLexer.g    |  391 -----
 .../org/apache/tajo/engine/parser/SQLParser.g   |  789 ----------
 .../org/apache/tajo/engine/parser/SQLLexer.g4   |  367 +++++
 .../org/apache/tajo/engine/parser/SQLParser.g4  |  788 ++++++++++
 .../java/org/apache/tajo/benchmark/TPCH.java    |    2 +-
 .../java/org/apache/tajo/client/TajoClient.java |   21 +-
 .../apache/tajo/engine/eval/EvalTreeUtil.java   |   46 +-
 .../engine/exception/NTAQueryException.java     |   42 -
 .../engine/function/builtin/CountValue.java     |    5 +-
 .../tajo/engine/json/FromTableDeserializer.java |    2 +-
 .../apache/tajo/engine/parser/CommandType.java  |   41 -
 .../org/apache/tajo/engine/parser/CopyStmt.java |   72 -
 .../tajo/engine/parser/CreateIndexStmt.java     |  107 --
 .../tajo/engine/parser/CreateTableStmt.java     |  134 --
 .../tajo/engine/parser/DropTableStmt.java       |   34 -
 .../apache/tajo/engine/parser/ParseTree.java    |   63 -
 .../apache/tajo/engine/parser/ParseUtil.java    |   76 -
 .../tajo/engine/parser/ParserException.java     |   54 -
 .../tajo/engine/parser/QueryAnalyzer.java       | 1347 ------------------
 .../apache/tajo/engine/parser/QueryBlock.java   |  586 --------
 .../apache/tajo/engine/parser/SQLAnalyzer.java  |  900 ++++++++++++
 .../org/apache/tajo/engine/parser/SetStmt.java  |   60 -
 .../tajo/engine/parser/StatementType.java       |   53 -
 .../org/apache/tajo/engine/parser/TableMap.java |   68 -
 .../apache/tajo/engine/planner/FromTable.java   |  105 ++
 .../tajo/engine/planner/GroupElement.java       |   65 +
 .../apache/tajo/engine/planner/JoinClause.java  |  126 ++
 .../apache/tajo/engine/planner/JoinType.java    |   28 -
 .../tajo/engine/planner/LogicalOptimizer.java   |  754 ++++------
 .../apache/tajo/engine/planner/LogicalPlan.java |  564 ++++++++
 .../tajo/engine/planner/LogicalPlanner.java     | 1333 ++++++++++-------
 .../engine/planner/NoSuchColumnException.java   |   25 +
 .../engine/planner/PhysicalPlannerImpl.java     |   13 -
 .../apache/tajo/engine/planner/PlannerUtil.java |  206 ++-
 .../tajo/engine/planner/PlanningContext.java    |   40 -
 .../engine/planner/PlanningContextImpl.java     |   94 --
 .../apache/tajo/engine/planner/Projector.java   |    3 -
 .../org/apache/tajo/engine/planner/Target.java  |  115 ++
 .../tajo/engine/planner/TargetListManager.java  |  168 +++
 .../tajo/engine/planner/VerifyException.java    |   25 +
 .../engine/planner/logical/CreateTableNode.java |    2 +-
 .../engine/planner/logical/DropTableNode.java   |   71 +
 .../engine/planner/logical/EvalExprNode.java    |   27 +-
 .../tajo/engine/planner/logical/ExprType.java   |    3 +-
 .../engine/planner/logical/GroupbyNode.java     |   29 +-
 .../engine/planner/logical/IndexWriteNode.java  |   95 --
 .../tajo/engine/planner/logical/JoinNode.java   |   43 +-
 .../tajo/engine/planner/logical/LimitNode.java  |   25 +-
 .../engine/planner/logical/LogicalNode.java     |   12 +-
 .../engine/planner/logical/Projectable.java     |   27 +
 .../engine/planner/logical/ProjectionNode.java  |   24 +-
 .../tajo/engine/planner/logical/ScanNode.java   |   33 +-
 .../planner/physical/AggregationExec.java       |    4 +-
 .../engine/planner/physical/BNLJoinExec.java    |    4 +-
 .../engine/planner/physical/EvalExprExec.java   |    2 +-
 .../engine/planner/physical/IndexWriteExec.java |   88 --
 .../engine/planner/physical/NLJoinExec.java     |    4 +
 .../apache/tajo/engine/utils/SchemaUtil.java    |   33 +-
 .../org/apache/tajo/master/ClientService.java   |    7 +-
 .../org/apache/tajo/master/ExecutionBlock.java  |    6 +-
 .../org/apache/tajo/master/GlobalEngine.java    |   82 +-
 .../org/apache/tajo/master/GlobalPlanner.java   |   42 +-
 .../apache/tajo/master/GlobalPlannerUtils.java  |  164 +--
 .../main/java/org/apache/tajo/master/Query.java |   29 +-
 .../java/org/apache/tajo/master/QueryUnit.java  |    7 +-
 .../org/apache/tajo/BackendTestingUtil.java     |   17 +-
 .../org/apache/tajo/benchmark/TestTPCH.java     |    8 +-
 .../apache/tajo/engine/eval/TestEvalTree.java   |   75 +-
 .../tajo/engine/eval/TestEvalTreeUtil.java      |   99 +-
 .../tajo/engine/parser/TestQueryAnalyzer.java   |  653 ---------
 .../tajo/engine/parser/TestSQLAnalyzer.java     |  297 ++++
 .../tajo/engine/parser/TestSQLParser.java       |  993 -------------
 .../plan/global/TestGlobalQueryPlanner.java     |   84 +-
 .../engine/planner/TestLogicalOptimizer.java    |   60 +-
 .../tajo/engine/planner/TestLogicalPlanner.java |  448 +++---
 .../tajo/engine/planner/TestPlannerUtil.java    |   25 +-
 .../global/TestGlobalQueryOptimizer.java        |   26 +-
 .../planner/physical/TestBNLJoinExec.java       |   32 +-
 .../planner/physical/TestBSTIndexExec.java      |   21 +-
 .../planner/physical/TestExternalSortExec.java  |   25 +-
 .../planner/physical/TestHashJoinExec.java      |   22 +-
 .../planner/physical/TestMergeJoinExec.java     |   18 +-
 .../engine/planner/physical/TestNLJoinExec.java |   21 +-
 .../planner/physical/TestPhysicalPlanner.java   |  295 ++--
 .../engine/planner/physical/TestSortExec.java   |   23 +-
 .../apache/tajo/engine/query/TestJoinQuery.java |   10 +-
 .../tajo/engine/query/TestSelectQuery.java      |   18 +-
 .../apache/tajo/engine/query/TestSortQuery.java |   19 +
 .../tajo/master/TestExecutionBlockCursor.java   |   21 +-
 .../tajo/worker/TestRangeRetrieverHandler.java  |   23 +-
 .../src/test/queries/create_table_1.sql         |    1 +
 .../src/test/queries/create_table_10.sql        |    1 +
 .../src/test/queries/create_table_2.sql         |    1 +
 .../src/test/queries/create_table_3.sql         |    1 +
 .../src/test/queries/create_table_4.sql         |    1 +
 .../src/test/queries/create_table_5.sql         |    1 +
 .../src/test/queries/create_table_6.sql         |    1 +
 .../src/test/queries/create_table_7.sql         |    1 +
 .../src/test/queries/create_table_8.sql         |   48 +
 .../src/test/queries/create_table_9.sql         |    1 +
 .../src/test/queries/drop_table.sql             |    1 +
 .../src/test/queries/groupby_1.sql              |    1 +
 .../src/test/queries/insert_1.sql               |    1 +
 .../src/test/queries/insert_2.sql               |    1 +
 .../src/test/queries/join_1.sql                 |    1 +
 .../src/test/queries/join_10.sql                |    1 +
 .../src/test/queries/join_11.sql                |    1 +
 .../src/test/queries/join_2.sql                 |    1 +
 .../src/test/queries/join_3.sql                 |    1 +
 .../src/test/queries/join_4.sql                 |    1 +
 .../src/test/queries/join_5.sql                 |    1 +
 .../src/test/queries/join_6.sql                 |    1 +
 .../src/test/queries/join_7.sql                 |    1 +
 .../src/test/queries/join_8.sql                 |   13 +
 .../src/test/queries/join_9.sql                 |    5 +
 .../src/test/queries/select_1.sql               |    1 +
 .../src/test/queries/select_2.sql               |    1 +
 .../src/test/queries/select_3.sql               |    1 +
 .../src/test/queries/select_4.sql               |    1 +
 .../src/test/queries/select_5.sql               |    1 +
 .../src/test/queries/select_6.sql               |    1 +
 .../src/test/queries/select_7.sql               |    1 +
 .../src/test/queries/select_8.sql               |    1 +
 .../src/test/queries/set_1.sql                  |    1 +
 .../src/test/queries/set_2.sql                  |    1 +
 .../src/test/queries/set_3.sql                  |    1 +
 tajo-core/tajo-core-storage/pom.xml             |   11 -
 tajo-frontend/pom.xml                           |  149 --
 tajo-frontend/tajo-frontend-sql/pom.xml         |  187 ---
 .../main/antlr3/tajo/frontend/sql/SQLLexer.g    | 1152 ---------------
 .../main/antlr3/tajo/frontend/sql/SQLParser.g   |  956 -------------
 .../apache/tajo/frontend/sql/QueryBlock.java    |  133 --
 .../apache/tajo/frontend/sql/SQLAnalyzer.java   |  932 ------------
 .../apache/tajo/frontend/sql/SQLParseError.java |   27 -
 .../tajo/frontend/sql/SQLSyntaxError.java       |   45 -
 .../tajo/frontend/sql/TestSQLAnalyzer.java      |  572 --------
 .../apache/tajo/frontend/sql/TestSQLParser.java |  914 ------------
 tajo-project/pom.xml                            |   12 +-
 185 files changed, 7106 insertions(+), 13608 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 988324e..2c984ea 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -12,6 +12,8 @@ Release 0.2.0 - unreleased
 
   IMPROVEMENTS
 
+    TAJO-87: Integration of tajo algebra module and SQL parser. (hyunsik)
+
     TAJO-70: Refactor GlobalEngine to handle DDL statements. (hyunsik)
 
     TAJO-86: Improved error messages in query analyzer. (jinho)

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 604ff83..e1e7b7d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -80,7 +80,6 @@
     <module>tajo-project</module>
     <module>tajo-common</module>
     <module>tajo-algebra</module>
-    <module>tajo-frontend</module>
     <module>tajo-core</module>
     <module>tajo-rpc</module>
     <module>tajo-catalog</module>
@@ -249,11 +248,6 @@
             </lifecycleMappingMetadata>
           </configuration>
         </plugin>
-        <plugin>
-          <groupId>org.antlr</groupId>
-          <artifactId>antlr3-maven-plugin</artifactId>
-          <version>3.4</version>
-        </plugin>
       </plugins>
     </pluginManagement>
 
@@ -304,6 +298,7 @@
           <excludes>
             <exclude>CHANGES.txt</exclude>
             <exclude>**/*.tql</exclude>
+            <exclude>**/*.sql</exclude>
             <exclude>**/*.schema</exclude>
             <exclude>**/*.tbl</exclude>
             <!-- generated content -->

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Aggregation.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Aggregation.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Aggregation.java
index a70956b..eccb873 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Aggregation.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Aggregation.java
@@ -21,19 +21,19 @@ package org.apache.tajo.algebra;
 import org.apache.tajo.util.TUtil;
 
 public class Aggregation extends UnaryOperator {
-  private Target [] targets;
+  private Target[] targets;
   private GroupElement [] groups;
   private Expr havingCondition;
 
   public Aggregation() {
-    super(ExprType.Aggregation);
+    super(OpType.Aggregation);
   }
 
-  public Target [] getTargets() {
+  public Target[] getTargets() {
     return this.targets;
   }
 
-  public void setTargets(Target [] targets) {
+  public void setTargets(Target[] targets) {
     this.targets = targets;
   }
 
@@ -109,8 +109,18 @@ public class Aggregation extends UnaryOperator {
   }
 
   public static enum GroupType {
-    GROUPBY,
-    CUBE,
-    ROLLUP
+    OrdinaryGroup(""),
+    Cube("Cube"),
+    Rollup("Rollup"),
+    EmptySet("()");
+
+    String displayName;
+    GroupType(String displayName) {
+      this.displayName = displayName;
+    }
+
+    public String toString() {
+      return displayName;
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/BinaryOperator.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/BinaryOperator.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/BinaryOperator.java
index 1883df2..3e00e5e 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/BinaryOperator.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/BinaryOperator.java
@@ -19,14 +19,14 @@
 package org.apache.tajo.algebra;
 
 public class BinaryOperator extends Expr {
-  Expr left;
-  Expr right;
+  protected Expr left;
+  protected Expr right;
 
-  BinaryOperator(ExprType opType) {
+  BinaryOperator(OpType opType) {
     super(opType);
   }
 
-  public BinaryOperator(ExprType type, Expr left, Expr right) {
+  public BinaryOperator(OpType type, Expr left, Expr right) {
     super(type);
     this.left = left;
     this.right = right;

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CaseWhenExpr.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/CaseWhenExpr.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CaseWhenExpr.java
deleted file mode 100644
index 5e95b8a..0000000
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/CaseWhenExpr.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- * 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 java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-public class CaseWhenExpr extends Expr {
-  private List<WhenExpr> whens = new ArrayList<WhenExpr>();
-  private Expr else_result;
-
-  public CaseWhenExpr() {
-    super(ExprType.CaseWhen);
-  }
-
-  public void addWhen(Expr condition, Expr result) {
-    whens.add(new WhenExpr(condition, result));
-  }
-
-  public Collection<WhenExpr> getWhens() {
-    return this.whens;
-  }
-
-  public void setElseResult(Expr else_result) {
-    this.else_result = else_result;
-  }
-
-  public Object getElseResult() {
-    return this.else_result;
-  }
-
-  public boolean hasElseResult() {
-    return else_result != null;
-  }
-
-  @Override
-  boolean equalsTo(Expr expr) {
-    return false;
-  }
-
-  @Override
-  public String toJson() {
-    return JsonHelper.toJson(this);
-  }
-
-  public static class WhenExpr {
-    Expr condition;
-    Expr result;
-
-    public WhenExpr(Expr condition, Expr result) {
-      this.condition = condition;
-      this.result = result;
-    }
-
-    public Expr getCondition() {
-      return this.condition;
-    }
-
-    public Expr getResult() {
-      return this.result;
-    }
-
-    public boolean equals(Object obj) {
-      if (obj instanceof WhenExpr) {
-        WhenExpr another = (WhenExpr) obj;
-      }
-
-      return false;
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CaseWhenPredicate.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/CaseWhenPredicate.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CaseWhenPredicate.java
new file mode 100644
index 0000000..398aa55
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CaseWhenPredicate.java
@@ -0,0 +1,89 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class CaseWhenPredicate extends Expr {
+  private List<WhenExpr> whens = new ArrayList<WhenExpr>();
+  private Expr elseResult;
+
+  public CaseWhenPredicate() {
+    super(OpType.CaseWhen);
+  }
+
+  public void addWhen(Expr condition, Expr result) {
+    whens.add(new WhenExpr(condition, result));
+  }
+
+  public Collection<WhenExpr> getWhens() {
+    return this.whens;
+  }
+
+  public void setElseResult(Expr elseResult) {
+    this.elseResult = elseResult;
+  }
+
+  public Expr getElseResult() {
+    return this.elseResult;
+  }
+
+  public boolean hasElseResult() {
+    return elseResult != null;
+  }
+
+  @Override
+  boolean equalsTo(Expr expr) {
+    return false;
+  }
+
+  @Override
+  public String toJson() {
+    return JsonHelper.toJson(this);
+  }
+
+  public static class WhenExpr {
+    Expr condition;
+    Expr result;
+
+    public WhenExpr(Expr condition, Expr result) {
+      this.condition = condition;
+      this.result = result;
+    }
+
+    public Expr getCondition() {
+      return this.condition;
+    }
+
+    public Expr getResult() {
+      return this.result;
+    }
+
+    public boolean equals(Object obj) {
+      if (obj instanceof WhenExpr) {
+        WhenExpr another = (WhenExpr) obj;
+        return condition.equals(another.condition) && result.equals(result);
+      }
+
+      return false;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java
index 888404d..dfc2584 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ColumnReferenceExpr.java
@@ -21,29 +21,41 @@ package org.apache.tajo.algebra;
 import org.apache.tajo.util.TUtil;
 
 public class ColumnReferenceExpr extends Expr {
-  private String rel_name;
-  private String column_name;
+  private String tableName;
+  private String name;
 
   public ColumnReferenceExpr(String columnName) {
-    super(ExprType.Column);
-    this.column_name = columnName;
+    super(OpType.Column);
+    this.name = columnName;
   }
 
-  public void setRelationName(String tableName) {
-    this.rel_name = tableName;
+  public void setTableName(String tableName) {
+    this.tableName = tableName;
   }
 
   public String getName() {
-    return this.column_name;
+    return this.name;
   }
 
-  public String getRelationName() {
-    return this.rel_name;
+  public boolean hasTableName() {
+    return this.tableName != null;
+  }
+
+  public String getTableName() {
+    return this.tableName;
+  }
+
+  public String getCanonicalName() {
+    if (tableName != null) {
+      return tableName + "." + name;
+    } else {
+      return name;
+    }
   }
 
   public boolean equalsTo(Expr expr) {
     ColumnReferenceExpr another = (ColumnReferenceExpr) expr;
-    return column_name.equals(another.column_name) &&
-        TUtil.checkEquals(rel_name, another.rel_name);
+    return name.equals(another.name) &&
+        TUtil.checkEquals(tableName, another.tableName);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CountRowsFunctionExpr.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/CountRowsFunctionExpr.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CountRowsFunctionExpr.java
new file mode 100644
index 0000000..77468fb
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CountRowsFunctionExpr.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed 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 CountRowsFunctionExpr extends FunctionExpr {
+  public CountRowsFunctionExpr() {
+    super(OpType.CountRowsFunction, "count");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CountValueFunctionExpr.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/CountValueFunctionExpr.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CountValueFunctionExpr.java
new file mode 100644
index 0000000..80c527b
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/CountValueFunctionExpr.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed 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 CountValueFunctionExpr extends FunctionExpr {
+  public CountValueFunctionExpr(Expr param) {
+    super(OpType.CountValueFunction, "count", new Expr[] {param});
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/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 92404ee..1552467 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
@@ -23,25 +23,34 @@ import org.apache.tajo.util.TUtil;
 import java.util.Map;
 
 public class CreateTable extends Expr {
-  private String rel_name;
-  private ColumnDefinition [] table_elements;
-  private String storage_type;
+  private boolean external = false;
+  private String tableName;
+  private ColumnDefinition [] tableElements;
+  private String storageType;
   private String location;
   private Expr subquery;
   private Map<String, String> params;
 
   public CreateTable(final String tableName) {
-    super(ExprType.CreateTable);
-    this.rel_name = tableName;
+    super(OpType.CreateTable);
+    this.tableName = tableName;
   }
 
-  public CreateTable(final String relationName, final Expr subQuery) {
-    this(relationName);
+  public CreateTable(final String tableName, final Expr subQuery) {
+    this(tableName);
     this.subquery = subQuery;
   }
 
-  public String getRelationName() {
-    return this.rel_name;
+  public void setExternal() {
+    external = true;
+  }
+
+  public boolean isExternal() {
+    return external;
+  }
+
+  public String getTableName() {
+    return this.tableName;
   }
 
   public boolean hasLocation() {
@@ -57,27 +66,27 @@ public class CreateTable extends Expr {
   }
 
   public boolean hasTableElements() {
-    return this.table_elements != null;
+    return this.tableElements != null;
   }
 
   public ColumnDefinition [] getTableElements() {
-    return table_elements;
+    return tableElements;
   }
 
   public void setTableElements(ColumnDefinition [] tableElements) {
-    this.table_elements = tableElements;
+    this.tableElements = tableElements;
   }
 
   public boolean hasStorageType() {
-    return storage_type != null;
+    return storageType != null;
   }
 
   public void setStorageType(String storageType) {
-    this.storage_type = storageType;
+    this.storageType = storageType;
   }
 
   public String getStorageType() {
-    return storage_type;
+    return storageType;
   }
 
   public boolean hasParams() {
@@ -96,6 +105,10 @@ public class CreateTable extends Expr {
     return subquery != null;
   }
 
+  public void setSubQuery(Expr subquery) {
+    this.subquery = subquery;
+  }
+
   public Expr getSubQuery() {
     return subquery;
   }
@@ -103,9 +116,9 @@ public class CreateTable extends Expr {
   @Override
   boolean equalsTo(Expr expr) {
     CreateTable another = (CreateTable) expr;
-    return rel_name.equals(another.rel_name) &&
-        TUtil.checkEquals(table_elements, another.table_elements) &&
-        TUtil.checkEquals(storage_type, another.storage_type) &&
+    return tableName.equals(another.tableName) &&
+        TUtil.checkEquals(tableElements, another.tableElements) &&
+        TUtil.checkEquals(storageType, another.storageType) &&
         TUtil.checkEquals(location, another.location) &&
         TUtil.checkEquals(subquery, another.subquery) &&
         TUtil.checkEquals(params, another.params);
@@ -114,6 +127,8 @@ public class CreateTable extends Expr {
   public static class ColumnDefinition {
     String col_name;
     String data_type;
+    Integer length_or_precision;
+    Integer scale;
 
     public ColumnDefinition(String columnName, String dataType) {
       this.col_name = columnName;
@@ -128,10 +143,28 @@ public class CreateTable extends Expr {
       return this.data_type;
     }
 
+    public void setLengthOrPrecision(int lengthOrPrecision) {
+      this.length_or_precision = lengthOrPrecision;
+    }
+
+    public Integer getLengthOrPrecision() {
+      return this.length_or_precision;
+    }
+
+    public void setScale(int scale) {
+      this.scale = scale;
+    }
+
+    public Integer getScale() {
+      return this.scale;
+    }
+
     public boolean equals(Object obj) {
       if (obj instanceof ColumnDefinition) {
         ColumnDefinition another = (ColumnDefinition) obj;
-        return col_name.equals(another.col_name) && data_type.equals(another.data_type);
+        return col_name.equals(another.col_name) && data_type.equals(another.data_type) &&
+            TUtil.checkEquals(length_or_precision, another.length_or_precision) &&
+            TUtil.checkEquals(scale, another.scale);
       }
 
       return false;

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/DropTable.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/DropTable.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/DropTable.java
new file mode 100644
index 0000000..9544cf3
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/DropTable.java
@@ -0,0 +1,41 @@
+/**
+ * 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 DropTable extends Expr {
+  private final String tableName;
+
+  public DropTable(String tableName) {
+    super(OpType.DropTable);
+    this.tableName = tableName;
+  }
+
+  public String getTableName() {
+    return this.tableName;
+  }
+
+  @Override
+  boolean equalsTo(Expr expr) {
+    if (expr instanceof DropTable) {
+      DropTable another = (DropTable) expr;
+      return tableName.equals(another.tableName);
+    }
+    return false;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Expr.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Expr.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Expr.java
index 041ce1d..54c230b 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Expr.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Expr.java
@@ -23,14 +23,14 @@ import com.google.gson.*;
 import java.lang.reflect.Type;
 
 public abstract class Expr implements JsonSerializable {
-  protected ExprType op_type;
+  protected OpType opType;
 
-	public Expr(ExprType op_type) {
-		this.op_type = op_type;
+	public Expr(OpType opType) {
+		this.opType = opType;
 	}
 	
-	public ExprType getType() {
-		return this.op_type;
+	public OpType getType() {
+		return this.opType;
 	}
 
   abstract boolean equalsTo(Expr expr);
@@ -40,7 +40,7 @@ public abstract class Expr implements JsonSerializable {
 	  if (obj instanceof Expr) {
 	    Expr casted = (Expr) obj;
 
-      if (this.op_type == casted.op_type && equalsTo(casted)) {
+      if (this.opType == casted.opType && equalsTo(casted)) {
         if (this instanceof UnaryOperator) {
           UnaryOperator one = (UnaryOperator) this;
           UnaryOperator another = (UnaryOperator) casted;
@@ -76,6 +76,24 @@ public abstract class Expr implements JsonSerializable {
     return JsonHelper.toJson(this);
   }
 
+  /**
+   * This method provides a visiting way in the post order.
+   *
+   * @param visitor
+   */
+  public void accept(ExprVisitor visitor) {
+    if (this instanceof UnaryOperator) {
+      UnaryOperator unary = (UnaryOperator) this;
+      unary.getChild().accept(visitor);
+    } else if (this instanceof BinaryOperator) {
+      BinaryOperator bin = (BinaryOperator) this;
+      bin.getLeft().accept(visitor);
+      bin.getRight().accept(visitor);
+    }
+
+    visitor.visit(this);
+  }
+
   static class JsonSerDer
       implements JsonSerializer<Expr>, JsonDeserializer<Expr> {
 
@@ -85,14 +103,14 @@ public abstract class Expr implements JsonSerializable {
         throws JsonParseException {
       JsonObject jsonObject = json.getAsJsonObject();
       String operator = jsonObject.get("type").getAsString();
-      return context.deserialize(json, ExprType.valueOf(operator).getBaseClass());
+      return context.deserialize(json, OpType.valueOf(operator).getBaseClass());
     }
 
 
     @Override
     public JsonElement serialize(Expr src, Type typeOfSrc,
                                  JsonSerializationContext context) {
-      return context.serialize(src, src.op_type.getBaseClass());
+      return context.serialize(src, src.opType.getBaseClass());
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ExprType.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/ExprType.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ExprType.java
deleted file mode 100644
index f94e567..0000000
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/ExprType.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * 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.gson.*;
-
-import java.lang.reflect.Type;
-
-public enum ExprType {
-  // relational operators
-  Relation(Relation.class),
-  TableSubQuery(TableSubQuery.class),
-  Except(SetOperation.class),
-	Aggregation(org.apache.tajo.algebra.Aggregation.class),
-  Intersect(SetOperation.class),
-  Join(Join.class),
-  Projection(Projection.class),
-  Rename,
-  Selection(Selection.class),
-  Sort(Sort.class),
-  Union(SetOperation.class),
-  Limit(Limit.class),
-
-  // extended relational operators
-  CreateTable(CreateTable.class),
-
-  // logical operators
-  And(BinaryOperator.class),
-  Or(BinaryOperator.class),
-
-  // comparison operators
-  Equals(BinaryOperator.class),
-  NotEquals(BinaryOperator.class),
-  LessThan(BinaryOperator.class),
-  LessThanOrEquals(BinaryOperator.class),
-  GreaterThan(BinaryOperator.class),
-  GreaterThanOrEquals(BinaryOperator.class),
-
-  // arithmetic operators
-  Plus(BinaryOperator.class),
-  Minus(BinaryOperator.class),
-  Multiply(BinaryOperator.class),
-  Divide(BinaryOperator.class),
-  Mod(BinaryOperator.class),
-
-  // other expressions
-  Column(ColumnReferenceExpr.class),
-  Function(FunctionExpr.class),
-  CaseWhen(CaseWhenExpr.class),
-  Like(LikeExpr.class),
-  Literal(LiteralExpr.class),
-  ScalarSubQuery(ScalarSubQuery.class);
-
-  private Class baseClass;
-
-  ExprType() {
-    this.baseClass = Expr.class;
-  }
-  ExprType(Class clazz) {
-    this.baseClass = clazz;
-  }
-
-  public Class getBaseClass() {
-    return this.baseClass;
-  }
-
-  public static class JsonSerDer implements JsonSerializer<ExprType>,
-                                            JsonDeserializer<ExprType> {
-
-    @Override
-    public JsonElement serialize(ExprType src, Type typeOfSrc,
-                                 JsonSerializationContext context) {
-      return new JsonPrimitive(src.name());
-    }
-
-    @Override
-    public ExprType deserialize(JsonElement json, Type typeOfT,
-                                      JsonDeserializationContext context)
-        throws JsonParseException {
-      return ExprType.valueOf(json.getAsString());
-    }
-  }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ExprVisitor.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/ExprVisitor.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ExprVisitor.java
new file mode 100644
index 0000000..d05c1db
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ExprVisitor.java
@@ -0,0 +1,19 @@
+/*
+ * Licensed 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 interface ExprVisitor {
+  void visit(Expr expr);
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/FunctionExpr.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/FunctionExpr.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/FunctionExpr.java
index 3bab189..29188bf 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/FunctionExpr.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/FunctionExpr.java
@@ -25,7 +25,37 @@ public class FunctionExpr extends Expr {
   private Expr[] params;
 
   public FunctionExpr(String signature) {
-    super(ExprType.Function);
+    this(OpType.Function, signature);
+  }
+
+  public FunctionExpr(String signature, Expr [] params) {
+    this(OpType.Function, signature);
+    setParams(params);
+  }
+
+  protected FunctionExpr(OpType type, String signature) {
+    super(type);
+    if (type != OpType.Function && type != OpType.CountRowsFunction) {
+      throw new IllegalArgumentException("FunctionExpr cannot accept " + type + "type");
+    }
+    this.signature = signature;
+  }
+
+  protected FunctionExpr(OpType type, String signature, Expr [] params) {
+    super(type);
+    if (type != OpType.Function && type != OpType.CountValueFunction) {
+      throw new IllegalArgumentException("FunctionExpr cannot accept " + type + "type");
+    }
+    this.signature = signature;
+    setParams(params);
+  }
+
+  public String getSignature() {
+    return this.signature;
+  }
+
+  public Expr[] getParams() {
+    return params;
   }
 
   public void setParams(Expr[] params) {

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Having.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Having.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Having.java
new file mode 100644
index 0000000..d48537a
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Having.java
@@ -0,0 +1,56 @@
+/**
+ * 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 org.apache.tajo.util.TUtil;
+
+public class Having extends UnaryOperator implements JsonSerializable {
+  private Expr qual;
+
+  public Having(Expr qual) {
+    super(OpType.Having);
+    this.qual = qual;
+  }
+
+  public boolean hasQual() {
+    return qual != null;
+  }
+
+  public void setQual(Expr expr) {
+    this.qual = expr;
+  }
+
+	public Expr getQual() {
+		return this.qual;
+	}
+
+  @Override
+  public String toJson() {
+    return JsonHelper.toJson(this);
+  }
+
+  @Override
+  public boolean equalsTo(Expr expr) {
+    if (expr instanceof Having) {
+      Having other = (Having) expr;
+      return TUtil.checkEquals(qual, other.qual);
+    }
+    return false;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/InPredicate.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/InPredicate.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/InPredicate.java
new file mode 100644
index 0000000..abdcc86
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/InPredicate.java
@@ -0,0 +1,34 @@
+/**
+ * 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 InPredicate extends BinaryOperator {
+
+  public InPredicate(Expr predicand, Expr in_values) {
+    super(OpType.InPredicate, predicand, in_values);
+  }
+
+  public Expr getPredicand() {
+    return left;
+  }
+
+  public Expr getInValue() {
+    return right;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/IsNullPredicate.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/IsNullPredicate.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/IsNullPredicate.java
new file mode 100644
index 0000000..610a81e
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/IsNullPredicate.java
@@ -0,0 +1,44 @@
+/**
+ * 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 IsNullPredicate extends Expr {
+  private final boolean not;
+  private final ColumnReferenceExpr columnRef;
+
+  public IsNullPredicate(boolean not, ColumnReferenceExpr column) {
+    super(OpType.IsNullPredicate);
+    this.not = not;
+    this.columnRef = column;
+  }
+
+  public boolean isNot() {
+    return not;
+  }
+
+  public ColumnReferenceExpr getColumnRef() {
+    return columnRef;
+  }
+
+  @Override
+  boolean equalsTo(Expr expr) {
+    IsNullPredicate nullPredicate = (IsNullPredicate) expr;
+    return not == nullPredicate.not && columnRef.equals(nullPredicate.columnRef);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Join.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Join.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Join.java
index c2316fd..51c84c2 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Join.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Join.java
@@ -20,43 +20,45 @@ package org.apache.tajo.algebra;
 
 import org.apache.tajo.util.TUtil;
 
+import java.util.Arrays;
+
 public class Join extends BinaryOperator {
-  private JoinType join_type;
-  private Expr join_qual;
-  private ColumnReferenceExpr [] join_columns;
+  private JoinType joinType;
+  private Expr joinQual;
+  private ColumnReferenceExpr[] joinColumns;
   private boolean natural = false;
 
   public Join(JoinType joinType) {
-    super(ExprType.Join);
-    this.join_type = joinType;
+    super(OpType.Join);
+    this.joinType = joinType;
   }
 
   public JoinType getJoinType() {
-    return  this.join_type;
+    return  this.joinType;
   }
 
   public boolean hasQual() {
-    return this.join_qual != null;
+    return this.joinQual != null;
   }
 
   public Expr getQual() {
-    return this.join_qual;
+    return this.joinQual;
   }
 
   public void setQual(Expr expr) {
-    this.join_qual = expr;
+    this.joinQual = expr;
   }
 
   public boolean hasJoinColumns() {
-    return join_columns != null;
+    return joinColumns != null;
   }
 
-  public ColumnReferenceExpr [] getJoinColumns() {
-    return join_columns;
+  public ColumnReferenceExpr[] getJoinColumns() {
+    return joinColumns;
   }
 
   public void setJoinColumns(ColumnReferenceExpr[] columns) {
-    join_columns = columns;
+    joinColumns = columns;
   }
 
   public void setNatural() {
@@ -69,9 +71,9 @@ public class Join extends BinaryOperator {
 
   boolean equalsTo(Expr expr) {
     Join another = (Join) expr;
-    return join_type.equals(another.join_type) &&
-        TUtil.checkEquals(join_qual, another.join_qual) &&
-        TUtil.checkEquals(join_columns, another.join_columns) &&
+    return joinType.equals(another.joinType) &&
+        TUtil.checkEquals(joinQual, another.joinQual) &&
+        TUtil.checkEquals(joinColumns, another.joinColumns) &&
         natural == another.natural;
   }
 
@@ -79,4 +81,14 @@ public class Join extends BinaryOperator {
   public String toJson() {
     return JsonHelper.toJson(this);
   }
+
+  @Override
+  public int hashCode() {
+    int result = getType().hashCode();
+    result = 31 * result + joinType.hashCode();
+    result = 31 * result + (joinQual != null ? joinQual.hashCode() : 0);
+    result = 31 * result + (joinColumns != null ? Arrays.hashCode(joinColumns) : 0);
+    result = 31 * result + (natural ? 1 : 0);
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/JsonHelper.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/JsonHelper.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/JsonHelper.java
index 5cf0376..f05a4ea 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/JsonHelper.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/JsonHelper.java
@@ -38,7 +38,7 @@ public class JsonHelper {
 
   private void initBuilder() {
     builder = new GsonBuilder().setPrettyPrinting();
-    builder.registerTypeAdapter(ExprType.class, new ExprType.JsonSerDer());
+    builder.registerTypeAdapter(OpType.class, new OpType.JsonSerDer());
     builder.registerTypeAdapter(Expr.class, new Expr.JsonSerDer());
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/LikeExpr.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/LikeExpr.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/LikeExpr.java
deleted file mode 100644
index ac73d74..0000000
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/LikeExpr.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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 LikeExpr extends BinaryOperator {
-  private boolean not;
-  private ColumnReferenceExpr column_ref;
-  private Expr pattern;
-
-  public LikeExpr(boolean not, ColumnReferenceExpr columnReferenceExpr, Expr pattern) {
-    super(ExprType.Like);
-    this.not = not;
-    this.column_ref = columnReferenceExpr;
-    this.pattern = pattern;
-  }
-
-  public boolean isNot() {
-    return not;
-  }
-
-  public ColumnReferenceExpr getColumnRef() {
-    return this.column_ref;
-  }
-
-  public Expr getPattern() {
-    return this.pattern;
-  }
-
-  boolean equalsTo(Expr expr) {
-    LikeExpr another = (LikeExpr) expr;
-    return not == another.not &&
-        column_ref.equals(another.column_ref) &&
-        pattern.equals(another.pattern);
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/LikePredicate.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/LikePredicate.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/LikePredicate.java
new file mode 100644
index 0000000..e091df1
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/LikePredicate.java
@@ -0,0 +1,51 @@
+/**
+ * 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 LikePredicate extends Expr {
+  private boolean not;
+  private ColumnReferenceExpr columnRef;
+  private Expr pattern;
+
+  public LikePredicate(boolean not, ColumnReferenceExpr columnReferenceExpr, Expr pattern) {
+    super(OpType.LikePredicate);
+    this.not = not;
+    this.columnRef = columnReferenceExpr;
+    this.pattern = pattern;
+  }
+
+  public boolean isNot() {
+    return not;
+  }
+
+  public ColumnReferenceExpr getColumnRef() {
+    return this.columnRef;
+  }
+
+  public Expr getPattern() {
+    return this.pattern;
+  }
+
+  boolean equalsTo(Expr expr) {
+    LikePredicate another = (LikePredicate) expr;
+    return not == another.not &&
+        columnRef.equals(another.columnRef) &&
+        pattern.equals(another.pattern);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Limit.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Limit.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Limit.java
index e3ded02..dd3aee9 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Limit.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Limit.java
@@ -20,15 +20,15 @@ package org.apache.tajo.algebra;
 
 
 public class Limit extends UnaryOperator {
-  private Expr fetch_first_num;
+  private Expr fetchFirstNum;
 
-  public Limit(Expr fetch_first_num) {
-    super(ExprType.Limit);
-    this.fetch_first_num = fetch_first_num;
+  public Limit(Expr fetchFirstNum) {
+    super(OpType.Limit);
+    this.fetchFirstNum = fetchFirstNum;
   }
 
   public Expr getFetchFirstNum() {
-    return this.fetch_first_num;
+    return this.fetchFirstNum;
   }
 
   @Override
@@ -44,6 +44,6 @@ public class Limit extends UnaryOperator {
   @Override
   boolean equalsTo(Expr expr) {
     Limit another = (Limit) expr;
-    return fetch_first_num.equals(another.fetch_first_num);
+    return fetchFirstNum.equals(another.fetchFirstNum);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/LiteralExpr.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/LiteralExpr.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/LiteralExpr.java
deleted file mode 100644
index df8f4dd..0000000
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/LiteralExpr.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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 LiteralExpr extends Expr {
-  private String value;
-  private LiteralType value_type;
-
-  public static enum LiteralType {
-    String,
-    Unsigned_Integer,
-    Unsigned_Float,
-    Unsigned_Large_Integer,
-  }
-
-  public LiteralExpr(String value, LiteralType value_type) {
-    super(ExprType.Literal);
-    this.value = value;
-    this.value_type = value_type;
-  }
-
-  public String getValue() {
-    return this.value;
-  }
-
-  public LiteralType getValueType() {
-    return this.value_type;
-  }
-
-  public boolean equalsTo(Expr expr) {
-    LiteralExpr another = (LiteralExpr) expr;
-    boolean a = value_type.equals(another.value_type);
-    boolean b =  value.equals(another.value);
-
-    return a && b;
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/LiteralValue.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/LiteralValue.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/LiteralValue.java
new file mode 100644
index 0000000..02445f0
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/LiteralValue.java
@@ -0,0 +1,53 @@
+/**
+ * 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 LiteralValue extends Expr {
+  private String value;
+  private LiteralType valueType;
+
+  public static enum LiteralType {
+    String,
+    Unsigned_Integer,
+    Unsigned_Float,
+    Unsigned_Large_Integer,
+  }
+
+  public LiteralValue(String value, LiteralType valueType) {
+    super(OpType.Literal);
+    this.value = value;
+    this.valueType = valueType;
+  }
+
+  public String getValue() {
+    return this.value;
+  }
+
+  public LiteralType getValueType() {
+    return this.valueType;
+  }
+
+  public boolean equalsTo(Expr expr) {
+    LiteralValue another = (LiteralValue) expr;
+    boolean a = valueType.equals(another.valueType);
+    boolean b =  value.equals(another.value);
+
+    return a && b;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/NotExpr.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/NotExpr.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/NotExpr.java
new file mode 100644
index 0000000..aba2f0e
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/NotExpr.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.algebra;
+
+public class NotExpr extends UnaryOperator {
+  public NotExpr(Expr child) {
+    super(OpType.Not);
+    setChild(child);
+  }
+
+  @Override
+  boolean equalsTo(Expr expr) {
+    return expr instanceof NotExpr;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/NullValue.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/NullValue.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/NullValue.java
new file mode 100644
index 0000000..9be1a2f
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/NullValue.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.algebra;
+
+public class NullValue extends Expr {
+
+  public NullValue() {
+    super(OpType.Null);
+  }
+
+  @Override
+  boolean equalsTo(Expr expr) {
+    return expr instanceof NullValue;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/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
new file mode 100644
index 0000000..7be2ea9
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/OpType.java
@@ -0,0 +1,117 @@
+/**
+ * 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.gson.*;
+
+import java.lang.reflect.Type;
+
+public enum OpType {
+
+  // relational operators
+  Relation(Relation.class),
+  RelationList(RelationList.class),
+  TableSubQuery(TableSubQuery.class),
+  Except(SetOperation.class),
+  Having(Having.class),
+	Aggregation(Aggregation.class),
+  Intersect(SetOperation.class),
+  Join(Join.class),
+  Projection(Projection.class),
+  Rename,
+  Filter(Selection.class),
+  Sort(Sort.class),
+  Union(SetOperation.class),
+  Limit(Limit.class),
+
+  // Data definition language
+  CreateTable(CreateTable.class),
+  DropTable(DropTable.class),
+
+  // logical operators
+  And(BinaryOperator.class),
+  Or(BinaryOperator.class),
+  Not(NotExpr.class),
+
+  // comparison predicates
+  Equals(BinaryOperator.class),
+  NotEquals(BinaryOperator.class),
+  LessThan(BinaryOperator.class),
+  LessThanOrEquals(BinaryOperator.class),
+  GreaterThan(BinaryOperator.class),
+  GreaterThanOrEquals(BinaryOperator.class),
+
+  // other predicates
+  CaseWhen(CaseWhenPredicate.class),
+  IsNullPredicate(IsNullPredicate.class),
+  InPredicate(InPredicate.class),
+  LikePredicate(LikePredicate.class),
+  ValueList(ValueListExpr.class),
+  Is,
+
+  // arithmetic operators
+  Plus(BinaryOperator.class),
+  Minus(BinaryOperator.class),
+  Multiply(BinaryOperator.class),
+  Divide(BinaryOperator.class),
+  Modular(BinaryOperator.class),
+
+  // other expressions
+  Column(ColumnReferenceExpr.class),
+  Target(Target.class),
+  Function(FunctionExpr.class),
+
+  // set functions
+  CountRowsFunction(CountRowsFunctionExpr.class),
+  CountValueFunction(CountValueFunctionExpr.class),
+
+  Literal(LiteralValue.class),
+  Null(NullValue.class),
+  ScalarSubQuery(ScalarSubQuery.class);
+
+  private Class baseClass;
+
+  OpType() {
+    this.baseClass = Expr.class;
+  }
+  OpType(Class clazz) {
+    this.baseClass = clazz;
+  }
+
+  public Class getBaseClass() {
+    return this.baseClass;
+  }
+
+  public static class JsonSerDer implements JsonSerializer<OpType>,
+                                            JsonDeserializer<OpType> {
+
+    @Override
+    public JsonElement serialize(OpType src, Type typeOfSrc,
+                                 JsonSerializationContext context) {
+      return new JsonPrimitive(src.name());
+    }
+
+    @Override
+    public OpType deserialize(JsonElement json, Type typeOfT,
+                                      JsonDeserializationContext context)
+        throws JsonParseException {
+      return OpType.valueOf(json.getAsString());
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Projection.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Projection.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Projection.java
index bc66bc0..38520ae 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Projection.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Projection.java
@@ -21,13 +21,17 @@ package org.apache.tajo.algebra;
 import org.apache.tajo.util.TUtil;
 
 public class Projection extends UnaryOperator implements Cloneable {
-  private boolean project_all;
+  private boolean all;
   private boolean distinct = false;
 
-  private Target [] targets;
+  private Target[] targets;
 
   public Projection() {
-    super(ExprType.Projection);
+    super(OpType.Projection);
+  }
+
+  public int size() {
+    return targets.length;
   }
 
   public boolean isDistinct() {
@@ -39,25 +43,25 @@ public class Projection extends UnaryOperator implements Cloneable {
   }
 
   public void setAll() {
-    project_all = true;
+    all = true;
   }
 
   public boolean isAllProjected() {
-    return project_all;
+    return all;
   }
 	
-	public Target [] getTargets() {
+	public Target[] getTargets() {
 	  return this.targets;
 	}
 
-  public void setTargets(Target [] targets) {
+  public void setTargets(Target[] targets) {
     this.targets = targets;
   }
 
   @Override
   boolean equalsTo(Expr expr) {
     Projection another = (Projection) expr;
-    return TUtil.checkEquals(project_all, another.project_all) &&
+    return TUtil.checkEquals(all, another.all) &&
         TUtil.checkEquals(targets, another.targets);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Relation.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Relation.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Relation.java
index df44b12..0cb0bbe 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Relation.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Relation.java
@@ -21,20 +21,24 @@ package org.apache.tajo.algebra;
 import org.apache.tajo.util.TUtil;
 
 public class Relation extends Expr {
-  private String rel_name;
+  private String tableName;
   private String alias;
 
-  protected Relation(ExprType type, String relationName) {
+  protected Relation(OpType type, String relationName) {
     super(type);
-    this.rel_name = relationName;
+    this.tableName = relationName;
   }
 
   public Relation(String relationName) {
-    this(ExprType.Relation, relationName);
+    this(OpType.Relation, relationName);
+  }
+
+  public String getCanonicalName() {
+    return alias == null ? tableName : alias;
   }
 
   public String getName() {
-    return rel_name;
+    return tableName;
   }
 
   public boolean hasAlias() {
@@ -57,13 +61,13 @@ public class Relation extends Expr {
   @Override
   boolean equalsTo(Expr expr) {
     Relation other = (Relation) expr;
-    return TUtil.checkEquals(rel_name, other.rel_name) &&
+    return TUtil.checkEquals(tableName, other.tableName) &&
         TUtil.checkEquals(alias, other.alias);
   }
 
   @Override
   public int hashCode() {
-    int result = rel_name.hashCode();
+    int result = tableName.hashCode();
     result = 31 * result + (alias != null ? alias.hashCode() : 0);
     return result;
   }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/RelationList.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/RelationList.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/RelationList.java
new file mode 100644
index 0000000..8e9f878
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/RelationList.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed 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.Preconditions;
+import org.apache.tajo.util.TUtil;
+
+import java.util.Set;
+
+public class RelationList extends Expr {
+  private Expr[] relations;
+
+  public RelationList(Expr[] relations) {
+    super(OpType.RelationList);
+    checkRelations(relations);
+    this.relations = relations;
+  }
+
+  private void checkRelations(Expr[] relations) {
+    for (Expr rel : relations) {
+      Preconditions.checkArgument(
+          rel.getType() == OpType.Relation ||
+          rel.getType() == OpType.Join ||
+          rel.getType() == OpType.TableSubQuery,
+          "Only Relation, Join, or TableSubQuery can be given to RelationList, but this expr "
+              + " is " + rel.getType());
+    }
+  }
+
+  public Expr[] getRelations() {
+    return this.relations;
+  }
+
+  public int size() {
+    return this.relations.length;
+  }
+
+  @Override
+  public String toString() {
+    return toJson();
+  }
+
+  @Override
+  boolean equalsTo(Expr expr) {
+    Set<Expr> thisSet = TUtil.newHashSet(relations);
+    RelationList another = (RelationList) expr;
+    Set<Expr> anotherSet = TUtil.newHashSet(another.relations);
+    return thisSet.equals(anotherSet);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ScalarSubQuery.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/ScalarSubQuery.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ScalarSubQuery.java
index f07cb31..2273a48 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/ScalarSubQuery.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ScalarSubQuery.java
@@ -20,8 +20,9 @@ package org.apache.tajo.algebra;
 
 public class ScalarSubQuery extends Expr {
   private Expr subquery;
+
   public ScalarSubQuery(Expr subQuery) {
-    super(ExprType.ScalarSubQuery);
+    super(OpType.ScalarSubQuery);
     this.subquery = subQuery;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Selection.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Selection.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Selection.java
index d9f68bc..f43c252 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Selection.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Selection.java
@@ -21,24 +21,23 @@ package org.apache.tajo.algebra;
 import org.apache.tajo.util.TUtil;
 
 public class Selection extends UnaryOperator implements JsonSerializable {
-  private Expr search_condition;
+  private Expr qual;
 
-  public Selection(Expr relation, Expr qual) {
-    super(ExprType.Selection);
-    setChild(relation);
-    search_condition = qual;
+  public Selection(Expr qual) {
+    super(OpType.Filter);
+    this.qual = qual;
   }
 
   public boolean hasQual() {
-    return search_condition != null;
+    return qual != null;
   }
 
   public void setQual(Expr expr) {
-    this.search_condition = expr;
+    this.qual = expr;
   }
 
 	public Expr getQual() {
-		return this.search_condition;
+		return this.qual;
 	}
 
   @Override
@@ -50,7 +49,7 @@ public class Selection extends UnaryOperator implements JsonSerializable {
   public boolean equalsTo(Expr expr) {
     if (expr instanceof Selection) {
       Selection other = (Selection) expr;
-      return TUtil.checkEquals(search_condition, other.search_condition);
+      return TUtil.checkEquals(qual, other.qual);
     }
     return false;
   }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/SetOperation.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/SetOperation.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/SetOperation.java
index 8a5ff9e..47ab44a 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/SetOperation.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/SetOperation.java
@@ -24,11 +24,12 @@ import com.google.common.base.Preconditions;
 public class SetOperation extends BinaryOperator {
   private boolean distinct = true;
 
-  public SetOperation(ExprType type, Expr left, Expr right, boolean distinct) {
+  public SetOperation(OpType type, Expr left, Expr right, boolean distinct) {
     super(type, left, right);
-    Preconditions.checkArgument(type == ExprType.Union ||
-        type == ExprType.Intersect ||
-        type == ExprType.Except);
+    Preconditions.checkArgument(type == OpType.Union ||
+        type == OpType.Intersect ||
+        type == OpType.Except);
+    this.distinct = distinct;
   }
 
   public boolean isDistinct() {

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Sort.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Sort.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Sort.java
index 7260e97..f57cd89 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Sort.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Sort.java
@@ -18,28 +18,29 @@
 
 package org.apache.tajo.algebra;
 
+import com.google.gson.annotations.SerializedName;
 import org.apache.tajo.util.TUtil;
 
 public class Sort extends UnaryOperator {
-  private SortSpec [] sort_specs;
+  private SortSpec [] sortSpecs;
 
   public Sort(final SortSpec [] sortSpecs) {
-    super(ExprType.Sort);
-    this.sort_specs = sortSpecs;
+    super(OpType.Sort);
+    this.sortSpecs = sortSpecs;
   }
 
-  public void setSortSpecs(SortSpec[] sort_specs) {
-    this.sort_specs = sort_specs;
+  public void setSortSpecs(SortSpec[] sortSpecs) {
+    this.sortSpecs = sortSpecs;
   }
 
   public SortSpec [] getSortSpecs() {
-    return this.sort_specs;
+    return this.sortSpecs;
   }
 
   @Override
   public boolean equalsTo(Expr expr) {
     Sort another = (Sort) expr;
-    return TUtil.checkEquals(sort_specs, another.sort_specs);
+    return TUtil.checkEquals(sortSpecs, another.sortSpecs);
   }
 
   @Override
@@ -50,7 +51,8 @@ public class Sort extends UnaryOperator {
   public static class SortSpec {
     private ColumnReferenceExpr key;
     private boolean asc = true;
-    private boolean null_first = false;
+    @SerializedName("null_first")
+    private boolean nullFirst = false;
 
     public SortSpec(final ColumnReferenceExpr key) {
       this.key = key;
@@ -67,7 +69,7 @@ public class Sort extends UnaryOperator {
                     final boolean nullFirst) {
       this(sortKey);
       this.asc = asc;
-      this.null_first = nullFirst;
+      this.nullFirst = nullFirst;
     }
 
     public final boolean isAscending() {
@@ -79,11 +81,11 @@ public class Sort extends UnaryOperator {
     }
 
     public final boolean isNullFirst() {
-      return this.null_first;
+      return this.nullFirst;
     }
 
     public final void setNullFirst() {
-      this.null_first = true;
+      this.nullFirst = true;
     }
 
     public final ColumnReferenceExpr getKey() {
@@ -95,7 +97,7 @@ public class Sort extends UnaryOperator {
         SortSpec other = (SortSpec) obj;
         return TUtil.checkEquals(key, other.key) &&
             TUtil.checkEquals(asc, other.asc) &&
-            TUtil.checkEquals(null_first, other.null_first);
+            TUtil.checkEquals(nullFirst, other.nullFirst);
       }
       return false;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/TableSubQuery.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/TableSubQuery.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/TableSubQuery.java
index d46dc4a..55c44ba 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/TableSubQuery.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/TableSubQuery.java
@@ -20,12 +20,25 @@ package org.apache.tajo.algebra;
 
 public class TableSubQuery extends Relation {
   private Expr subquery;
+  private String [] columnNames;
 
   public TableSubQuery(String relName, Expr subquery) {
-    super(ExprType.TableSubQuery, relName);
+    super(OpType.TableSubQuery, relName);
     this.subquery = subquery;
   }
 
+  public boolean hasColumnNames() {
+    return this.columnNames != null;
+  }
+
+  public void setColumnNames(String[] aliasList) {
+    this.columnNames = aliasList;
+  }
+
+  public String [] getColumnNames() {
+    return columnNames;
+  }
+
   public Expr getSubQuery() {
     return subquery;
   }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Target.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Target.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Target.java
index f7019ea..2de5057 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/Target.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/Target.java
@@ -20,11 +20,12 @@ package org.apache.tajo.algebra;
 
 import org.apache.tajo.util.TUtil;
 
-public class Target implements JsonSerializable {
+public class Target extends Expr {
   private Expr expr;
   private String alias;
 
   public Target(Expr expr) {
+    super(OpType.Target);
    this.expr = expr;
   }
 
@@ -45,12 +46,7 @@ public class Target implements JsonSerializable {
   }
 
   @Override
-  public String toJson() {
-    return JsonHelper.toJson(this);
-  }
-
-  @Override
-  public boolean equals(Object obj) {
+  public boolean equalsTo(Expr obj) {
     if (obj instanceof Target) {
       Target another = (Target) obj;
       return expr.equals(another.expr) && TUtil.checkEquals(alias, another.alias);
@@ -58,4 +54,9 @@ public class Target implements JsonSerializable {
 
     return false;
   }
+
+  @Override
+  public String toJson() {
+    return JsonHelper.toJson(this);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/UnaryOperator.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/UnaryOperator.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/UnaryOperator.java
index 59db158..fec87d0 100644
--- a/tajo-algebra/src/main/java/org/apache/tajo/algebra/UnaryOperator.java
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/UnaryOperator.java
@@ -21,7 +21,7 @@ package org.apache.tajo.algebra;
 public abstract class UnaryOperator extends Expr {
   private Expr child;
 
-  public UnaryOperator(ExprType type) {
+  public UnaryOperator(OpType type) {
     super(type);
   }
 
@@ -29,6 +29,10 @@ public abstract class UnaryOperator extends Expr {
     return this.child;
   }
 
+  public boolean hasChild() {
+    return child != null;
+  }
+
   public void setChild(Expr op) {
     this.child = op;
   }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ValueListExpr.java
----------------------------------------------------------------------
diff --git a/tajo-algebra/src/main/java/org/apache/tajo/algebra/ValueListExpr.java b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ValueListExpr.java
new file mode 100644
index 0000000..bbcbd21
--- /dev/null
+++ b/tajo-algebra/src/main/java/org/apache/tajo/algebra/ValueListExpr.java
@@ -0,0 +1,40 @@
+/**
+ * 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 org.apache.tajo.util.TUtil;
+
+public class ValueListExpr extends Expr {
+  private Expr[] values;
+
+  public ValueListExpr(Expr[] values) {
+    super(OpType.ValueList);
+    this.values = values;
+  }
+
+  public Expr[] getValues() {
+    return values;
+  }
+
+  @Override
+  boolean equalsTo(Expr expr) {
+    ValueListExpr valueListExpr = (ValueListExpr) expr;
+    return TUtil.checkEquals(values, valueListExpr.values);
+  }
+}


Mime
View raw message