tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [07/13] TAJO-87: Integration of tajo algebra module and SQL parser
Date Mon, 29 Jul 2013 04:03:36 GMT
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalPlannerUtils.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalPlannerUtils.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalPlannerUtils.java
index 76c5afd..f78dc21 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalPlannerUtils.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalPlannerUtils.java
@@ -21,177 +21,25 @@ package org.apache.tajo.master;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.fs.Path;
-import org.apache.tajo.catalog.*;
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Schema;
+import org.apache.tajo.catalog.TableDesc;
+import org.apache.tajo.catalog.TableMeta;
 import org.apache.tajo.catalog.proto.CatalogProtos.StoreType;
-import org.apache.tajo.engine.eval.EvalNode;
-import org.apache.tajo.engine.parser.QueryBlock;
-import org.apache.tajo.engine.planner.logical.GroupbyNode;
+import org.apache.tajo.engine.planner.FromTable;
 import org.apache.tajo.engine.planner.logical.ScanNode;
-import org.apache.tajo.engine.planner.logical.StoreTableNode;
-
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Map;
 
 public class GlobalPlannerUtils {
   private static Log LOG = LogFactory.getLog(GlobalPlannerUtils.class);
 
-  static class WorkerComparatorByNumOfQueryUnits implements Comparator {
-    Map base;
-    public WorkerComparatorByNumOfQueryUnits(Map base) {
-      this.base = base;
-    }
-    public int compare(Object a, Object b) {
-      Collection<QueryUnit> l1 = (Collection<QueryUnit>)base.get(a);
-      Collection<QueryUnit> l2 = (Collection<QueryUnit>)base.get(b);
-      if (l1.size() > l2.size()) {
-        return 1;
-      } else {
-        return -1;
-      }
-    }
-  }
-
- /* public static QueryUnit[] buildQueryDistributionPlan(
-      Map<Fragment, FragmentServingInfo> servingMap,
-      Map<String, List<String>> DNSNameToHostsMap,
-//      Set<String> failedHost,
-      QueryUnit[] queryUnits
-  ) throws UnknownWorkerException {
-    Map<String, Collection<QueryUnit>> map = Maps.newHashMap();
-    ListMultimap<String, QueryUnit> distStatus =
-        Multimaps.newListMultimap(map,
-            new Supplier<List<QueryUnit>>() {
-              @Override
-              public List<QueryUnit> get() {
-                return Lists.newArrayList();
-              }
-            });
-
-    String host;
-    Fragment fragment;
-    FragmentServingInfo servingInfo = null;
-    // build the initial query distribution status
-    for (QueryUnit unit : queryUnits) {
-      Preconditions.checkState(unit.getScanNodes().length == 1);
-      fragment = unit.getFragment(unit.getScanNodes()[0].getTableId());
-      if (servingMap.containsKey(fragment)) {
-        servingInfo = servingMap.get(fragment);
-      } else {
-        servingInfo = null;
-        // error
-      }
-      host = servingInfo.getPrimaryHost();
-      distStatus.put(host, unit);
-    }
-
-    *//*LOG.info("===== before re-balancing =====");
-    for (Map.Entry<String, Collection<QueryUnit>> e : map.entrySet()) {
-      LOG.info(e.getKey() + " : " + e.getValue().size());
-    }
-    LOG.info("\n");*//*
-
-    // re-balancing the query distribution
-    Preconditions.checkState(queryUnits.length >= servingMap.size());
-    int threshold = 0;
-    int mean = queryUnits.length / map.size();
-    int maxQueryUnitNum = mean + threshold;
-    WorkerComparatorByNumOfQueryUnits comp =
-        new WorkerComparatorByNumOfQueryUnits(map);
-    TreeMap<String, Collection<QueryUnit>> sortedMap =
-        Maps.newTreeMap(comp);
-    sortedMap.putAll(map);
-
-    Collection<QueryUnit> fromUnits;
-    Collection<QueryUnit> toUnits;
-    QueryUnit moved;
-    int moveNum = 0;
-    List<Map.Entry<String, Collection<QueryUnit>>> list =
-        Lists.newArrayList(sortedMap.entrySet());
-    int fromIdx = list.size()-1, toIdx = 0;
-    while (fromIdx > toIdx) {
-      toUnits = list.get(toIdx).getValue();
-      fromUnits = list.get(fromIdx).getValue();
-
-      do{
-        moved = fromUnits.iterator().next();
-        toUnits.add(moved);
-        fromUnits.remove(moved);
-        moveNum++;
-      } while (toUnits.size() < maxQueryUnitNum &&
-          fromUnits.size() > maxQueryUnitNum);
-      if (fromUnits.size() <= maxQueryUnitNum) {
-        fromIdx--;
-      }
-      if (toUnits.size() >= maxQueryUnitNum) {
-        toIdx++;
-      }
-    }
-
-    *//*LOG.info("===== after re-balancing " + maxQueryUnitNum + " =====");
-    for (Map.Entry<String, Collection<QueryUnit>> e : list) {
-      LOG.info(e.getKey() + " : " + e.getValue().size());
-    }
-    LOG.info("\n");*//*
-
-    LOG.info(moveNum + " query units among " +
-        queryUnits.length + " are moved!");
-
-    List<String> hosts;
-    int rrIdx = 0;
-    for (Map.Entry<String, Collection<QueryUnit>> e : list) {
-      hosts = DNSNameToHostsMap.get(e.getKey());
-      if (hosts == null) {
-        throw new UnknownWorkerException(e.getKey() + "");
-      }
-      for (QueryUnit unit : e.getValue()) {
-*//*
-        while (failedHost.contains(hosts.get(rrIdx))) {
-          if (++rrIdx == hosts.size()) {
-            rrIdx = 0;
-          }
-        }
-*//*
-        unit.setHost(hosts.get(rrIdx++));
-        if (rrIdx == hosts.size()) {
-          rrIdx = 0;
-        }
-      }
-    }
-
-    return queryUnits;
-  }*/
-
-  public static StoreTableNode newStorePlan(Schema outputSchema,
-                                            String outputTableId) {
-    StoreTableNode store = new StoreTableNode(outputTableId);
-    store.setInSchema(outputSchema);
-    store.setOutSchema(outputSchema);
-    return store;
-  }
-
   public static ScanNode newScanPlan(Schema inputSchema,
                                      String inputTableId,
                                      Path inputPath) {
     TableMeta meta = CatalogUtil.newTableMeta(inputSchema, StoreType.CSV);
     TableDesc desc = CatalogUtil.newTableDesc(inputTableId, meta, inputPath);
-    ScanNode newScan = new ScanNode(new QueryBlock.FromTable(desc));
+    ScanNode newScan = new ScanNode(new FromTable(desc));
     newScan.setInSchema(desc.getMeta().getSchema());
     newScan.setOutSchema(desc.getMeta().getSchema());
     return newScan;
   }
-
-  public static GroupbyNode newGroupbyPlan(Schema inputSchema,
-                                           Schema outputSchema,
-                                           Column[] keys,
-                                           EvalNode havingCondition,
-                                           QueryBlock.Target[] targets) {
-    GroupbyNode groupby = new GroupbyNode(keys);
-    groupby.setInSchema(inputSchema);
-    groupby.setOutSchema(outputSchema);
-    groupby.setHavingCondition(havingCondition);
-    groupby.setTargetList(targets);
-
-    return groupby;
-  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/Query.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/Query.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/Query.java
index 197ff11..6e7092c 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/Query.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/Query.java
@@ -31,16 +31,12 @@ import org.apache.tajo.QueryConf;
 import org.apache.tajo.QueryId;
 import org.apache.tajo.SubQueryId;
 import org.apache.tajo.TajoProtos.QueryState;
-import org.apache.tajo.catalog.*;
-import org.apache.tajo.catalog.proto.CatalogProtos.StoreType;
-import org.apache.tajo.engine.json.GsonCreator;
+import org.apache.tajo.catalog.TableDesc;
+import org.apache.tajo.catalog.TableDescImpl;
 import org.apache.tajo.engine.planner.global.MasterPlan;
-import org.apache.tajo.engine.planner.logical.ExprType;
-import org.apache.tajo.engine.planner.logical.IndexWriteNode;
 import org.apache.tajo.master.QueryMaster.QueryContext;
 import org.apache.tajo.master.event.*;
 import org.apache.tajo.storage.StorageManager;
-import org.apache.tajo.util.IndexUtil;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -408,25 +404,6 @@ public class Query implements EventHandler<QueryEvent> {
   private void writeStat(Path outputPath, SubQuery subQuery)
       throws IOException {
     ExecutionBlock execBlock = subQuery.getBlock();
-    if (execBlock.getPlan().getType() == ExprType.CREATE_INDEX) {
-      IndexWriteNode index = (IndexWriteNode) execBlock.getPlan();
-      Path indexPath = new Path(sm.getTablePath(index.getTableName()), "index");
-      TableMeta meta;
-      if (sm.getFileSystem().exists(new Path(indexPath, ".meta"))) {
-        meta = sm.getTableMeta(indexPath);
-      } else {
-        meta = CatalogUtil
-            .newTableMeta(execBlock.getOutputSchema(), StoreType.CSV);
-      }
-      String indexName = IndexUtil.getIndexName(index.getTableName(),
-          index.getSortSpecs());
-      String json = GsonCreator.getInstance().toJson(index.getSortSpecs());
-      meta.putOption(indexName, json);
-
-      sm.writeTableMeta(indexPath, meta);
-
-    } else {
-      sm.writeTableMeta(outputPath, subQuery.getTableMeta());
-    }
+    sm.writeTableMeta(outputPath, subQuery.getTableMeta());
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/QueryUnit.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/QueryUnit.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/QueryUnit.java
index 8489e6c..8eb26bc 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/QueryUnit.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/QueryUnit.java
@@ -148,11 +148,8 @@ public class QueryUnit implements EventHandler<TaskEvent> {
         plan.getType() == ExprType.CREATE_INDEX);
     
 	  this.plan = plan;
-	  if (plan instanceof StoreTableNode) {
-      store = (StoreTableNode) plan;      
-    } else {
-      store = (StoreTableNode) ((IndexWriteNode)plan).getSubNode();
-    }
+    store = (StoreTableNode) plan;
+
 	  LogicalNode node = plan;
 	  ArrayList<LogicalNode> s = new ArrayList<LogicalNode>();
 	  s.add(node);

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/BackendTestingUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/BackendTestingUtil.java b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/BackendTestingUtil.java
index ea711b8..361a560 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/BackendTestingUtil.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/BackendTestingUtil.java
@@ -25,12 +25,13 @@ import com.google.common.collect.Lists;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.tajo.algebra.Expr;
 import org.apache.tajo.catalog.*;
 import org.apache.tajo.catalog.proto.CatalogProtos.StoreType;
 import org.apache.tajo.common.TajoDataTypes.Type;
 import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.datum.DatumFactory;
-import org.apache.tajo.engine.parser.QueryAnalyzer;
+import org.apache.tajo.engine.parser.SQLAnalyzer;
 import org.apache.tajo.engine.planner.*;
 import org.apache.tajo.engine.planner.logical.LogicalNode;
 import org.apache.tajo.engine.planner.physical.PhysicalExec;
@@ -95,17 +96,17 @@ public class BackendTestingUtil {
 
   private TajoConf conf;
   private CatalogService catalog;
-  private QueryAnalyzer analyzer;
+  private SQLAnalyzer analyzer;
   private LogicalPlanner planner;
   public BackendTestingUtil(TajoConf conf) throws IOException {
     this.conf = conf;
     this.catalog = new LocalCatalog(conf);
-    analyzer = new QueryAnalyzer(catalog);
+    analyzer = new SQLAnalyzer();
     planner = new LogicalPlanner(catalog);
   }
 
   public ResultSet run(String [] tableNames, File [] tables, Schema [] schemas, String query)
-      throws IOException {
+      throws IOException, CloneNotSupportedException {
     Path workDir = createTmpTestDir();
     StorageManager sm = StorageManager.get(new TajoConf(), workDir);
     List<Fragment> frags = Lists.newArrayList();
@@ -119,11 +120,11 @@ public class BackendTestingUtil {
     TaskAttemptContext ctx = new TaskAttemptContext(conf,
         TUtil.newQueryUnitAttemptId(),
         frags.toArray(new Fragment[frags.size()]), workDir);
-    PlanningContext context = analyzer.parse(query);
-    LogicalNode plan = planner.createPlan(context);
-    plan = LogicalOptimizer.optimize(context, plan);
+    Expr EXPR = analyzer.parse(query);
+    LogicalPlan plan = planner.createPlan(EXPR);
+    LogicalNode rootNode = LogicalOptimizer.optimize(plan);
     PhysicalPlanner phyPlanner = new PhysicalPlannerImpl(conf, sm);
-    PhysicalExec exec = phyPlanner.createPlan(ctx, plan);
+    PhysicalExec exec = phyPlanner.createPlan(ctx, rootNode);
 
     return new ResultSetImpl(conf, new Path(workDir, "out"));
   }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/benchmark/TestTPCH.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/benchmark/TestTPCH.java b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/benchmark/TestTPCH.java
index 9e6ad8d..b47c635 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/benchmark/TestTPCH.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/benchmark/TestTPCH.java
@@ -19,12 +19,12 @@
 package org.apache.tajo.benchmark;
 
 import com.google.common.collect.Maps;
+import org.apache.tajo.IntegrationTest;
+import org.apache.tajo.TpchTestBase;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
-import org.apache.tajo.IntegrationTest;
-import org.apache.tajo.TpchTestBase;
 
 import java.io.IOException;
 import java.sql.ResultSet;
@@ -65,7 +65,7 @@ public class TestTPCH {
   }
 
   @Test
-  public void testQ2FiveWayJoin() throws Exception {
+  public void testQ2FourJoins() throws Exception {
     ResultSet res = tpch.execute(
         "select s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment, ps_supplycost, " +
             "r_name, p_type, p_size " +
@@ -85,7 +85,7 @@ public class TestTPCH {
   @Test
   public void testTPCH14Expr() throws Exception {
     ResultSet res = tpch.execute("select 100 * sum(" +
-        "case when p_type like 'PROMO%' then l_extendedprice else 0 end) / sum(l_extendedprice * (1 - l_discount)) "
+        "case when p_type like 'PROMO%' then l_extendedprice else 0.0 end) / sum(l_extendedprice * (1 - l_discount)) "
         + "as promo_revenue from lineitem, part where l_partkey = p_partkey");
 
     res.next();

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
index f1402d0..6b3d14b 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
@@ -19,10 +19,8 @@
 package org.apache.tajo.engine.eval;
 
 import org.apache.hadoop.fs.Path;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
 import org.apache.tajo.TajoTestingCluster;
+import org.apache.tajo.algebra.Expr;
 import org.apache.tajo.catalog.*;
 import org.apache.tajo.catalog.function.GeneralFunction;
 import org.apache.tajo.catalog.proto.CatalogProtos.FunctionType;
@@ -32,19 +30,25 @@ import org.apache.tajo.datum.Datum;
 import org.apache.tajo.datum.DatumFactory;
 import org.apache.tajo.engine.eval.EvalNode.Type;
 import org.apache.tajo.engine.json.GsonCreator;
-import org.apache.tajo.engine.parser.QueryAnalyzer;
-import org.apache.tajo.engine.parser.QueryBlock;
+import org.apache.tajo.engine.parser.SQLAnalyzer;
+import org.apache.tajo.engine.planner.LogicalPlan;
+import org.apache.tajo.engine.planner.LogicalPlanner;
+import org.apache.tajo.engine.planner.Target;
 import org.apache.tajo.master.TajoMaster;
 import org.apache.tajo.storage.Tuple;
 import org.apache.tajo.storage.VTuple;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
 
-import static org.junit.Assert.*;
 import static org.apache.tajo.common.TajoDataTypes.Type.*;
+import static org.junit.Assert.*;
 
 public class TestEvalTree {
   private static TajoTestingCluster util;
   private static CatalogService cat;
-  private static QueryAnalyzer analyzer;
+  private static SQLAnalyzer analyzer;
+  private static LogicalPlanner planner;
   private static Tuple [] tuples = new Tuple[3];
   
   @BeforeClass
@@ -70,7 +74,8 @@ public class TestEvalTree {
         CatalogUtil.newDataTypesWithoutLen(INT4, INT4));
     cat.registerFunction(funcMeta);
 
-    analyzer = new QueryAnalyzer(cat);
+    analyzer = new SQLAnalyzer();
+    planner = new LogicalPlanner(cat);
     
     tuples[0] = new VTuple(3);
     tuples[0].put(new Datum[] {
@@ -124,6 +129,18 @@ public class TestEvalTree {
       "select name from people where NOT (20 > 30)", // 5
   };
 
+  public static Target[] getRawTargets(String query) {
+    Expr expr = analyzer.parse(query);
+    LogicalPlan plan = planner.createPlan(expr);
+    return plan.getRootBlock().getTargetListManager().getUnEvaluatedTargets();
+  }
+
+  public static EvalNode getRootSelection(String query) {
+    Expr block = analyzer.parse(query);
+    LogicalPlan plan = planner.createPlan(block);
+    return plan.getRootBlock().getSelectionNode().getQual();
+  }
+
   @Test
   public final void testFunctionEval() throws Exception {    
     Tuple tuple = new VTuple(3);
@@ -133,41 +150,29 @@ public class TestEvalTree {
           DatumFactory.createInt4(500),
           DatumFactory.createInt4(30)});
 
-    QueryBlock block;
     EvalNode expr;
 
     Schema peopleSchema = cat.getTableDesc("people").getMeta().getSchema();
-    block = (QueryBlock) analyzer.parse(QUERIES[0]).getParseTree();
     EvalContext evalCtx;
-    expr = block.getWhereCondition();
+    expr = getRootSelection(QUERIES[0]);
     evalCtx = expr.newContext();
     expr.eval(evalCtx, peopleSchema, tuple);
     assertEquals(true, expr.terminate(evalCtx).asBool());
 
-    block = (QueryBlock) analyzer.parse(QUERIES[1]).getParseTree();
-    expr = block.getWhereCondition();
+    expr = getRootSelection(QUERIES[1]);
     evalCtx = expr.newContext();
     expr.eval(evalCtx, peopleSchema, tuple);
     assertEquals(15000, expr.terminate(evalCtx).asInt4());
     assertCloneEqual(expr);
 
-    block = (QueryBlock) analyzer.parse(QUERIES[2]).getParseTree();
-    expr = block.getWhereCondition();
-    evalCtx = expr.newContext();
-    expr.eval(evalCtx, peopleSchema, tuple);
-    assertEquals(15050, expr.terminate(evalCtx).asInt4());
-    assertCloneEqual(expr);
-    
-    block = (QueryBlock) analyzer.parse(QUERIES[2]).getParseTree();
-    expr = block.getWhereCondition();
+    expr = getRootSelection(QUERIES[2]);
     evalCtx = expr.newContext();
     expr.eval(evalCtx, peopleSchema, tuple);
     assertEquals(15050, expr.terminate(evalCtx).asInt4());
     assertCloneEqual(expr);
     
     // Aggregation function test
-    block = (QueryBlock) analyzer.parse(QUERIES[4]).getParseTree();
-    expr = block.getTargetList()[0].getEvalTree();
+    expr = getRawTargets(QUERIES[4])[0].getEvalTree();
     evalCtx = expr.newContext();
     
     final int tuplenum = 10;
@@ -372,7 +377,6 @@ public class TestEvalTree {
     assertFalse(expr.terminate(evalCtx).asBool());
 
     BinaryEval plus = new BinaryEval(Type.PLUS, e1, e2);
-    evalCtx = expr.newContext();
     expr = new BinaryEval(Type.LTH, e1, plus);
     evalCtx = expr.newContext();
     expr.eval(evalCtx, null, null);
@@ -598,10 +602,8 @@ public class TestEvalTree {
     assertTrue(not.terminate(evalCtx).asBool());
     
     // Evaluation Test
-    QueryBlock block;
     Schema peopleSchema = cat.getTableDesc("people").getMeta().getSchema();
-    block = (QueryBlock) analyzer.parse(NOT[0]).getParseTree();
-    expr = block.getWhereCondition();
+    expr = getRootSelection(NOT[0]);
     evalCtx = expr.newContext();
     expr.eval(evalCtx, peopleSchema, tuples[0]);
     assertTrue(expr.terminate(evalCtx).asBool());
@@ -619,12 +621,10 @@ public class TestEvalTree {
   
   @Test
   public final void testLike() {
-    QueryBlock block;
     EvalNode expr;
 
     Schema peopleSchema = cat.getTableDesc("people").getMeta().getSchema();
-    block = (QueryBlock) analyzer.parse(LIKE[0]).getParseTree();
-    expr = block.getWhereCondition();
+    expr = getRootSelection(LIKE[0]);
     EvalContext evalCtx = expr.newContext();
     expr.eval(evalCtx, peopleSchema, tuples[0]);
     assertTrue(expr.terminate(evalCtx).asBool());
@@ -634,8 +634,7 @@ public class TestEvalTree {
     assertTrue(expr.terminate(evalCtx).asBool());
     
     // prefix
-    block = (QueryBlock) analyzer.parse(LIKE[1]).getParseTree();
-    expr = block.getWhereCondition();
+    expr = getRootSelection(LIKE[1]);
     evalCtx = expr.newContext();
     expr.eval(evalCtx, peopleSchema, tuples[0]);
     assertTrue(expr.terminate(evalCtx).asBool());
@@ -645,8 +644,7 @@ public class TestEvalTree {
     assertFalse(expr.terminate(evalCtx).asBool());
 
     // Not Test
-    block = (QueryBlock) analyzer.parse(LIKE[2]).getParseTree();
-    expr = block.getWhereCondition();
+    expr = getRootSelection(LIKE[2]);
     evalCtx = expr.newContext();
     expr.eval(evalCtx, peopleSchema, tuples[0]);
     assertFalse(expr.terminate(evalCtx).asBool());
@@ -663,16 +661,13 @@ public class TestEvalTree {
 
   @Test
   public void testIsNullEval() {
-    QueryBlock block;
     EvalNode expr;
 
-    block = (QueryBlock) analyzer.parse(IS_NULL[0]).getParseTree();
-    expr = block.getWhereCondition();
+    expr = getRootSelection(IS_NULL[0]);
 
     assertIsNull(expr);
 
-    block = (QueryBlock) analyzer.parse(IS_NULL[1]).getParseTree();
-    expr = block.getWhereCondition();
+    expr = getRootSelection(IS_NULL[1]);
 
     IsNullEval nullEval = (IsNullEval) expr;
     assertTrue(nullEval.isNot());

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
index 033578b..3638352 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
@@ -20,10 +20,8 @@ package org.apache.tajo.engine.eval;
 
 import com.google.common.collect.Sets;
 import org.apache.hadoop.fs.Path;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
 import org.apache.tajo.TajoTestingCluster;
+import org.apache.tajo.algebra.Expr;
 import org.apache.tajo.catalog.*;
 import org.apache.tajo.catalog.proto.CatalogProtos.FunctionType;
 import org.apache.tajo.catalog.proto.CatalogProtos.StoreType;
@@ -31,12 +29,17 @@ import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.datum.DatumFactory;
 import org.apache.tajo.engine.eval.EvalNode.Type;
 import org.apache.tajo.engine.eval.TestEvalTree.TestSum;
-import org.apache.tajo.engine.parser.QueryAnalyzer;
-import org.apache.tajo.engine.parser.QueryBlock;
-import org.apache.tajo.engine.parser.QueryBlock.Target;
 import org.apache.tajo.engine.planner.LogicalPlanner;
+import org.apache.tajo.engine.planner.Target;
+import org.apache.tajo.engine.parser.SQLAnalyzer;
+import org.apache.tajo.engine.planner.LogicalPlan;
+import org.apache.tajo.engine.planner.logical.EvalExprNode;
+import org.apache.tajo.engine.planner.logical.ExprType;
 import org.apache.tajo.exception.InternalException;
 import org.apache.tajo.master.TajoMaster;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
 
 import java.util.Collection;
 import java.util.List;
@@ -51,7 +54,7 @@ public class TestEvalTreeUtil {
   static EvalNode expr1;
   static EvalNode expr2;
   static EvalNode expr3;
-  static QueryAnalyzer analyzer;
+  static SQLAnalyzer analyzer;
   static LogicalPlanner planner;
 
 
@@ -79,19 +82,12 @@ public class TestEvalTreeUtil {
         CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.INT4, TajoDataTypes.Type.INT4));
     catalog.registerFunction(funcMeta);
 
-    analyzer = new QueryAnalyzer(catalog);
+    analyzer = new SQLAnalyzer();
     planner = new LogicalPlanner(catalog);
-    
-    QueryBlock block;
 
-    block = (QueryBlock) analyzer.parse(TestEvalTree.QUERIES[0]).getParseTree();
-    expr1 = block.getWhereCondition();
-
-    block = (QueryBlock) analyzer.parse(TestEvalTree.QUERIES[1]).getParseTree();
-    expr2 = block.getWhereCondition();
-    
-    block = (QueryBlock) analyzer.parse(TestEvalTree.QUERIES[2]).getParseTree();
-    expr3 = block.getWhereCondition();
+    expr1 = getRootSelection(TestEvalTree.QUERIES[0]);
+    expr2 = getRootSelection(TestEvalTree.QUERIES[1]);
+    expr3 = getRootSelection(TestEvalTree.QUERIES[2]);
   }
 
   @AfterClass
@@ -99,6 +95,22 @@ public class TestEvalTreeUtil {
     util.shutdownCatalogCluster();
   }
 
+  public static Target [] getRawTargets(String query) {
+    Expr expr = analyzer.parse(query);
+    LogicalPlan plan = planner.createPlan(expr);
+    if (plan.getRootBlock().getRoot().getType() == ExprType.EXPRS) {
+      return ((EvalExprNode)plan.getRootBlock().getRoot()).getExprs();
+    } else {
+      return plan.getRootBlock().getTargetListManager().getUnEvaluatedTargets();
+    }
+  }
+
+  public static EvalNode getRootSelection(String query) {
+    Expr block = analyzer.parse(query);
+    LogicalPlan plan = planner.createPlan(block);
+    return plan.getRootBlock().getSelectionNode().getQual();
+  }
+
   @Test
   public final void testChangeColumnRef() throws CloneNotSupportedException {
     EvalNode copy = (EvalNode)expr1.clone();
@@ -151,9 +163,8 @@ public class TestEvalTreeUtil {
   
   @Test
   public final void testGetSchemaFromTargets() throws InternalException {
-    QueryBlock block = (QueryBlock) analyzer.parse(QUERIES[0]).getParseTree();
-    Schema schema = 
-        EvalTreeUtil.getSchemaByTargets(null, block.getTargetList());
+    Target [] targets = getRawTargets(QUERIES[0]);
+    Schema schema = EvalTreeUtil.getSchemaByTargets(null, targets);
     Column col1 = schema.getColumn(0);
     Column col2 = schema.getColumn(1);
     assertEquals("plus", col1.getColumnName());
@@ -164,9 +175,9 @@ public class TestEvalTreeUtil {
   
   @Test
   public final void testGetContainExprs() throws CloneNotSupportedException {
-    QueryBlock block = (QueryBlock) analyzer.parse(QUERIES[1]).getParseTree();
-    Target [] targets = block.getTargetList();
-    
+    Expr expr = analyzer.parse(QUERIES[1]);
+    LogicalPlan plan = planner.createPlan(expr);
+    Target [] targets = plan.getRootBlock().getTargetListManager().getUnEvaluatedTargets();
     Column col1 = new Column("people.score", TajoDataTypes.Type.INT4);
     Collection<EvalNode> exprs =
         EvalTreeUtil.getContainExpr(targets[0].getEvalTree(), col1);
@@ -186,8 +197,7 @@ public class TestEvalTreeUtil {
   @Test
   public final void testGetCNF() {
     // "select score from people where score < 10 and 4 < score "
-    QueryBlock block = (QueryBlock) analyzer.parse(QUERIES[5]).getParseTree();
-    EvalNode node = block.getWhereCondition();
+    EvalNode node = getRootSelection(QUERIES[5]);
     EvalNode [] cnf = EvalTreeUtil.getConjNormalForm(node);
     
     Column col1 = new Column("people.score", TajoDataTypes.Type.INT4);
@@ -214,8 +224,7 @@ public class TestEvalTreeUtil {
   @Test
   public final void testTransformCNF2Singleton() {
     // "select score from people where score < 10 and 4 < score "
-    QueryBlock block = (QueryBlock) analyzer.parse(QUERIES[6]).getParseTree();
-    EvalNode node = block.getWhereCondition();
+    EvalNode node = getRootSelection(QUERIES[6]);
     EvalNode [] cnf1 = EvalTreeUtil.getConjNormalForm(node);
     assertEquals(3, cnf1.length);
     
@@ -229,8 +238,7 @@ public class TestEvalTreeUtil {
   
   @Test
   public final void testSimplify() {
-    QueryBlock block = (QueryBlock) analyzer.parse(QUERIES[0]).getParseTree();
-    Target [] targets = block.getTargetList();
+    Target [] targets = getRawTargets(QUERIES[0]);
     EvalNode node = AlgebraicUtil.simplify(targets[0].getEvalTree());
     EvalContext nodeCtx = node.newContext();
     assertEquals(Type.CONST, node.getType());
@@ -242,35 +250,30 @@ public class TestEvalTreeUtil {
     node.eval(nodeCtx, null, null);
     assertTrue(7.0d == node.terminate(nodeCtx).asFloat8());
 
-    block = (QueryBlock) analyzer.parse(QUERIES[1]).getParseTree();
-    targets = block.getTargetList();
+    Expr expr = analyzer.parse(QUERIES[1]);
+    LogicalPlan plan = planner.createPlan(expr);
+    targets = plan.getRootBlock().getTargetListManager().getUnEvaluatedTargets();
     Column col1 = new Column("people.score", TajoDataTypes.Type.INT4);
     Collection<EvalNode> exprs =
         EvalTreeUtil.getContainExpr(targets[0].getEvalTree(), col1);
     node = exprs.iterator().next();
-    System.out.println(AlgebraicUtil.simplify(node));
   }
   
   @Test
   public final void testConatainSingleVar() {
-    QueryBlock block = (QueryBlock) analyzer.parse(QUERIES[2]).getParseTree();
-    EvalNode node = block.getWhereCondition();
+    EvalNode node = getRootSelection(QUERIES[2]);
     assertEquals(true, AlgebraicUtil.containSingleVar(node));
-    
-    block = (QueryBlock) analyzer.parse(QUERIES[3]).getParseTree();
-    node = block.getWhereCondition();
+    node = getRootSelection(QUERIES[3]);
     assertEquals(true, AlgebraicUtil.containSingleVar(node));
   }
   
   @Test
   public final void testTranspose() {
-    QueryBlock block = (QueryBlock) analyzer.parse(QUERIES[2]).getParseTree();
-    EvalNode node = block.getWhereCondition();
-    assertEquals(true, AlgebraicUtil.containSingleVar(node));
+    //EvalNode node = getRootSelection(QUERIES[2]);
+    //assertEquals(true, AlgebraicUtil.containSingleVar(node));
     
     Column col1 = new Column("people.score", TajoDataTypes.Type.INT4);
-    block = (QueryBlock) analyzer.parse(QUERIES[3]).getParseTree();
-    node = block.getWhereCondition();    
+    EvalNode node = getRootSelection(QUERIES[3]);
     // we expect that score < 3
     EvalNode transposed = AlgebraicUtil.transpose(node, col1);
     assertEquals(Type.GTH, transposed.getType());
@@ -280,8 +283,7 @@ public class TestEvalTreeUtil {
     transposed.getRightExpr().eval(evalCtx, null, null);
     assertEquals(1, transposed.getRightExpr().terminate(evalCtx).asInt4());
 
-    block = (QueryBlock) analyzer.parse(QUERIES[4]).getParseTree();
-    node = block.getWhereCondition();    
+    node = getRootSelection(QUERIES[4]);
     // we expect that score < 3
     transposed = AlgebraicUtil.transpose(node, col1);
     assertEquals(Type.LTH, transposed.getType());
@@ -294,11 +296,10 @@ public class TestEvalTreeUtil {
 
   @Test
   public final void testFindDistinctAggFunctions() {
-
-    QueryBlock block = (QueryBlock) analyzer.parse(
-        "select sum(score) + max(age) from people").getParseTree();
+    String query = "select sum(score) + max(age) from people";
+    Target [] targets = getRawTargets(query);
     List<AggFuncCallEval> list = EvalTreeUtil.
-        findDistinctAggFunction(block.getTargetList()[0].getEvalTree());
+        findDistinctAggFunction(targets[0].getEvalTree());
     assertEquals(2, list.size());
     Set<String> result = Sets.newHashSet("max", "sum");
     for (AggFuncCallEval eval : list) {

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestQueryAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestQueryAnalyzer.java b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestQueryAnalyzer.java
deleted file mode 100644
index 04eab36..0000000
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestQueryAnalyzer.java
+++ /dev/null
@@ -1,653 +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.engine.parser;
-
-import org.apache.hadoop.fs.Path;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.apache.tajo.TajoTestingCluster;
-import org.apache.tajo.benchmark.TPCH;
-import org.apache.tajo.catalog.*;
-import org.apache.tajo.catalog.proto.CatalogProtos.FunctionType;
-import org.apache.tajo.catalog.proto.CatalogProtos.IndexMethod;
-import org.apache.tajo.catalog.proto.CatalogProtos.StoreType;
-import org.apache.tajo.common.TajoDataTypes;
-import org.apache.tajo.datum.DatumFactory;
-import org.apache.tajo.engine.eval.ConstEval;
-import org.apache.tajo.engine.eval.EvalNode;
-import org.apache.tajo.engine.eval.EvalNode.Type;
-import org.apache.tajo.engine.eval.TestEvalTree.TestSum;
-import org.apache.tajo.engine.parser.QueryBlock.GroupElement;
-import org.apache.tajo.engine.parser.QueryBlock.GroupType;
-import org.apache.tajo.engine.parser.QueryBlock.JoinClause;
-import org.apache.tajo.engine.planner.JoinType;
-import org.apache.tajo.engine.query.exception.InvalidQueryException;
-
-import java.util.Iterator;
-import java.util.List;
-
-import static org.junit.Assert.*;
-
-/**
- * This unit test examines the correctness of QueryAnalyzer that analyzes 
- * an abstract syntax tree built from Antlr and generates a QueryBlock instance.
- * 
- * @see QueryAnalyzer
- * @see org.apache.tajo.engine.parser.QueryBlock
- */
-public class TestQueryAnalyzer {
-  private static TajoTestingCluster util;
-  private static CatalogService cat = null;
-  private static Schema schema1 = null;
-  private static QueryAnalyzer analyzer = null;
-  
-  @BeforeClass
-  public static void setUp() throws Exception {
-    util = new TajoTestingCluster();
-    util.startCatalogCluster();
-    cat = util.getMiniCatalogCluster().getCatalog();
-    
-    schema1 = new Schema();
-    schema1.addColumn("id", TajoDataTypes.Type.INT4);
-    schema1.addColumn("name", TajoDataTypes.Type.TEXT);
-    schema1.addColumn("score", TajoDataTypes.Type.INT4);
-    schema1.addColumn("age", TajoDataTypes.Type.INT4);
-    
-    Schema schema2 = new Schema();
-    schema2.addColumn("id", TajoDataTypes.Type.INT4);
-    schema2.addColumn("people_id", TajoDataTypes.Type.INT4);
-    schema2.addColumn("dept", TajoDataTypes.Type.TEXT);
-    schema2.addColumn("year", TajoDataTypes.Type.INT4);
-    
-    Schema schema3 = new Schema();
-    schema3.addColumn("id", TajoDataTypes.Type.INT4);
-    schema3.addColumn("people_id", TajoDataTypes.Type.INT4);
-    schema3.addColumn("class", TajoDataTypes.Type.TEXT);
-    schema3.addColumn("branch_name", TajoDataTypes.Type.TEXT);
-
-    Schema schema4 = new Schema();
-    schema4.addColumn("char_col", TajoDataTypes.Type.CHAR);
-    schema4.addColumn("short_col", TajoDataTypes.Type.INT2);
-    schema4.addColumn("int_col", TajoDataTypes.Type.INT4);
-    schema4.addColumn("long_col", TajoDataTypes.Type.INT8);
-    schema4.addColumn("float_col", TajoDataTypes.Type.FLOAT4);
-    schema4.addColumn("double_col", TajoDataTypes.Type.FLOAT8);
-    schema4.addColumn("string_col", TajoDataTypes.Type.TEXT);
-
-    TableMeta meta = CatalogUtil.newTableMeta(schema1, StoreType.CSV);
-    TableDesc people = new TableDescImpl("people", meta, new Path("file:///"));
-    cat.addTable(people);
-    
-    TableDesc student = CatalogUtil.newTableDesc("student", schema2, StoreType.CSV,
-        new Options(),
-        new Path("file:///"));
-    cat.addTable(student);
-    
-    TableDesc branch = CatalogUtil.newTableDesc("branch", schema3, StoreType.CSV,
-        new Options(),
-        new Path("file:///"));
-    cat.addTable(branch);
-
-    TableDesc allType = CatalogUtil.newTableDesc("alltype", schema4, StoreType.CSV,
-        new Options(),
-        new Path("file:///"));
-    cat.addTable(allType);
-
-    TPCH tpch = new TPCH();
-    tpch.loadSchemas();
-    Schema lineitemSchema = tpch.getSchema("lineitem");
-    Schema partSchema = tpch.getSchema("part");
-    TableDesc lineitem = CatalogUtil.newTableDesc("lineitem", lineitemSchema, StoreType.CSV,
-        new Options(),
-        new Path("file:///"));
-    TableDesc part = CatalogUtil.newTableDesc("part", partSchema, StoreType.CSV,
-        new Options(),
-        new Path("file:///"));
-    cat.addTable(lineitem);
-    cat.addTable(part);
-    
-    FunctionDesc funcMeta = new FunctionDesc("sumtest", TestSum.class, FunctionType.GENERAL,
-        CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.INT4),
-        CatalogUtil.newDataTypesWithoutLen(TajoDataTypes.Type.INT4));
-
-    cat.registerFunction(funcMeta);
-    
-    analyzer = new QueryAnalyzer(cat);
-  }
-
-  @AfterClass
-  public static void tearDown() throws Exception {
-    util.shutdownCatalogCluster();
-  }
-
-  private String[] QUERIES = { 
-      "select id, name, score, age from people", // 0
-      "select name, score, age from people where score > 30", // 1
-      "select name, score, age from people where 3 + 5 * 3", // 2
-      "select age, sumtest(score) as total from people group by age having sumtest(score) > 30", // 3
-      "select p.id, s.id, score, dept from people as p, student as s where p.id = s.id", // 4
-      "select name, score from people order by score asc, age desc null first", // 5
-      // only expr
-      "select 7 + 8", // 6
-      // limit test
-      "select id, name, score, age from people limit 3" // 7
-
-  };
- 
-  @Test
-  public final void testSelectStatement() {
-    QueryBlock block = (QueryBlock) analyzer.parse(QUERIES[0]).getParseTree();
-    assertEquals(1, block.getFromTables().length);
-    assertEquals("people", block.getFromTables()[0].getTableName());
-  }
-
-  @Test
-  public final void testOnlyExpr() {
-    QueryBlock block = (QueryBlock) analyzer.parse(QUERIES[6]).getParseTree();
-    EvalNode node = block.getTargetList()[0].getEvalTree();
-    assertEquals(Type.PLUS, node.getType());
-  }
-
-  @Test
-  public void testLimit() {
-    QueryBlock queryBlock =
-        (QueryBlock) analyzer.parse(QUERIES[7]).getParseTree();
-    assertEquals(3, queryBlock.getLimitClause().getLimitRow());
-  }
-
-  private String[] GROUP_BY = { 
-      "select age, sumtest(score) as total from people group by age having sumtest(score) > 30", // 0
-      "select name, age, sumtest(score) total from people group by cube (name,age)", // 1
-      "select name, age, sumtest(score) total from people group by rollup (name,age)", // 2
-      "select id, name, age, sumtest(score) total from people group by id, cube (name), rollup (age)", // 3
-      "select id, name, age, sumtest(score) total from people group by ()", // 4
-  };
-  
-  @Test
-  public final void testGroupByStatement() {
-    ParseTree tree = analyzer.parse(GROUP_BY[0]).getParseTree();
-    assertEquals(StatementType.SELECT, tree.getType());
-    QueryBlock block = (QueryBlock) tree;
-    assertTrue(block.hasGroupbyClause());
-    assertEquals(1, block.getGroupByClause().getGroupSet().size());
-    assertEquals("age", block.getGroupByClause().getGroupSet().get(0).getColumns()[0].getColumnName());
-    assertTrue(block.hasHavingCond());
-    assertEquals(Type.GTH, block.getHavingCond().getType());
-  }
-  
-  @Test
-  public final void testCubeByStatement() {
-    ParseTree tree = analyzer.parse(GROUP_BY[1]).getParseTree();
-    assertEquals(StatementType.SELECT, tree.getType());
-    QueryBlock block = (QueryBlock) tree;
-    assertTrue(block.hasGroupbyClause());
-    assertEquals(1, block.getGroupByClause().getGroupSet().size());
-    assertEquals(GroupType.CUBE, block.getGroupByClause().
-        getGroupSet().get(0).getType());
-    List<GroupElement> groups = block.getGroupByClause().getGroupSet();
-    assertEquals("people.name", groups.get(0).getColumns()[0].getQualifiedName());
-    assertEquals("people.age", groups.get(0).getColumns()[1].getQualifiedName());
-  }
-  
-  @Test
-  public final void testRollUpStatement() {
-    ParseTree tree = analyzer.parse(GROUP_BY[2]).getParseTree();
-    assertEquals(StatementType.SELECT, tree.getType());
-    QueryBlock block = (QueryBlock) tree;
-    assertTrue(block.hasGroupbyClause());
-    assertEquals(1, block.getGroupByClause().getGroupSet().size());
-    assertEquals(GroupType.ROLLUP, block.getGroupByClause().
-        getGroupSet().get(0).getType());
-    List<GroupElement> groups = block.getGroupByClause().getGroupSet();
-    assertEquals("people.name", groups.get(0).getColumns()[0].getQualifiedName());
-    assertEquals("people.age", groups.get(0).getColumns()[1].getQualifiedName());
-  }
-  
-  @Test
-  public final void testMixedGroupByStatement() {
-    ParseTree tree = analyzer.parse(GROUP_BY[3]).getParseTree();
-    assertEquals(StatementType.SELECT, tree.getType());
-    QueryBlock block = (QueryBlock) tree;
-    assertTrue(block.hasGroupbyClause());
-    assertEquals(3, block.getGroupByClause().getGroupSet().size());
-    Iterator<GroupElement> it = block.getGroupByClause().getGroupSet().iterator();
-    GroupElement group = it.next();
-    assertEquals(GroupType.CUBE, group.getType());    
-    assertEquals("people.name", group.getColumns()[0].getQualifiedName());
-    group = it.next();
-    assertEquals(GroupType.ROLLUP, group.getType());    
-    assertEquals("people.age", group.getColumns()[0].getQualifiedName());
-    group = it.next();
-    assertEquals(GroupType.GROUPBY, group.getType());
-    assertEquals("people.id", group.getColumns()[0].getQualifiedName());
-  }
-  
-  @Test
-  public final void testEmptyGroupSetStatement() {
-    ParseTree tree = analyzer.parse(GROUP_BY[4]).getParseTree();
-    assertEquals(StatementType.SELECT, tree.getType());
-    QueryBlock block = (QueryBlock) tree;
-    assertTrue(block.hasGroupbyClause());
-    assertTrue(block.getGroupByClause().isEmptyGroupSet());
-  }
-  
-  @Test
-  public final void testSelectStatementWithAlias() {
-    QueryBlock block = (QueryBlock) analyzer.parse(QUERIES[4]).getParseTree();
-    assertEquals(2, block.getFromTables().length);
-    assertEquals("people", block.getFromTables()[0].getTableName());
-    assertEquals("student", block.getFromTables()[1].getTableName());
-  }
-  
-  @Test
-  public final void testOrderByClause() {
-    QueryBlock block = (QueryBlock) analyzer.parse(QUERIES[5]).getParseTree();
-    testOrderByCluse(block);
-  }
-  
-  private static void testOrderByCluse(QueryBlock block) {
-    assertEquals(2, block.getSortKeys().length);
-    assertEquals("people.score", block.getSortKeys()[0].getSortKey().getQualifiedName());
-    assertEquals(true, block.getSortKeys()[0].isAscending());
-    assertEquals(false, block.getSortKeys()[0].isNullFirst());
-    assertEquals("people.age", block.getSortKeys()[1].getSortKey().getQualifiedName());
-    assertEquals(false, block.getSortKeys()[1].isAscending());
-    assertEquals(true, block.getSortKeys()[1].isNullFirst());
-  }
-
-  static final String [] createTableStmts = {
-    "create table table1 (name text, age int)", // 0
-    "create table table1 (name text, age int) using rcfile", // 1
-    "create table table1 (name text, age int) using rcfile with ('rcfile.buffer'=4096)", // 2
-    // create table test
-    "create table store1 as select name, score from people order by score asc, age desc null first",// 3
-    // create table test
-    "create table store1 (c1 text, c2 bigint) as select name, score from people order by score asc, age desc null first",// 4
-    // create table test
-    "create table store2 using rcfile with ('rcfile.buffer' = 4096) as select name, score from people order by score asc, age desc null first", // 5
-    // create table def
-    "create table table1 (name text, age int, earn float(10), score float(30)) using rcfile with ('rcfile.buffer' = 4096)", // 6
-    // create table def with location
-    "create external table table1 (name text, age int, earn bigint, score float) using csv with ('csv.delimiter'='|') location '/tmp/data'" // 7
-  };
-
-  @Test
-  public final void testCreateTable1() {
-    CreateTableStmt stmt = (CreateTableStmt) analyzer.parse(createTableStmts[0]).getParseTree();
-    assertEquals("table1", stmt.getTableName());
-    assertTrue(stmt.hasDefinition());
-
-    stmt = (CreateTableStmt) analyzer.parse(createTableStmts[1]).getParseTree();
-    assertEquals("table1", stmt.getTableName());
-    assertTrue(stmt.hasDefinition());
-    assertTrue(stmt.hasStoreType());
-    assertEquals(StoreType.RCFILE, stmt.getStoreType());
-
-    stmt = (CreateTableStmt) analyzer.parse(createTableStmts[2]).getParseTree();
-    assertEquals("table1", stmt.getTableName());
-    assertTrue(stmt.hasDefinition());
-    assertTrue(stmt.hasStoreType());
-    assertEquals(StoreType.RCFILE, stmt.getStoreType());
-    assertTrue(stmt.hasOptions());
-    assertEquals("4096", stmt.getOptions().get("rcfile.buffer"));
-  }
-  
-  @Test
-  public final void testCreateTableAsSelect() {
-    CreateTableStmt stmt = (CreateTableStmt) analyzer.parse(createTableStmts[3]).getParseTree();
-    assertEquals("store1", stmt.getTableName());
-    testOrderByCluse(stmt.getSelectStmt());
-
-    stmt = (CreateTableStmt) analyzer.parse(createTableStmts[4]).getParseTree();
-    assertEquals("store1", stmt.getTableName());
-    testOrderByCluse(stmt.getSelectStmt());
-    assertTrue(stmt.hasTableDef());
-
-    stmt = (CreateTableStmt) analyzer.parse(createTableStmts[5]).getParseTree();
-    assertEquals("store2", stmt.getTableName());
-    assertEquals(StoreType.RCFILE, stmt.getStoreType());
-    assertEquals("4096", stmt.getOptions().get("rcfile.buffer"));
-    testOrderByCluse(stmt.getSelectStmt());
-  }
-
-  @Test
-  public final void testCreateTableDef1() {
-    CreateTableStmt stmt = (CreateTableStmt) analyzer.parse(createTableStmts[6]).getParseTree();
-    assertEquals("table1", stmt.getTableName());
-    Schema def = stmt.getTableDef();
-    assertEquals("name", def.getColumn(0).getColumnName());
-    assertEquals(TajoDataTypes.Type.TEXT, def.getColumn(0).getDataType().getType());
-    assertEquals("age", def.getColumn(1).getColumnName());
-    assertEquals(TajoDataTypes.Type.INT4, def.getColumn(1).getDataType().getType());
-    assertEquals("earn", def.getColumn(2).getColumnName());
-    assertEquals(TajoDataTypes.Type.FLOAT4, def.getColumn(2).getDataType().getType()); // float(10)
-    assertEquals("score", def.getColumn(3).getColumnName());
-    assertEquals(TajoDataTypes.Type.FLOAT8, def.getColumn(3).getDataType().getType()); // float(30)
-    assertEquals(StoreType.RCFILE, stmt.getStoreType());
-    assertFalse(stmt.hasPath());
-    assertTrue(stmt.hasOptions());
-    assertEquals("4096", stmt.getOptions().get("rcfile.buffer"));
-  }
-  
-  @Test
-  public final void testCreateTableDef2() {
-    CreateTableStmt stmt = (CreateTableStmt) analyzer.parse(createTableStmts[7]).getParseTree();
-    assertEquals("table1", stmt.getTableName());
-    Schema def = stmt.getTableDef();
-    assertEquals("name", def.getColumn(0).getColumnName());
-    assertEquals(TajoDataTypes.Type.TEXT, def.getColumn(0).getDataType().getType());
-    assertEquals("age", def.getColumn(1).getColumnName());
-    assertEquals(TajoDataTypes.Type.INT4, def.getColumn(1).getDataType().getType());
-    assertEquals("earn", def.getColumn(2).getColumnName());
-    assertEquals(TajoDataTypes.Type.INT8, def.getColumn(2).getDataType().getType());
-    assertEquals("score", def.getColumn(3).getColumnName());
-    assertEquals(TajoDataTypes.Type.FLOAT8, def.getColumn(3).getDataType().getType()); // float
-    assertEquals(StoreType.CSV, stmt.getStoreType());    
-    assertEquals("/tmp/data", stmt.getPath().toString());
-    assertTrue(stmt.hasOptions());
-    assertEquals("|", stmt.getOptions().get("csv.delimiter"));
-  }
-
-  // create index
-  final static String createIndexStmt =
-      "create unique index score_idx on people using hash (score, age desc null first) with ('fillfactor' = 70)";
-  
-  @Test 
-  public final void testCreateIndex() {
-    CreateIndexStmt stmt = (CreateIndexStmt) analyzer.parse(createIndexStmt).getParseTree();
-    assertEquals("score_idx", stmt.getIndexName());
-    assertTrue(stmt.isUnique());
-    assertEquals("people", stmt.getTableName());
-    assertEquals(IndexMethod.HASH, stmt.getMethod());
-    
-    SortSpec [] sortKeys = stmt.getSortSpecs();
-    assertEquals(2, sortKeys.length);
-    assertEquals("score", sortKeys[0].getSortKey().getColumnName());
-    assertEquals(TajoDataTypes.Type.INT4, sortKeys[0].getSortKey().getDataType().getType());
-    assertEquals("age", sortKeys[1].getSortKey().getColumnName());
-    assertEquals(TajoDataTypes.Type.INT4, sortKeys[1].getSortKey().getDataType().getType());
-    assertEquals(false, sortKeys[1].isAscending());
-    assertEquals(true, sortKeys[1].isNullFirst());
-    
-    assertTrue(stmt.hasParams());
-    assertEquals("70", stmt.getParams().get("fillfactor"));
-  }
-  
-  private String [] INVALID_QUERIES = {
-      "select * from invalid", // 0 - when a given table does not exist
-      "select time, age from people", // 1 - when a given column does not exist
-      "select age from people group by age2" // 2 - when a grouping field does not eixst
-  };
-  @Test(expected = InvalidQueryException.class)
-  public final void testNoSuchTables()  {
-    analyzer.parse(INVALID_QUERIES[0]);
-  }
-  
-  @Test(expected = InvalidQueryException.class)
-  public final void testNoSuchFields()  {
-    analyzer.parse(INVALID_QUERIES[1]);
-  }
-  
-  @Test(expected = InvalidQueryException.class)
-  public final void testInvalidGroupFields() {
-    QueryBlock block = (QueryBlock) analyzer.parse(INVALID_QUERIES[2]).getParseTree();
-    assertEquals("age", block.getGroupByClause().getGroupSet().get(0).getColumns()[0].getQualifiedName());
-  }
-  
-  static String [] JOINS = {
-    "select p.id, name, branch_name from people as p natural join student natural join branch", // 0
-    "select name, dept from people as p inner join student as s on p.id = s.people_id", // 1
-    "select name, dept from people as p inner join student as s using (p.id)", // 2
-    "select p.id, name, branch_name from people as p cross join student cross join branch", // 3
-    "select p.id, dept from people as p left outer join student as s on p.id = s.people_id", // 4
-    "select p.id, dept from people as p right outer join student as s on p.id = s.people_id", // 5
-    "select p.id, dept from people as p join student as s on p.id = s.people_id", // 6
-    "select p.id, dept from people as p left join student as s on p.id = s.people_id", // 7
-    "select p.id, dept from people as p right join student as s on p.id= s.people_id" // 8
-  };
-  
-  @Test
-  /**
-   *           join
-   *          /    \
-   *       join    branch
-   *    /       \
-   * people  student
-   */
-  public final void testNaturalJoinClause() {
-    QueryBlock block = (QueryBlock) analyzer.parse(JOINS[0]).getParseTree();
-    JoinClause join = block.getJoinClause();
-    assertEquals(JoinType.INNER, join.getJoinType());
-    assertTrue(join.isNatural());
-    assertEquals("branch", join.getRight().getTableName());
-    assertTrue(join.hasLeftJoin());
-    assertEquals("people", join.getLeftJoin().getLeft().getTableName());
-    assertEquals("student", join.getLeftJoin().getRight().getTableName());
-  }
-  
-  @Test
-  /**
-   *       join
-   *    /       \
-   * people student
-   */
-  public final void testInnerJoinClause() {
-    QueryBlock block = (QueryBlock) analyzer.parse(JOINS[1]).getParseTree();
-    JoinClause join = block.getJoinClause();
-    assertEquals(JoinType.INNER, join.getJoinType());
-    assertEquals("people", join.getLeft().getTableName());
-    assertEquals("p", join.getLeft().getAlias());
-    assertEquals("student", join.getRight().getTableName());
-    assertEquals("s", join.getRight().getAlias());
-    assertTrue(join.hasJoinQual());
-    assertEquals(EvalNode.Type.EQUAL, join.getJoinQual().getType());
-
-    block = (QueryBlock) analyzer.parse(JOINS[2]).getParseTree();
-    join = block.getJoinClause();
-    assertEquals(JoinType.INNER, join.getJoinType());
-    assertEquals("people", join.getLeft().getTableName());
-    assertEquals("p", join.getLeft().getAlias());
-    assertEquals("student", join.getRight().getTableName());
-    assertEquals("s", join.getRight().getAlias());
-    assertTrue(join.hasJoinColumns());
-    assertEquals("id", join.getJoinColumns()[0].getColumnName());
-  }
-  
-  @Test
-  public final void testJoinClause() {
-    QueryBlock block = (QueryBlock) analyzer.parse(JOINS[6]).getParseTree();
-    JoinClause join = block.getJoinClause();
-    assertEquals(JoinType.INNER, join.getJoinType());
-    assertEquals("people", join.getLeft().getTableName());
-    assertEquals("p", join.getLeft().getAlias());
-    assertEquals("student", join.getRight().getTableName());
-    assertEquals("s", join.getRight().getAlias());
-    assertTrue(join.hasJoinQual());
-    assertEquals(EvalNode.Type.EQUAL, join.getJoinQual().getType());
-  }
-  
-  @Test
-  public final void testCrossJoinClause() {
-    QueryBlock block = (QueryBlock) analyzer.parse(JOINS[3]).getParseTree();
-    JoinClause join = block.getJoinClause();
-    assertEquals(JoinType.CROSS_JOIN, join.getJoinType());
-    assertEquals("branch", join.getRight().getTableName());
-    assertTrue(join.hasLeftJoin());
-    assertEquals("people", join.getLeftJoin().getLeft().getTableName());
-    assertEquals("student", join.getLeftJoin().getRight().getTableName());
-  }
-  
-  @Test
-  public final void testLeftOuterJoinClause() {
-    QueryBlock block = (QueryBlock) analyzer.parse(JOINS[4]).getParseTree();
-    JoinClause join = block.getJoinClause();
-    assertEquals(JoinType.LEFT_OUTER, join.getJoinType());
-    assertEquals("people", join.getLeft().getTableName());
-    assertEquals("p", join.getLeft().getAlias());
-    assertEquals("student", join.getRight().getTableName());
-    assertEquals("s", join.getRight().getAlias());
-    assertTrue(join.hasJoinQual());
-    assertEquals(EvalNode.Type.EQUAL, join.getJoinQual().getType());
-  }
-  
-  @Test
-  public final void testLeftJoinClause() {
-    QueryBlock block = (QueryBlock) analyzer.parse(JOINS[7]).getParseTree();
-    JoinClause join = block.getJoinClause();
-    assertEquals(JoinType.LEFT_OUTER, join.getJoinType());
-    assertEquals("people", join.getLeft().getTableName());
-    assertEquals("p", join.getLeft().getAlias());
-    assertEquals("student", join.getRight().getTableName());
-    assertEquals("s", join.getRight().getAlias());
-    assertTrue(join.hasJoinQual());
-    assertEquals(EvalNode.Type.EQUAL, join.getJoinQual().getType());
-  }
-  
-  @Test
-  public final void testRightOuterJoinClause() {
-    QueryBlock block = (QueryBlock) analyzer.parse(JOINS[5]).getParseTree();
-    JoinClause join = block.getJoinClause();
-    assertEquals(JoinType.RIGHT_OUTER, join.getJoinType());
-    assertEquals("people", join.getLeft().getTableName());
-    assertEquals("p", join.getLeft().getAlias());
-    assertEquals("student", join.getRight().getTableName());
-    assertEquals("s", join.getRight().getAlias());
-    assertTrue(join.hasJoinQual());
-    assertEquals(EvalNode.Type.EQUAL, join.getJoinQual().getType());
-  }
-  
-  @Test
-  public final void testRightJoinClause() {
-    QueryBlock block = (QueryBlock) analyzer.parse(JOINS[8]).getParseTree();
-    JoinClause join = block.getJoinClause();
-    assertEquals(JoinType.RIGHT_OUTER, join.getJoinType());
-    assertEquals("people", join.getLeft().getTableName());
-    assertEquals("p", join.getLeft().getAlias());
-    assertEquals("student", join.getRight().getTableName());
-    assertEquals("s", join.getRight().getAlias());
-    assertTrue(join.hasJoinQual());
-    assertEquals(EvalNode.Type.EQUAL, join.getJoinQual().getType());
-  }
-  
-  private final String [] setClauses = {
-      "select id, people_id from student union select id, people_id from branch",
-      "select id, people_id from student union select id, people_id from branch intersect select id, people_id from branch as b"
-  };
-  
-  @Test
-  public final void testUnionClause() {
-    ParseTree tree = analyzer.parse(setClauses[0]).getParseTree();
-    assertEquals(StatementType.UNION, tree.getType());
-    SetStmt union = (SetStmt) tree;
-    assertEquals(StatementType.SELECT, union.getLeftTree().getType());
-    assertEquals(StatementType.SELECT, union.getRightTree().getType());
-    QueryBlock left = (QueryBlock) union.getLeftTree();
-    assertEquals("student", left.getFromTables()[0].getTableName());
-    QueryBlock right = (QueryBlock) union.getRightTree();
-    assertEquals("branch", right.getFromTables()[0].getTableName());
-    
-    // multiple set statements
-    tree = analyzer.parse(setClauses[1]).getParseTree();
-    assertEquals(StatementType.UNION, tree.getType());
-    union = (SetStmt) tree;
-    assertEquals(StatementType.SELECT, union.getLeftTree().getType());
-    assertEquals(StatementType.INTERSECT, union.getRightTree().getType());
-    left = (QueryBlock) union.getLeftTree();
-    assertEquals("student", left.getFromTables()[0].getTableName());
-    SetStmt rightSet = (SetStmt) union.getRightTree();
-    left = (QueryBlock) rightSet.getLeftTree();
-    assertEquals("branch", left.getFromTables()[0].getTableName());
-    right = (QueryBlock) rightSet.getRightTree();
-    assertEquals("b", right.getFromTables()[0].getAlias());
-  }
-
-  static final String [] setQualifier = {
-      "select id, people_id from student",
-      "select distinct id, people_id from student",
-      "select all id, people_id from student",
-  };
-
-  @Test
-  public final void testSetQulaifier() {
-    ParseTree tree = analyzer.parse(setQualifier[0]).getParseTree();
-    assertEquals(StatementType.SELECT, tree.getType());
-    QueryBlock block = (QueryBlock) tree;
-    assertFalse(block.isDistinct());
-
-    tree = analyzer.parse(setQualifier[1]).getParseTree();
-    assertEquals(StatementType.SELECT, tree.getType());
-    block = (QueryBlock) tree;
-    assertTrue(block.isDistinct());
-
-    tree = analyzer.parse(setQualifier[2]).getParseTree();
-    assertEquals(StatementType.SELECT, tree.getType());
-    block = (QueryBlock) tree;
-    assertFalse(block.isDistinct());
-  }
-
-  @Test
-  public final void testTypeInferring() {
-    QueryBlock block = (QueryBlock) analyzer.parse("select 1 from alltype where char_col = 'a'").getParseTree();
-    assertEquals(TajoDataTypes.Type.CHAR, block.getWhereCondition().getRightExpr().getValueType()[0].getType());
-
-    block = (QueryBlock) analyzer.parse("select 1 from alltype where short_col = 1").getParseTree();
-    assertEquals(TajoDataTypes.Type.INT2, block.getWhereCondition().getRightExpr().getValueType()[0].getType());
-
-    block = (QueryBlock) analyzer.parse("select 1 from alltype where int_col = 1").getParseTree();
-    assertEquals(TajoDataTypes.Type.INT4, block.getWhereCondition().getRightExpr().getValueType()[0].getType());
-
-    block = (QueryBlock) analyzer.parse("select 1 from alltype where long_col = 1").getParseTree();
-    assertEquals(TajoDataTypes.Type.INT8, block.getWhereCondition().getRightExpr().getValueType()[0].getType());
-
-    block = (QueryBlock) analyzer.parse("select 1 from alltype where float_col = 1").getParseTree();
-    assertEquals(TajoDataTypes.Type.INT4, block.getWhereCondition().getRightExpr().getValueType()[0].getType());
-
-    block = (QueryBlock) analyzer.parse("select 1 from alltype where float_col = 1.0").getParseTree();
-    assertEquals(TajoDataTypes.Type.FLOAT4, block.getWhereCondition().getRightExpr().getValueType()[0].getType());
-
-    block = (QueryBlock) analyzer.parse("select 1 from alltype where int_col = 1.0").getParseTree();
-    assertEquals(TajoDataTypes.Type.FLOAT4, block.getWhereCondition().getRightExpr().getValueType()[0].getType());
-
-    block = (QueryBlock) analyzer.parse("select 1 from alltype where double_col = 1.0").getParseTree();
-    assertEquals(TajoDataTypes.Type.FLOAT4, block.getWhereCondition().getRightExpr().getValueType()[0].getType());
-
-    block = (QueryBlock) analyzer.parse("select 1 from alltype where string_col = 'a'").getParseTree();
-    assertEquals(TajoDataTypes.Type.TEXT, block.getWhereCondition().getRightExpr().getValueType()[0].getType());
-  }
-
-  @Test
-  public void testCaseWhen() {
-    ParseTree tree = analyzer.parse(
-        "select case when p_type like 'PROMO%' then l_extendedprice * (1 - l_discount) "+
-        "when p_type = 'MOCC' then l_extendedprice - 100 else 0 end as cond from lineitem, part").getParseTree();
-    assertEquals(StatementType.SELECT, tree.getType());
-    QueryBlock block = (QueryBlock) tree;
-    assertTrue(block.getTargetList()[0].hasAlias());
-    assertEquals("cond", block.getTargetList()[0].getAlias());
-    assertEquals(TajoDataTypes.Type.FLOAT8, block.getTargetList()[0].getEvalTree().getValueType()[0].getType());
-  }
-
-  @Test
-  public void testTarget() throws CloneNotSupportedException {
-    QueryBlock.Target t1 = new QueryBlock.Target(new ConstEval(DatumFactory.createInt4(5)), 0);
-    QueryBlock.Target t2 = (QueryBlock.Target) t1.clone();
-    assertEquals(t1,t2);
-  }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/00c3ee2b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java
new file mode 100644
index 0000000..549cd1e
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/parser/TestSQLAnalyzer.java
@@ -0,0 +1,297 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.engine.parser;
+
+import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.apache.tajo.algebra.Expr;
+import org.apache.tajo.engine.parser.SQLParser.Boolean_value_expressionContext;
+import org.apache.tajo.engine.parser.SQLParser.SqlContext;
+import org.apache.tajo.util.FileUtil;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * This unit tests uses a number of query files located in tajo/tajo-core/tajo-core-backend/test/queries.
+ * So, you must set tajo/tajo-core/tajo-core-backend as the working directory.
+ */
+public class TestSQLAnalyzer {
+
+  public static Expr parseQuery(String sql) {
+    ANTLRInputStream input = new ANTLRInputStream(sql);
+    SQLLexer lexer = new SQLLexer(input);
+    CommonTokenStream tokens = new CommonTokenStream(lexer);
+    SQLParser parser = new SQLParser(tokens);
+    parser.setBuildParseTree(true);
+    SQLAnalyzer visitor = new SQLAnalyzer();
+    SqlContext context = parser.sql();
+    return visitor.visitSql(context);
+  }
+
+
+  @Test
+  public void testSelect1() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/select_1.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testSelect2() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/select_2.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testSelect3() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/select_3.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testSelect4() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/select_4.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testSelect5() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/select_5.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testInsert1() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/insert_1.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testInsert2() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/insert_2.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testGroupby1() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/groupby_1.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testJoin1() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/join_1.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testJoin2() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/join_2.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testJoin3() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/join_3.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testJoin4() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/join_4.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testJoin5() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/join_5.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testJoin6() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/join_6.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testJoin7() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/join_7.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testJoin8() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/join_8.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testJoin9() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/join_9.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testJoin10() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/join_10.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testJoin11() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/join_11.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testSet1() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/set_1.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testSet2() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/set_2.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testSet3() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/set_3.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testDropTable() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/drop_table.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testCreateTable1() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/create_table_1.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testCreateTable2() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/create_table_2.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testCreateTable3() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/create_table_3.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testCreateTable4() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/create_table_4.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testCreateTable5() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/create_table_5.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testCreateTable6() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/create_table_6.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testCreateTable7() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/create_table_7.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testCreateTable8() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/create_table_8.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testCreateTable9() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/create_table_9.sql"));
+    parseQuery(sql);
+  }
+
+  @Test
+  public void testCreateTable10() throws IOException {
+    String sql = FileUtil.readTextFile(new File("src/test/queries/create_table_10.sql"));
+    parseQuery(sql);
+  }
+
+  static String[] exprs = {
+      "1 + 2", // 0
+      "3 - 4", // 1
+      "5 * 6", // 2
+      "7 / 8", // 3
+      "10 % 2", // 4
+      "1 * 2 > 3 / 4", // 5
+      "1 * 2 < 3 / 4", // 6
+      "1 * 2 = 3 / 4", // 7
+      "1 * 2 != 3 / 4", // 8
+      "1 * 2 <> 3 / 4", // 9
+      "gender in ('male', 'female')", // 10
+      "gender not in ('male', 'female')", // 11
+      "score > 90 and age < 20", // 12
+      "score > 90 and age < 20 and name != 'hyunsik'", // 13
+      "score > 90 or age < 20", // 14
+      "score > 90 or age < 20 and name != 'hyunsik'", // 15
+      "((a+3 > 1) or 1=1) and (3 != (abc + 4) and type in (3,4))", // 16
+      "3", // 17
+      "1.2", // 18
+      "sum(age)", // 19
+      "now()", // 20
+      "not (90 > 100)", // 21
+      "type like '%top'", // 22
+      "type not like 'top%'", // 23
+      "col = 'value'", // 24
+      "col is null", // 25
+      "col is not null", // 26
+      "col = null", // 27
+      "col != null" // 38
+  };
+
+  public static Expr parseExpr(String sql) {
+    ANTLRInputStream input = new ANTLRInputStream(sql);
+    SQLLexer lexer = new SQLLexer(input);
+    CommonTokenStream tokens = new CommonTokenStream(lexer);
+    SQLParser parser = new SQLParser(tokens);
+    parser.setBuildParseTree(true);
+    SQLAnalyzer visitor = new SQLAnalyzer();
+    Boolean_value_expressionContext context = parser.boolean_value_expression();
+    return visitor.visitBoolean_value_expression(context);
+  }
+
+  @Test
+  public void testExprs() {
+    for (int i = 0; i < exprs.length; i++) {
+      parseExpr(exprs[i]);
+    }
+  }
+}


Mime
View raw message