tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [05/50] [abbrv] git commit: TAJO-854: Supports INSERT INTO with UNION. (Hyoungjun Kim via jihoon)
Date Wed, 09 Jul 2014 04:10:22 GMT
TAJO-854: Supports INSERT INTO with UNION. (Hyoungjun Kim via jihoon)


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

Branch: refs/heads/window_function
Commit: f7810074378823cf70114d31548f52c08c63f7c5
Parents: d365e9e
Author: Jihoon Son <jihoonson@apache.org>
Authored: Mon Jun 2 17:56:19 2014 +0900
Committer: Jihoon Son <jihoonson@apache.org>
Committed: Mon Jun 2 17:56:19 2014 +0900

----------------------------------------------------------------------
 CHANGES                                         |  2 +
 .../apache/tajo/engine/planner/LogicalPlan.java | 10 ++
 .../tajo/engine/planner/LogicalPlanner.java     | 58 +++++++++++-
 .../engine/planner/global/GlobalPlanner.java    | 55 ++++++++++-
 .../java/org/apache/tajo/QueryTestCaseBase.java | 59 ++++++++++++
 .../tajo/engine/query/TestInsertQuery.java      | 96 ++++++++++++++++++++
 .../tajo/engine/query/TestUnionQuery.java       | 14 +++
 .../queries/TestCaseByCases/testTAJO418Case.sql |  2 +-
 .../testInsertOverwriteLocationWithUnion.sql    |  4 +
 ...verwriteLocationWithUnionDifferenceAlias.sql |  4 +
 .../testInsertOverwriteWithUnion.sql            |  4 +
 ...stInsertOverwriteWithUnionDifferentAlias.sql |  4 +
 .../testUnionWithDifferentAlias.sql             | 29 ++++++
 .../testUnionWithDifferentAliasAndFunction.sql  | 29 ++++++
 .../TestCaseByCases/testTAJO418Case.result      |  1 +
 .../testUnionWithDifferentAlias.result          |  4 +
 ...estUnionWithDifferentAliasAndFunction.result |  7 ++
 17 files changed, 373 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index b5f5189..84a83e8 100644
--- a/CHANGES
+++ b/CHANGES
@@ -15,6 +15,8 @@ Release 0.9.0 - unreleased
 
   IMPROVEMENT
 
+    TAJO-854: Supports INSERT INTO with UNION. (Hyoungjun Kim via jihoon)
+
     TAJO-793: CLI should be able to exit when single query is failed.
     (Hyoungjun Kim via jinho)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java b/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
index 519f594..6d3f15f 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
@@ -217,6 +217,10 @@ public class LogicalPlan {
     }
   }
 
+  public void disconnectBlocks(QueryBlock srcBlock, QueryBlock targetBlock) {
+    queryBlockGraph.removeEdge(srcBlock.getName(), targetBlock.getName());
+  }
+
   public void connectBlocks(QueryBlock srcBlock, QueryBlock targetBlock, BlockType type)
{
     queryBlockGraph.addEdge(srcBlock.getName(), targetBlock.getName(), new BlockEdge(srcBlock,
targetBlock, type));
   }
@@ -743,6 +747,12 @@ public class LogicalPlan {
       queryBlockByPID.put(node.getPID(), this);
     }
 
+    public void unregisterNode(LogicalNode node) {
+      nodeMap.remove(node.getPID());
+      nodeTypeToNodeMap.remove(node.getType());
+      queryBlockByPID.remove(node.getPID());
+    }
+
     @SuppressWarnings("unchecked")
     public <T extends LogicalNode> T getNode(NodeType nodeType) {
       return (T) nodeTypeToNodeMap.get(nodeType);

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java b/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
index 76dae24..b19efe1 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
@@ -1218,7 +1218,7 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
       }
       insertNode.setTargetSchema(targetColumns);
       insertNode.setOutSchema(targetColumns);
-      buildProjectedInsert(insertNode);
+      buildProjectedInsert(context, insertNode);
 
     } else { // when a user do not specified target columns
 
@@ -1231,7 +1231,7 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
         targetColumns.addColumn(tableSchema.getColumn(i));
       }
       insertNode.setTargetSchema(targetColumns);
-      buildProjectedInsert(insertNode);
+      buildProjectedInsert(context, insertNode);
     }
 
     if (desc.hasPartition()) {
@@ -1240,11 +1240,16 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
     return insertNode;
   }
 
-  private void buildProjectedInsert(InsertNode insertNode) {
+  private void buildProjectedInsert(PlanContext context, InsertNode insertNode) {
     Schema tableSchema = insertNode.getTableSchema();
     Schema targetColumns = insertNode.getTargetSchema();
 
     LogicalNode child = insertNode.getChild();
+
+    if (child.getType() == NodeType.UNION) {
+      child = makeProjectionForInsertUnion(context, insertNode);
+    }
+
     if (child instanceof Projectable) {
       Projectable projectionNode = (Projectable) insertNode.getChild();
 
@@ -1270,6 +1275,45 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
     }
   }
 
+  private ProjectionNode makeProjectionForInsertUnion(PlanContext context, InsertNode insertNode)
{
+    LogicalNode child = insertNode.getChild();
+    // add (projection - subquery) to RootBlock and create new QueryBlock for UnionNode
+    TableSubQueryNode subQueryNode = context.plan.createNode(TableSubQueryNode.class);
+    subQueryNode.init(context.queryBlock.getName(), child);
+    subQueryNode.setTargets(PlannerUtil.schemaToTargets(subQueryNode.getOutSchema()));
+
+    ProjectionNode projectionNode = context.plan.createNode(ProjectionNode.class);
+    projectionNode.setChild(subQueryNode);
+    projectionNode.setInSchema(subQueryNode.getInSchema());
+    projectionNode.setTargets(subQueryNode.getTargets());
+
+    context.queryBlock.registerNode(projectionNode);
+    context.queryBlock.registerNode(subQueryNode);
+
+    // add child QueryBlock to the UnionNode's QueryBlock
+    UnionNode unionNode = (UnionNode)child;
+    context.queryBlock.unregisterNode(unionNode);
+
+    QueryBlock unionBlock = context.plan.newQueryBlock();
+    unionBlock.registerNode(unionNode);
+    unionBlock.setRoot(unionNode);
+
+    QueryBlock leftBlock = context.plan.getBlock(unionNode.getLeftChild());
+    QueryBlock rightBlock = context.plan.getBlock(unionNode.getRightChild());
+
+    context.plan.disconnectBlocks(leftBlock, context.queryBlock);
+    context.plan.disconnectBlocks(rightBlock, context.queryBlock);
+
+    context.plan.connectBlocks(unionBlock, context.queryBlock, BlockType.TableSubQuery);
+    context.plan.connectBlocks(leftBlock, unionBlock, BlockType.TableSubQuery);
+    context.plan.connectBlocks(rightBlock, unionBlock, BlockType.TableSubQuery);
+
+    // set InsertNode's child with ProjectionNode which is created.
+    insertNode.setChild(projectionNode);
+
+    return projectionNode;
+  }
+
   /**
    * Build a InsertNode with a location.
    *
@@ -1278,7 +1322,13 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
   private InsertNode buildInsertIntoLocationPlan(PlanContext context, InsertNode insertNode,
Insert expr) {
     // INSERT (OVERWRITE)? INTO LOCATION path (USING file_type (param_clause)?)? query_expression
 
-    Schema childSchema = insertNode.getChild().getOutSchema();
+    LogicalNode child = insertNode.getChild();
+
+    if (child.getType() == NodeType.UNION) {
+      child = makeProjectionForInsertUnion(context, insertNode);
+    }
+
+    Schema childSchema = child.getOutSchema();
     insertNode.setInSchema(childSchema);
     insertNode.setOutSchema(childSchema);
     insertNode.setTableSchema(childSchema);

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
b/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
index 16def83..536dbd8 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
@@ -31,10 +31,7 @@ import org.apache.tajo.catalog.partition.PartitionMethodDesc;
 import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.conf.TajoConf;
-import org.apache.tajo.engine.eval.AggregationFunctionCallEval;
-import org.apache.tajo.engine.eval.EvalNode;
-import org.apache.tajo.engine.eval.EvalTreeUtil;
-import org.apache.tajo.engine.eval.FieldEval;
+import org.apache.tajo.engine.eval.*;
 import org.apache.tajo.engine.function.AggFunction;
 import org.apache.tajo.engine.planner.*;
 import org.apache.tajo.engine.planner.global.builder.DistinctGroupbyBuilder;
@@ -1195,10 +1192,60 @@ public class GlobalPlanner {
       ExecutionBlock currentBlock = context.execBlockMap.remove(child.getPID());
 
       if (child.getType() == NodeType.UNION) {
+        List<TableSubQueryNode> addedTableSubQueries = new ArrayList<TableSubQueryNode>();
+        TableSubQueryNode leftMostSubQueryNode = null;
         for (ExecutionBlock childBlock : context.plan.getChilds(currentBlock.getId())) {
           TableSubQueryNode copy = PlannerUtil.clone(plan, node);
           copy.setSubQuery(childBlock.getPlan());
           childBlock.setPlan(copy);
+          addedTableSubQueries.add(copy);
+
+          //Find a SubQueryNode which contains all columns in InputSchema matched with Target
and OutputSchema's column
+          if (copy.getInSchema().containsAll(copy.getOutSchema().getColumns())) {
+            for (Target eachTarget : copy.getTargets()) {
+              Set<Column> columns = EvalTreeUtil.findUniqueColumns(eachTarget.getEvalTree());
+              if (copy.getInSchema().containsAll(columns)) {
+                leftMostSubQueryNode = copy;
+                break;
+              }
+            }
+          }
+        }
+
+        if (leftMostSubQueryNode != null) {
+          // replace target column name
+          Target[] targets = leftMostSubQueryNode.getTargets();
+          int[] targetMappings = new int[targets.length];
+          for (int i = 0; i < targets.length; i++) {
+            if (targets[i].getEvalTree().getType() != EvalType.FIELD) {
+              throw new PlanningException("Target of a UnionNode's subquery should be FieldEval.");
+            }
+            int index = leftMostSubQueryNode.getInSchema().getColumnId(targets[i].getNamedColumn().getQualifiedName());
+            targetMappings[i] = index;
+          }
+
+          for (TableSubQueryNode eachNode: addedTableSubQueries) {
+            if (eachNode.getPID() == leftMostSubQueryNode.getPID()) {
+              continue;
+            }
+            Target[] eachNodeTargets = eachNode.getTargets();
+            if (eachNodeTargets.length != targetMappings.length) {
+              throw new PlanningException("Union query can't have different number of target
columns.");
+            }
+            for (int i = 0; i < eachNodeTargets.length; i++) {
+              Column inColumn = eachNode.getInSchema().getColumn(targetMappings[i]);
+              eachNodeTargets[i].setAlias(eachNodeTargets[i].getNamedColumn().getQualifiedName());
+              EvalNode evalNode = eachNodeTargets[i].getEvalTree();
+              if (evalNode.getType() != EvalType.FIELD) {
+                throw new PlanningException("Target of a UnionNode's subquery should be FieldEval.");
+              }
+              FieldEval fieldEval = (FieldEval) evalNode;
+              EvalTreeUtil.changeColumnRef(fieldEval,
+                  fieldEval.getColumnRef().getQualifiedName(), inColumn.getQualifiedName());
+            }
+          }
+        } else {
+          LOG.warn("Can't find left most SubQuery in the UnionNode.");
         }
       } else {
         currentBlock.setPlan(node);

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
index d68eb5f..1d7d0ff 100644
--- a/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
+++ b/tajo-core/src/test/java/org/apache/tajo/QueryTestCaseBase.java
@@ -21,6 +21,7 @@ package org.apache.tajo;
 import com.google.protobuf.ServiceException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.tajo.algebra.*;
@@ -40,6 +41,7 @@ import org.junit.rules.TestName;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
@@ -553,4 +555,61 @@ public class QueryTestCaseBase {
     }
     return result;
   }
+
+  /**
+   * Reads data file from Test Cluster's HDFS
+   * @param path data parent path
+   * @return data file's contents
+   * @throws Exception
+   */
+  public String getTableFileContents(Path path) throws Exception {
+    FileSystem fs = path.getFileSystem(conf);
+
+    FileStatus[] files = fs.listStatus(path);
+
+    if (files == null || files.length == 0) {
+      return null;
+    }
+
+    StringBuilder sb = new StringBuilder();
+    byte[] buf = new byte[1024];
+
+    for (FileStatus file: files) {
+      if (file.isDirectory()) {
+        continue;
+      }
+
+      InputStream in = fs.open(file.getPath());
+      try {
+        while (true) {
+          int readBytes = in.read(buf);
+          if (readBytes <= 0) {
+            break;
+          }
+
+          sb.append(new String(buf, 0, readBytes));
+        }
+      } finally {
+        in.close();
+      }
+    }
+
+    return sb.toString();
+  }
+
+  /**
+   * Reads data file from Test Cluster's HDFS
+   * @param tableName
+   * @return data file's contents
+   * @throws Exception
+   */
+  public String getTableFileContents(String tableName) throws Exception {
+    TableDesc tableDesc = testingCluster.getMaster().getCatalog().getTableDesc(getCurrentDatabase(),
tableName);
+    if (tableDesc == null) {
+      return null;
+    }
+
+    Path path = tableDesc.getPath();
+    return getTableFileContents(path);
+  }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java
index 3aacbff..890159c 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestInsertQuery.java
@@ -384,4 +384,100 @@ public class TestInsertQuery extends QueryTestCaseBase {
       reader.close();
     }
   }
+
+  @Test
+  public final void testInsertOverwriteWithUnion() throws Exception {
+    ResultSet res = executeFile("table1_ddl.sql");
+    res.close();
+
+    CatalogService catalog = testingCluster.getMaster().getCatalog();
+    assertTrue(catalog.existsTable(getCurrentDatabase(), "table1"));
+
+    res = executeFile("testInsertOverwriteWithUnion.sql");
+    res.close();
+
+    String tableDatas = getTableFileContents("table1");
+
+    String expected = "1|1|17.0\n" +
+        "1|1|36.0\n" +
+        "2|2|38.0\n" +
+        "3|2|45.0\n" +
+        "3|3|49.0\n" +
+        "1|3|173665.47\n" +
+        "2|4|46929.18\n" +
+        "3|2|193846.25\n";
+
+    assertNotNull(tableDatas);
+    assertEquals(expected, tableDatas);
+
+    executeString("DROP TABLE table1 PURGE");
+  }
+
+  @Test
+  public final void testInsertOverwriteWithUnionDifferentAlias() throws Exception {
+    ResultSet res = executeFile("table1_ddl.sql");
+    res.close();
+
+    CatalogService catalog = testingCluster.getMaster().getCatalog();
+    assertTrue(catalog.existsTable(getCurrentDatabase(), "table1"));
+
+    res = executeFile("testInsertOverwriteWithUnionDifferentAlias.sql");
+    res.close();
+
+    String tableDatas = getTableFileContents("table1");
+
+    String expected = "1|1|17.0\n" +
+        "1|1|36.0\n" +
+        "2|2|38.0\n" +
+        "3|2|45.0\n" +
+        "3|3|49.0\n" +
+        "1|3|173665.47\n" +
+        "2|4|46929.18\n" +
+        "3|2|193846.25\n";
+
+    assertNotNull(tableDatas);
+    assertEquals(expected, tableDatas);
+
+    executeString("DROP TABLE table1 PURGE");
+  }
+
+  @Test
+  public final void testInsertOverwriteLocationWithUnion() throws Exception {
+    ResultSet res = executeFile("testInsertOverwriteLocationWithUnion.sql");
+    res.close();
+
+    String resultDatas= getTableFileContents(new Path("/tajo-data/testInsertOverwriteLocationWithUnion"));
+
+    String expected = "1|1|17.0\n" +
+        "1|1|36.0\n" +
+        "2|2|38.0\n" +
+        "3|2|45.0\n" +
+        "3|3|49.0\n" +
+        "1|3|173665.47\n" +
+        "2|4|46929.18\n" +
+        "3|2|193846.25\n";
+
+    assertNotNull(resultDatas);
+    assertEquals(expected, resultDatas);
+  }
+
+  @Test
+  public final void testInsertOverwriteLocationWithUnionDifferenceAlias() throws Exception
{
+    ResultSet res = executeFile("testInsertOverwriteLocationWithUnionDifferenceAlias.sql");
+    res.close();
+
+    String resultDatas= getTableFileContents(new Path("/tajo-data/testInsertOverwriteLocationWithUnionDifferenceAlias"));
+
+    String expected = "1|1|17.0\n" +
+        "1|1|36.0\n" +
+        "2|2|38.0\n" +
+        "3|2|45.0\n" +
+        "3|3|49.0\n" +
+        "1|3|173665.47\n" +
+        "2|4|46929.18\n" +
+        "3|2|193846.25\n";
+
+    assertNotNull(resultDatas);
+    assertEquals(expected, resultDatas);
+  }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java
index 5845ba8..857cb63 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java
@@ -191,4 +191,18 @@ public class TestUnionQuery extends QueryTestCaseBase {
     assertResultSet(res);
     cleanupQuery(res);
   }
+
+  @Test
+  public final void testUnionWithDifferentAlias() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
+
+  @Test
+  public final void testUnionWithDifferentAliasAndFunction() throws Exception {
+    ResultSet res = executeQuery();
+    assertResultSet(res);
+    cleanupQuery(res);
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/test/resources/queries/TestCaseByCases/testTAJO418Case.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestCaseByCases/testTAJO418Case.sql b/tajo-core/src/test/resources/queries/TestCaseByCases/testTAJO418Case.sql
index b3ad48a..2e62923 100644
--- a/tajo-core/src/test/resources/queries/TestCaseByCases/testTAJO418Case.sql
+++ b/tajo-core/src/test/resources/queries/TestCaseByCases/testTAJO418Case.sql
@@ -8,7 +8,7 @@ FROM (
   FROM
     lineitem
   WHERE
-    l_returnflag = 'K'
+    l_returnflag = 'N'
 
   UNION ALL
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteLocationWithUnion.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteLocationWithUnion.sql
b/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteLocationWithUnion.sql
new file mode 100644
index 0000000..65bab10
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteLocationWithUnion.sql
@@ -0,0 +1,4 @@
+insert overwrite into location '/tajo-data/testInsertOverwriteLocationWithUnion'
+select l_orderkey as col1, l_partkey as col2, l_quantity as col3 from default.lineitem
+union all
+select o_orderkey as col1, o_custkey as col2, o_totalprice as col3 from default.orders
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteLocationWithUnionDifferenceAlias.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteLocationWithUnionDifferenceAlias.sql
b/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteLocationWithUnionDifferenceAlias.sql
new file mode 100644
index 0000000..cbd7a94
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteLocationWithUnionDifferenceAlias.sql
@@ -0,0 +1,4 @@
+insert overwrite into location '/tajo-data/testInsertOverwriteLocationWithUnionDifferenceAlias'
+select l_orderkey as col1, l_partkey as col2, l_quantity as col3 from default.lineitem
+union all
+select o_orderkey as col4, o_custkey as col5, o_totalprice as col6 from default.orders
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteWithUnion.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteWithUnion.sql
b/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteWithUnion.sql
new file mode 100644
index 0000000..843d24c
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteWithUnion.sql
@@ -0,0 +1,4 @@
+insert overwrite into table1
+select l_orderkey as col1, l_partkey as col2, l_quantity as col3 from default.lineitem
+union all
+select o_orderkey as col1, o_custkey as col2, o_totalprice as col3 from default.orders
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteWithUnionDifferentAlias.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteWithUnionDifferentAlias.sql
b/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteWithUnionDifferentAlias.sql
new file mode 100644
index 0000000..1660eb5
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestInsertQuery/testInsertOverwriteWithUnionDifferentAlias.sql
@@ -0,0 +1,4 @@
+insert overwrite into table1
+select l_orderkey as col1, l_partkey as col2, l_quantity as col3 from default.lineitem
+union all
+select o_orderkey as col4, o_custkey as col5, o_totalprice as col6 from default.orders
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/test/resources/queries/TestUnionQuery/testUnionWithDifferentAlias.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestUnionQuery/testUnionWithDifferentAlias.sql
b/tajo-core/src/test/resources/queries/TestUnionQuery/testUnionWithDifferentAlias.sql
new file mode 100644
index 0000000..f41ee32
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestUnionQuery/testUnionWithDifferentAlias.sql
@@ -0,0 +1,29 @@
+SELECT
+  col1,
+  col2
+
+FROM (
+  SELECT
+    l_returnflag col1, l_linestatus col2, l_orderkey col3
+  FROM
+    lineitem
+  WHERE
+    l_returnflag = 'N'
+
+  UNION ALL
+
+  SELECT
+    l_returnflag col2, l_linestatus col5, l_orderkey col6
+  FROM
+    lineitem
+  WHERE
+    l_returnflag = 'R'
+) T
+
+GROUP BY
+  col1,
+	col2
+
+ORDER BY
+  col1,
+	col2
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/test/resources/queries/TestUnionQuery/testUnionWithDifferentAliasAndFunction.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestUnionQuery/testUnionWithDifferentAliasAndFunction.sql
b/tajo-core/src/test/resources/queries/TestUnionQuery/testUnionWithDifferentAliasAndFunction.sql
new file mode 100644
index 0000000..598f399
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestUnionQuery/testUnionWithDifferentAliasAndFunction.sql
@@ -0,0 +1,29 @@
+SELECT
+  col1,
+  col2
+
+FROM (
+  SELECT
+    l_returnflag col1, concat(l_linestatus, l_shipdate) col2, l_orderkey col3
+  FROM
+    lineitem
+  WHERE
+    l_returnflag = 'N'
+
+  UNION ALL
+
+  SELECT
+    concat(l_returnflag, l_shipdate) col3, l_linestatus col4, l_orderkey col5
+  FROM
+    lineitem
+  WHERE
+    l_returnflag = 'R'
+) T
+
+GROUP BY
+  col1,
+	col2
+
+ORDER BY
+  col1,
+	col2
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/test/resources/results/TestCaseByCases/testTAJO418Case.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestCaseByCases/testTAJO418Case.result b/tajo-core/src/test/resources/results/TestCaseByCases/testTAJO418Case.result
index ba35aa1..d78067e 100644
--- a/tajo-core/src/test/resources/results/TestCaseByCases/testTAJO418Case.result
+++ b/tajo-core/src/test/resources/results/TestCaseByCases/testTAJO418Case.result
@@ -1,3 +1,4 @@
 l_returnflag,l_linestatus
 -------------------------------
+N,O
 R,F
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/test/resources/results/TestUnionQuery/testUnionWithDifferentAlias.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestUnionQuery/testUnionWithDifferentAlias.result
b/tajo-core/src/test/resources/results/TestUnionQuery/testUnionWithDifferentAlias.result
new file mode 100644
index 0000000..7415ec4
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestUnionQuery/testUnionWithDifferentAlias.result
@@ -0,0 +1,4 @@
+col1,col2
+-------------------------------
+N,O
+R,F
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/f7810074/tajo-core/src/test/resources/results/TestUnionQuery/testUnionWithDifferentAliasAndFunction.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestUnionQuery/testUnionWithDifferentAliasAndFunction.result
b/tajo-core/src/test/resources/results/TestUnionQuery/testUnionWithDifferentAliasAndFunction.result
new file mode 100644
index 0000000..7e6f6cd
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestUnionQuery/testUnionWithDifferentAliasAndFunction.result
@@ -0,0 +1,7 @@
+col1,col2
+-------------------------------
+N,O1996-03-13
+N,O1996-04-12
+N,O1997-01-28
+R1993-11-09,F
+R1994-02-02,F
\ No newline at end of file


Mime
View raw message