drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amansi...@apache.org
Subject drill git commit: DRILL-2207: Union RelOperator supports different types to be unioned together by casting; Disable Union-all on Select * from schemaless data source
Date Tue, 10 Mar 2015 01:50:57 GMT
Repository: drill
Updated Branches:
  refs/heads/master f658a3c51 -> 0368adf0c


DRILL-2207: Union RelOperator supports different types to be unioned together by casting; Disable Union-all on  Select * from schemaless data source


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

Branch: refs/heads/master
Commit: 0368adf0cdf6ba229e273b0e41c5c564735c95ee
Parents: f658a3c
Author: Hsuan-Yi Chu <hsuanyi@usc.edu>
Authored: Wed Feb 11 18:29:09 2015 -0800
Committer: Hsuan-Yi Chu <hsuanyi@usc.edu>
Committed: Mon Mar 9 18:12:37 2015 -0700

----------------------------------------------------------------------
 .../exec/expr/ExpressionTreeMaterializer.java   |  19 +-
 .../impl/union/UnionAllRecordBatch.java         | 484 +++++++++++++++----
 .../exec/physical/impl/union/UnionAller.java    |  33 ++
 .../physical/impl/union/UnionAllerTemplate.java |  60 +++
 .../exec/planner/common/DrillRelOptUtil.java    |   2 +-
 .../planner/logical/PreProcessLogicalRel.java   |  21 +-
 .../physical/visitor/FinalColumnReorderer.java  |  28 +-
 .../sql/parser/UnsupportedOperatorsVisitor.java |   9 +-
 .../drill/exec/record/VectorContainer.java      |   1 -
 .../drill/exec/resolver/TypeCastRules.java      |  20 +-
 .../org/apache/drill/TestExampleQueries.java    |   1 -
 .../java/org/apache/drill/TestUnionAll.java     | 312 +++++++++++-
 .../src/test/resources/store/text/data/t.json   |  10 +
 .../testAggregationOnUnionAllOperator/q1.tsv    |   4 +
 .../testAggregationOnUnionAllOperator/q2.tsv    |   4 +
 .../testframework/testUnionAllQueries/q1.tsv    |  30 ++
 .../testframework/testUnionAllQueries/q10.tsv   |  30 ++
 .../testframework/testUnionAllQueries/q11.tsv   |  30 ++
 .../testframework/testUnionAllQueries/q12.tsv   |  30 ++
 .../testframework/testUnionAllQueries/q13.tsv   |  20 +
 .../testframework/testUnionAllQueries/q14.tsv   |  30 ++
 .../testframework/testUnionAllQueries/q15.tsv   |  10 +
 .../testframework/testUnionAllQueries/q16.tsv   |   5 +
 .../testframework/testUnionAllQueries/q17.tsv   |   5 +
 .../testframework/testUnionAllQueries/q2.tsv    |   4 +
 .../testframework/testUnionAllQueries/q3.tsv    |   7 +
 .../testframework/testUnionAllQueries/q4.tsv    |  59 +++
 .../testframework/testUnionAllQueries/q5.tsv    |  10 +
 .../testframework/testUnionAllQueries/q6.tsv    |   6 +
 .../testframework/testUnionAllQueries/q6_1.tsv  |  30 ++
 .../testframework/testUnionAllQueries/q7.tsv    |  10 +
 .../testframework/testUnionAllQueries/q8.tsv    |  30 ++
 .../testframework/testUnionAllQueries/q9.tsv    |  20 +
 33 files changed, 1252 insertions(+), 122 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
index 3565bf4..0ac3e30 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/ExpressionTreeMaterializer.java
@@ -102,6 +102,23 @@ public class ExpressionTreeMaterializer {
     }
   }
 
+  public static LogicalExpression convertToNullableType(LogicalExpression fromExpr, MinorType toType, FunctionImplementationRegistry registry, ErrorCollector errorCollector) {
+    String funcName = "convertToNullable" + toType.toString();
+    List<LogicalExpression> args = Lists.newArrayList();
+    args.add(fromExpr);
+    FunctionCall funcCall = new FunctionCall(funcName, args, ExpressionPosition.UNKNOWN);
+    FunctionResolver resolver = FunctionResolverFactory.getResolver(funcCall);
+
+    DrillFuncHolder matchedConvertToNullableFuncHolder = registry.findDrillFunction(resolver, funcCall);
+    if (matchedConvertToNullableFuncHolder == null) {
+      logFunctionResolutionError(errorCollector, funcCall);
+      return NullExpression.INSTANCE;
+    }
+
+    return matchedConvertToNullableFuncHolder.getExpr(funcName, args, ExpressionPosition.UNKNOWN);
+  }
+
+
   public static LogicalExpression addCastExpression(LogicalExpression fromExpr, MajorType toType, FunctionImplementationRegistry registry, ErrorCollector errorCollector) {
     String castFuncName = CastFunctions.getCastFunc(toType.getMinorType());
     List<LogicalExpression> castArgs = Lists.newArrayList();
@@ -198,7 +215,7 @@ public class ExpressionTreeMaterializer {
       return new BooleanOperator(op.getName(), args, op.getPosition());
     }
 
-   @Override
+    @Override
     public LogicalExpression visitFunctionCall(FunctionCall call, FunctionImplementationRegistry registry) {
       List<LogicalExpression> args = Lists.newArrayList();
       for (int i = 0; i < call.args.size(); ++i) {

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAllRecordBatch.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAllRecordBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAllRecordBatch.java
index 99aec92..806104a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAllRecordBatch.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAllRecordBatch.java
@@ -17,149 +17,449 @@
  */
 package org.apache.drill.exec.physical.impl.union;
 
-import java.util.ArrayList;
+import java.io.IOException;
 import java.util.Iterator;
 import java.util.List;
-
+import com.google.common.collect.Lists;
+import org.apache.drill.common.exceptions.DrillRuntimeException;
+import org.apache.drill.common.expression.ErrorCollector;
+import org.apache.drill.common.expression.ErrorCollectorImpl;
+import org.apache.drill.common.expression.LogicalExpression;
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.TypeProtos.MinorType;
+import org.apache.drill.common.types.TypeProtos.DataMode;
+import org.apache.drill.exec.exception.ClassTransformationException;
 import org.apache.drill.exec.exception.SchemaChangeException;
+import org.apache.drill.exec.expr.ClassGenerator;
+import org.apache.drill.exec.expr.CodeGenerator;
+import org.apache.drill.exec.expr.ExpressionTreeMaterializer;
+import org.apache.drill.exec.expr.ValueVectorReadExpression;
+import org.apache.drill.exec.expr.ValueVectorWriteExpression;
 import org.apache.drill.exec.memory.OutOfMemoryException;
 import org.apache.drill.exec.ops.FragmentContext;
-import org.apache.drill.exec.physical.config.UnionAll;
 import org.apache.drill.exec.record.AbstractRecordBatch;
 import org.apache.drill.exec.record.BatchSchema;
+import org.apache.drill.exec.record.MaterializedField;
 import org.apache.drill.exec.record.RecordBatch;
 import org.apache.drill.exec.record.TransferPair;
+import org.apache.drill.exec.record.TypedFieldId;
 import org.apache.drill.exec.record.VectorWrapper;
 import org.apache.drill.exec.record.WritableBatch;
 import org.apache.drill.exec.record.selection.SelectionVector2;
-
-import com.google.common.collect.Lists;
+import org.apache.drill.exec.record.selection.SelectionVector4;
+import org.apache.drill.exec.resolver.TypeCastRules;
+import org.apache.drill.exec.vector.AllocationHelper;
+import org.apache.drill.exec.vector.FixedWidthVector;
+import org.apache.drill.exec.vector.SchemaChangeCallBack;
+import org.apache.drill.exec.vector.ValueVector;
+import org.apache.drill.exec.physical.config.UnionAll;
 
 public class UnionAllRecordBatch extends AbstractRecordBatch<UnionAll> {
+  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(UnionAllRecordBatch.class);
 
-  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(UnionAllRecordBatch.class);
+  private List<MaterializedField> outputFields;
+  private UnionAller unionall;
+  private UnionAllInput unionAllInput;
+  private RecordBatch current;
 
-  private final List<RecordBatch> incoming;
-  private SelectionVector2 sv;
-  private Iterator<RecordBatch> incomingIterator = null;
-  private RecordBatch current = null;
-  private ArrayList<TransferPair> transfers;
-  private int outRecordCount;
+  private final List<TransferPair> transfers = Lists.newArrayList();
+  private List<ValueVector> allocationVectors;
+  protected SchemaChangeCallBack callBack = new SchemaChangeCallBack();
+  private int recordCount = 0;
+  private boolean schemaAvailable = false;
 
   public UnionAllRecordBatch(UnionAll config, List<RecordBatch> children, FragmentContext context) throws OutOfMemoryException {
     super(config, context, false);
-    this.incoming = children;
-    this.incomingIterator = incoming.iterator();
-    current = incomingIterator.next();
-    sv = null;
+    assert (children.size() == 2) : "The number of the operands of Union must be 2";
+    unionAllInput = new UnionAllInput(this, children.get(0), children.get(1));
   }
 
   @Override
   public int getRecordCount() {
-    return outRecordCount;
-  }
-
-  @Override
-  public void kill(boolean sendUpstream) {
-    if(current != null){
-      current.kill(sendUpstream);
-      current = null;
-    }
-    for(;incomingIterator.hasNext();){
-      incomingIterator.next().kill(sendUpstream);
-    }
+    return recordCount;
   }
 
   @Override
   protected void killIncoming(boolean sendUpstream) {
-    for (int i = 0; i < incoming.size(); i++) {
-      RecordBatch in = incoming.get(i);
-      in.kill(sendUpstream);
-    }
+    unionAllInput.getLeftRecordBatch().kill(sendUpstream);
+    unionAllInput.getRightRecordBatch().kill(sendUpstream);
   }
 
-  public void buildSchema() throws SchemaChangeException {
-    setupSchema();
+  @Override
+  public SelectionVector2 getSelectionVector2() {
+    throw new UnsupportedOperationException("UnionAllRecordBatch does not support selection vector");
   }
 
   @Override
-  public SelectionVector2 getSelectionVector2() {
-    return sv;
+  public SelectionVector4 getSelectionVector4() {
+    throw new UnsupportedOperationException("UnionAllRecordBatch does not support selection vector");
   }
 
   @Override
   public IterOutcome innerNext() {
-    if (current == null) { // end of iteration
-      return IterOutcome.NONE;
-    }
-    IterOutcome upstream = current.next();
-    logger.debug("Upstream... {}", upstream);
-    while (upstream == IterOutcome.NONE) {
-      if (!incomingIterator.hasNext()) {
-        current = null;
-        return IterOutcome.NONE;
-      }
-      current = incomingIterator.next();
-      upstream = current.next();
-      if (upstream == IterOutcome.OK) {
-        upstream = IterOutcome.OK_NEW_SCHEMA;
+    try {
+      IterOutcome upstream = unionAllInput.nextBatch();
+      logger.debug("Upstream of Union-All: ", upstream.toString());
+      switch(upstream) {
+        case NONE:
+        case OUT_OF_MEMORY:
+        case STOP:
+          return upstream;
+
+        case OK_NEW_SCHEMA:
+          outputFields = unionAllInput.getOutputFields();
+        case OK:
+          IterOutcome workOutcome = doWork();
+
+          if(workOutcome != IterOutcome.OK) {
+            return workOutcome;
+          } else {
+            return upstream;
+          }
+        default:
+          throw new IllegalStateException(String.format("Unknown state %s.", upstream));
       }
+    } catch (ClassTransformationException | IOException | SchemaChangeException ex) {
+      context.fail(ex);
+      killIncoming(false);
+      return IterOutcome.STOP;
     }
-    switch (upstream) {
-      case NONE:
-        throw new IllegalArgumentException("not possible!");
-      case NOT_YET:
-      case STOP:
-        return upstream;
-      case OK_NEW_SCHEMA:
-        setupSchema();
-        // fall through.
-      case OK:
-        doTransfer();
-        return upstream; // change if upstream changed, otherwise normal.
-      default:
-        throw new UnsupportedOperationException();
-    }
   }
 
-  private void doTransfer() {
-    outRecordCount = current.getRecordCount();
-    // If the batch is empty we still need to set up the outgoing vectors otherwise the downstream operators will get
-    // a NPE. SEE DRILL-1886
-    if (container.getSchema().getSelectionVectorMode() == BatchSchema.SelectionVectorMode.TWO_BYTE) {
-      this.sv = current.getSelectionVector2();
+  @Override
+  public WritableBatch getWritableBatch() {
+    return WritableBatch.get(this);
+  }
+
+  @Override
+  public void cleanup() {
+    super.cleanup();
+    unionAllInput.cleanup();
+  }
+
+  private void setValueCount(int count) {
+    for (ValueVector v : allocationVectors) {
+      ValueVector.Mutator m = v.getMutator();
+      m.setValueCount(count);
     }
-    for (TransferPair transfer : transfers) {
-      transfer.transfer();
+  }
+
+  private boolean doAlloc() {
+    for (ValueVector v : allocationVectors) {
+      if(!AllocationHelper.allocateNew(v, current.getRecordCount())) {
+        return false;
+      }
     }
+    return true;
   }
 
-  private void setupSchema() {
-    if (container != null) {
-      container.clear();
+  private IterOutcome doWork() throws ClassTransformationException, IOException, SchemaChangeException {
+    if (allocationVectors != null) {
+      for (ValueVector v : allocationVectors) {
+        v.clear();
+      }
     }
-    transfers = Lists.newArrayList();
 
-    for (VectorWrapper<?> vw : current) {
-      TransferPair pair = vw.getValueVector().getTransferPair();
-      container.add(pair.getTo());
-      transfers.add(pair);
+    allocationVectors = Lists.newArrayList();
+    transfers.clear();
+
+    final ClassGenerator<UnionAller> cg = CodeGenerator.getRoot(UnionAller.TEMPLATE_DEFINITION, context.getFunctionRegistry());
+    int index = 0;
+    for(VectorWrapper<?> vw : current) {
+      ValueVector vvIn = vw.getValueVector();
+      // get the original input column names
+      SchemaPath inputPath = vvIn.getField().getPath();
+      // get the renamed column names
+      SchemaPath outputPath = outputFields.get(index).getPath();
+
+      final ErrorCollector collector = new ErrorCollectorImpl();
+      // According to input data names, Minortypes, Datamodes, choose to
+      // transfer directly,
+      // rename columns or
+      // cast data types (Minortype or DataMode)
+      if(hasSameTypeAndMode(outputFields.get(index), vw.getValueVector().getField())) {
+        // Transfer column
+        if(outputFields.get(index).getPath().equals(inputPath)) {
+          final LogicalExpression expr = ExpressionTreeMaterializer.materialize(inputPath, current, collector, context.getFunctionRegistry());
+          if (collector.hasErrors()) {
+            throw new SchemaChangeException(String.format("Failure while trying to materialize incoming schema.  Errors:\n %s.", collector.toErrorString()));
+          }
+
+          ValueVectorReadExpression vectorRead = (ValueVectorReadExpression) expr;
+          ValueVector vvOut = container.addOrGet(MaterializedField.create(outputPath, vectorRead.getMajorType()));
+          TransferPair tp = vvIn.makeTransferPair(vvOut);
+          transfers.add(tp);
+        // Copy data in order to rename the column
+        } else {
+          final LogicalExpression expr = ExpressionTreeMaterializer.materialize(inputPath, current, collector, context.getFunctionRegistry() );
+          if (collector.hasErrors()) {
+            throw new SchemaChangeException(String.format("Failure while trying to materialize incoming schema.  Errors:\n %s.", collector.toErrorString()));
+          }
+
+          MaterializedField outputField = MaterializedField.create(outputPath, expr.getMajorType());
+          ValueVector vv = container.addOrGet(outputField, callBack);
+          allocationVectors.add(vv);
+          TypedFieldId fid = container.getValueVectorId(outputField.getPath());
+          ValueVectorWriteExpression write = new ValueVectorWriteExpression(fid, expr, true);
+          cg.addExpr(write);
+        }
+      // Cast is necessary
+      } else {
+        LogicalExpression expr = ExpressionTreeMaterializer.materialize(inputPath, current, collector, context.getFunctionRegistry());
+        if (collector.hasErrors()) {
+          throw new SchemaChangeException(String.format("Failure while trying to materialize incoming schema.  Errors:\n %s.", collector.toErrorString()));
+        }
+
+        // If the inputs' DataMode is required and the outputs' DataMode is not required
+        // cast to the one with the least restriction
+        if(vvIn.getField().getType().getMode() == DataMode.REQUIRED
+            && outputFields.get(index).getType().getMode() != DataMode.REQUIRED) {
+          expr = ExpressionTreeMaterializer.convertToNullableType(expr, vvIn.getField().getType().getMinorType(), context.getFunctionRegistry(), collector);
+          if (collector.hasErrors()) {
+            throw new SchemaChangeException(String.format("Failure while trying to materialize incoming schema.  Errors:\n %s.", collector.toErrorString()));
+          }
+        }
+
+        // If two inputs' MinorTypes are different,
+        // Insert a cast before the Union operation
+        if(vvIn.getField().getType().getMinorType() != outputFields.get(index).getType().getMinorType()) {
+          expr = ExpressionTreeMaterializer.addCastExpression(expr, outputFields.get(index).getType(), context.getFunctionRegistry(), collector);
+          if (collector.hasErrors()) {
+            throw new SchemaChangeException(String.format("Failure while trying to materialize incoming schema.  Errors:\n %s.", collector.toErrorString()));
+          }
+        }
+
+        final MaterializedField outputField = MaterializedField.create(outputPath, expr.getMajorType());
+        ValueVector vector = container.addOrGet(outputField, callBack);
+        allocationVectors.add(vector);
+        TypedFieldId fid = container.getValueVectorId(outputField.getPath());
+
+        boolean useSetSafe = !(vector instanceof FixedWidthVector);
+        ValueVectorWriteExpression write = new ValueVectorWriteExpression(fid, expr, useSetSafe);
+        cg.addExpr(write);
+      }
+      ++index;
     }
-    container.buildSchema(current.getSchema().getSelectionVectorMode());
+
+    unionall = context.getImplementationClass(cg.getCodeGenerator());
+    unionall.setup(context, current, this, transfers);
+
+    if(!schemaAvailable) {
+      container.buildSchema(BatchSchema.SelectionVectorMode.NONE);
+      schemaAvailable = true;
+    }
+
+    if(!doAlloc()) {
+      return IterOutcome.OUT_OF_MEMORY;
+    }
+
+    recordCount = unionall.unionRecords(0, current.getRecordCount(), 0);
+    setValueCount(recordCount);
+    return IterOutcome.OK;
   }
 
-  @Override
-  public WritableBatch getWritableBatch() {
-    return WritableBatch.get(this);
+  public static boolean hasSameTypeAndMode(MaterializedField leftField, MaterializedField rightField) {
+    return (leftField.getType().getMinorType() == rightField.getType().getMinorType())
+        && (leftField.getType().getMode() == rightField.getType().getMode());
   }
 
-  @Override
-  public void cleanup() {
-    super.cleanup();
-    for (int i = 0; i < incoming.size(); i++) {
-      RecordBatch in = incoming.get(i);
-      in.cleanup();
+  // This method is used by inner class to point the reference `current` to the correct record batch
+  private void setCurrentRecordBatch(RecordBatch target) {
+    this.current = target;
+  }
+
+  // This method is used by inner class to clear the current record batch
+  private void clearCurrentRecordBatch() {
+    for(VectorWrapper<?> v: current) {
+      v.clear();
     }
   }
 
-}
+  public static class UnionAllInput {
+    private UnionAllRecordBatch unionAllRecordBatch;
+    private List<MaterializedField> outputFields;
+    private OneSideInput leftSide;
+    private OneSideInput rightSide;
+    private IterOutcome upstream = IterOutcome.NOT_YET;
+    private boolean leftIsFinish = false;
+
+    public UnionAllInput(UnionAllRecordBatch unionAllRecordBatch, RecordBatch left, RecordBatch right) {
+      this.unionAllRecordBatch = unionAllRecordBatch;
+      leftSide = new OneSideInput(left);
+      rightSide = new OneSideInput(right);
+    }
+
+    public IterOutcome nextBatch() throws SchemaChangeException {
+      if(upstream == RecordBatch.IterOutcome.NOT_YET) {
+        IterOutcome iterLeft = leftSide.nextBatch();
+        if(iterLeft != IterOutcome.OK_NEW_SCHEMA) {
+          upstream = iterLeft;
+          return upstream;
+        }
+
+        IterOutcome iterRight = rightSide.nextBatch();
+        if(iterRight != IterOutcome.OK_NEW_SCHEMA) {
+          upstream = iterRight;
+          return upstream;
+        }
+
+        unionAllRecordBatch.setCurrentRecordBatch(leftSide.getRecordBatch());
+        inferOutputFields();
+        upstream = IterOutcome.OK_NEW_SCHEMA;
+        return upstream;
+      } else {
+        unionAllRecordBatch.clearCurrentRecordBatch();
+
+        if(leftIsFinish) {
+          IterOutcome iterOutcome = rightSide.nextBatch();
+
+          switch(iterOutcome) {
+            case STOP:
+            case OUT_OF_MEMORY:
+            case NONE:
+              upstream = iterOutcome;
+              return upstream;
+
+            case OK:
+              unionAllRecordBatch.setCurrentRecordBatch(rightSide.getRecordBatch());
+              upstream = iterOutcome;
+              return upstream;
+
+            default:
+              throw new SchemaChangeException("Schema change detected in the right input of Union-All. This is not currently supported");
+          }
+        } else {
+          IterOutcome iterOutcome = leftSide.nextBatch();
+
+          switch(iterOutcome) {
+            case STOP:
+            case OUT_OF_MEMORY:
+              upstream = iterOutcome;
+              return upstream;
+
+            case OK:
+              unionAllRecordBatch.setCurrentRecordBatch(leftSide.getRecordBatch());
+              upstream = iterOutcome;
+              return upstream;
+
+            case NONE:
+              unionAllRecordBatch.setCurrentRecordBatch(rightSide.getRecordBatch());
+              upstream = IterOutcome.OK;
+              leftIsFinish = true;
+              return upstream;
+
+            default:
+              throw new SchemaChangeException("Schema change detected in the left input of Union-All. This is not currently supported");
+          }
+        }
+      }
+    }
+
+    // The output table's column names always follow the left table,
+    // where the output type is chosen based on DRILL's implicit casting rules
+    private void inferOutputFields() {
+      outputFields = Lists.newArrayList();
+      Iterator<MaterializedField> leftIter = leftSide.getRecordBatch().getSchema().iterator();
+      Iterator<MaterializedField> rightIter = rightSide.getRecordBatch().getSchema().iterator();
+
+      int index = 1;
+      while(leftIter.hasNext() && rightIter.hasNext()) {
+        MaterializedField leftField  = leftIter.next();
+        MaterializedField rightField = rightIter.next();
+
+        if(hasSameTypeAndMode(leftField, rightField)) {
+          outputFields.add(MaterializedField.create(leftField.getPath(), leftField.getType()));
+        } else {
+          // If the output type is not the same,
+          // cast the column of one of the table to a data type which is the Least Restrictive
+          MinorType outputMinorType;
+          if(leftField.getType().getMinorType() == rightField.getType().getMinorType()) {
+            outputMinorType = leftField.getType().getMinorType();
+          } else {
+            List<MinorType> types = Lists.newLinkedList();
+            types.add(leftField.getType().getMinorType());
+            types.add(rightField.getType().getMinorType());
+            outputMinorType = TypeCastRules.getLeastRestrictiveType(types);
+            if(outputMinorType == null) {
+              throw new DrillRuntimeException("Type mismatch between " + leftField.getType().getMinorType().toString() +
+                  " on the left side and " + rightField.getType().getMinorType().toString() +
+                  " on the right side in column " + index + " of UNION ALL");
+            }
+          }
+
+          // The output data mode should be as flexible as the more flexible one from the two input tables
+          List<DataMode> dataModes = Lists.newLinkedList();
+          dataModes.add(leftField.getType().getMode());
+          dataModes.add(rightField.getType().getMode());
+          DataMode dataMode = TypeCastRules.getLeastRestrictiveDataMode(dataModes);
+
+          MajorType.Builder builder = MajorType.newBuilder();
+          builder.setMinorType(outputMinorType);
+          builder.setMode(dataMode);
+          outputFields.add(MaterializedField.create(leftField.getPath(), builder.build()));
+        }
+        ++index;
+      }
+
+      assert !leftIter.hasNext() && ! rightIter.hasNext() : "Mis-match of column count should have been detected when validating sqlNode at planning";
+    }
+
+    public List<MaterializedField> getOutputFields() {
+      if(outputFields == null) {
+        throw new NullPointerException("Output fields have not been inferred");
+      }
+
+      return outputFields;
+    }
+
+    public void killIncoming(boolean sendUpstream) {
+      leftSide.getRecordBatch().kill(sendUpstream);
+      rightSide.getRecordBatch().kill(sendUpstream);
+    }
+
+    public RecordBatch getLeftRecordBatch() {
+      return leftSide.getRecordBatch();
+    }
+
+    public RecordBatch getRightRecordBatch() {
+      return rightSide.getRecordBatch();
+    }
+
+    public void cleanup() {
+      leftSide.getRecordBatch().cleanup();
+      rightSide.getRecordBatch().cleanup();
+    }
+
+    private class OneSideInput {
+      private IterOutcome upstream = IterOutcome.NOT_YET;
+      private RecordBatch recordBatch;
+
+      public OneSideInput(RecordBatch recordBatch) {
+        this.recordBatch = recordBatch;
+      }
+
+      public RecordBatch getRecordBatch() {
+        return recordBatch;
+      }
+
+      public IterOutcome nextBatch() {
+        if(upstream == IterOutcome.NONE) {
+          throw new IllegalStateException(String.format("Unknown state %s.", upstream));
+        }
+
+        if(upstream == IterOutcome.NOT_YET) {
+          upstream = unionAllRecordBatch.next(recordBatch);
+
+          return upstream;
+        } else {
+          do {
+            upstream = unionAllRecordBatch.next(recordBatch);
+          } while (upstream == IterOutcome.OK && recordBatch.getRecordCount() == 0);
+
+          return upstream;
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAller.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAller.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAller.java
new file mode 100644
index 0000000..9cd9cdc
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAller.java
@@ -0,0 +1,33 @@
+/**
+ * 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.drill.exec.physical.impl.union;
+
+import org.apache.drill.exec.compile.TemplateClassDefinition;
+import org.apache.drill.exec.exception.SchemaChangeException;
+import org.apache.drill.exec.ops.FragmentContext;
+import org.apache.drill.exec.record.RecordBatch;
+import org.apache.drill.exec.record.TransferPair;
+
+import java.util.List;
+
+public interface UnionAller {
+  public abstract void setup(FragmentContext context, RecordBatch incoming,  RecordBatch outgoing, List<TransferPair> transfers)  throws SchemaChangeException;
+  public abstract int unionRecords(int startIndex, int recordCount, int firstOutputIndex);
+
+  public static TemplateClassDefinition<UnionAller> TEMPLATE_DEFINITION = new TemplateClassDefinition<UnionAller>(UnionAller.class, UnionAllerTemplate.class);
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAllerTemplate.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAllerTemplate.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAllerTemplate.java
new file mode 100644
index 0000000..fdccdb6
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/union/UnionAllerTemplate.java
@@ -0,0 +1,60 @@
+/**
+ * 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.drill.exec.physical.impl.union;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.drill.exec.exception.SchemaChangeException;
+import org.apache.drill.exec.ops.FragmentContext;
+import org.apache.drill.exec.record.RecordBatch;
+import org.apache.drill.exec.record.TransferPair;
+
+import javax.inject.Named;
+import java.util.List;
+
+public abstract class UnionAllerTemplate implements UnionAller {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(UnionAllerTemplate.class);
+
+  private ImmutableList<TransferPair> transfers;
+
+  public UnionAllerTemplate() throws SchemaChangeException {
+
+  }
+
+  @Override
+  public final int unionRecords(int startIndex, final int recordCount, int firstOutputIndex) {
+    int i;
+    for (i = startIndex; i < startIndex + recordCount; i++, firstOutputIndex++) {
+      doEval(i, firstOutputIndex);
+    }
+
+    for (TransferPair t : transfers) {
+      t.transfer();
+    }
+    return recordCount;
+  }
+
+  @Override
+  public final void setup(FragmentContext context, RecordBatch incoming, RecordBatch outgoing, List<TransferPair> transfers)  throws SchemaChangeException{
+    this.transfers = ImmutableList.copyOf(transfers);
+    doSetup(context, incoming, outgoing);
+  }
+
+  public abstract void doSetup(@Named("context") FragmentContext context, @Named("incoming") RecordBatch incoming, @Named("outgoing") RecordBatch outgoing);
+  public abstract void doEval(@Named("inIndex") int inIndex, @Named("outIndex") int outIndex);
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
index 270462b..aba6022 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillRelOptUtil.java
@@ -57,7 +57,7 @@ public abstract class DrillRelOptUtil {
         || type2.getSqlTypeName() == SqlTypeName.ANY) {
         continue;
       }
-      if (!type1.equals(type2)) {
+      if (type1.getSqlTypeName() != type2.getSqlTypeName()) {
         if (allowSubstring
             && (type1.getSqlTypeName() == SqlTypeName.CHAR && type2.getSqlTypeName() == SqlTypeName.CHAR)
             && (type1.getPrecision() <= type2.getPrecision())) {

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/PreProcessLogicalRel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/PreProcessLogicalRel.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/PreProcessLogicalRel.java
index 4c9d301..a421861 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/PreProcessLogicalRel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/PreProcessLogicalRel.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.drill.exec.exception.UnsupportedOperatorCollector;
+import org.apache.drill.exec.planner.StarColumnHelper;
 import org.apache.drill.exec.planner.sql.DrillOperatorTable;
 import org.apache.drill.exec.work.foreman.SqlUnsupportedException;
 import org.eigenbase.rel.AggregateCall;
@@ -28,7 +29,10 @@ import org.eigenbase.rel.AggregateRel;
 import org.eigenbase.rel.ProjectRel;
 import org.eigenbase.rel.RelNode;
 import org.eigenbase.rel.RelShuttleImpl;
+import org.eigenbase.rel.UnionRel;
+import org.eigenbase.reltype.RelDataType;
 import org.eigenbase.reltype.RelDataTypeFactory;
+import org.eigenbase.reltype.RelDataTypeField;
 import org.eigenbase.rex.RexBuilder;
 import org.eigenbase.rex.RexCall;
 import org.eigenbase.rex.RexLiteral;
@@ -60,7 +64,7 @@ public class PreProcessLogicalRel extends RelShuttleImpl {
 
   public static PreProcessLogicalRel getVisitor() {
     if(INSTANCE == null) {
-      throw new IllegalStateException("RewriteProjectRel is not initialized properly");
+      throw new IllegalStateException("PreProcessLogicalRel is not initialized properly");
     }
 
     return INSTANCE;
@@ -137,6 +141,21 @@ public class PreProcessLogicalRel extends RelShuttleImpl {
     return visitChild(project, 0, project.getChild());
   }
 
+  @Override
+  public RelNode visit(UnionRel union) {
+    for(RelNode child : union.getInputs()) {
+      for(RelDataTypeField dataField : child.getRowType().getFieldList()) {
+        if(dataField.getName().contains(StarColumnHelper.STAR_COLUMN)) {
+          unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.RELATIONAL,
+            "2414", "Union-all over schema-less tables must specify the columns explicitly");
+          throw new UnsupportedOperationException();
+        }
+      }
+    }
+
+    return visitChildren(union);
+  }
+
   public void convertException() throws SqlUnsupportedException {
     unsupportedOperatorCollector.convertException();
   }

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/FinalColumnReorderer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/FinalColumnReorderer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/FinalColumnReorderer.java
index 60a9e4b..1aa033b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/FinalColumnReorderer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/visitor/FinalColumnReorderer.java
@@ -20,9 +20,11 @@ package org.apache.drill.exec.planner.physical.visitor;
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.drill.exec.physical.config.Project;
 import org.apache.drill.exec.planner.physical.Prel;
 import org.apache.drill.exec.planner.physical.ProjectPrel;
 import org.apache.drill.exec.planner.physical.ScreenPrel;
+import org.apache.drill.exec.planner.physical.UnionPrel;
 import org.apache.drill.exec.planner.physical.WriterPrel;
 import org.eigenbase.rel.RelNode;
 import org.eigenbase.reltype.RelDataType;
@@ -43,12 +45,11 @@ public class FinalColumnReorderer extends BasePrelVisitor<Prel, Void, RuntimeExc
   @Override
   public Prel visitScreen(ScreenPrel prel, Void value) throws RuntimeException {
     Prel newChild = ((Prel) prel.getChild()).accept(this, value);
-    return prel.copy(prel.getTraitSet(), Collections.singletonList( (RelNode) addTrivialOrderedProjectPrel( newChild )));
+    return prel.copy(prel.getTraitSet(), Collections.singletonList( (RelNode) addTrivialOrderedProjectPrel(newChild)));
   }
 
   private Prel addTrivialOrderedProjectPrel(Prel prel) {
-
-    if ( !prel.needsFinalColumnReordering()) {
+    if (!prel.needsFinalColumnReordering()) {
       return prel;
     }
 
@@ -72,11 +73,15 @@ public class FinalColumnReorderer extends BasePrelVisitor<Prel, Void, RuntimeExc
   @Override
   public Prel visitWriter(WriterPrel prel, Void value) throws RuntimeException {
     Prel newChild = ((Prel) prel.getChild()).accept(this, null);
-    return prel.copy(prel.getTraitSet(), Collections.singletonList( (RelNode) addTrivialOrderedProjectPrel( newChild )));
+    return prel.copy(prel.getTraitSet(), Collections.singletonList( (RelNode) addTrivialOrderedProjectPrel(newChild)));
   }
 
   @Override
   public Prel visitPrel(Prel prel, Void value) throws RuntimeException {
+    if(prel instanceof UnionPrel) {
+      return addColumnOrderingBelowUnion(prel);
+    }
+
     List<RelNode> children = Lists.newArrayList();
     boolean changed = false;
     for (Prel p : prel) {
@@ -93,4 +98,19 @@ public class FinalColumnReorderer extends BasePrelVisitor<Prel, Void, RuntimeExc
     }
   }
 
+  private Prel addColumnOrderingBelowUnion(Prel prel) {
+    List<RelNode> children = Lists.newArrayList();
+    for (Prel p : prel) {
+      Prel child = p.accept(this, null);
+
+      boolean needProjectBelowUnion = !(p instanceof ProjectPrel);
+      if(needProjectBelowUnion) {
+        child = addTrivialOrderedProjectPrel(child);
+      }
+
+      children.add(child);
+    }
+
+    return (Prel) prel.copy(prel.getTraitSet(), children);
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/UnsupportedOperatorsVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/UnsupportedOperatorsVisitor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/UnsupportedOperatorsVisitor.java
index dcd5ebf..2504280 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/UnsupportedOperatorsVisitor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/UnsupportedOperatorsVisitor.java
@@ -17,12 +17,17 @@
  */
 package org.apache.drill.exec.planner.sql.parser;
 
+import org.apache.drill.exec.ExecConstants;
 import org.apache.drill.exec.exception.UnsupportedOperatorCollector;
+import org.apache.drill.exec.planner.StarColumnHelper;
 import org.apache.drill.exec.work.foreman.SqlUnsupportedException;
+import org.eigenbase.sql.SqlCall;
 import org.eigenbase.sql.SqlKind;
 import org.eigenbase.sql.SqlJoin;
 import org.eigenbase.sql.JoinType;
 import org.eigenbase.sql.SqlNode;
+import org.eigenbase.sql.SqlNodeList;
+import org.eigenbase.sql.SqlSelect;
 import org.eigenbase.sql.type.SqlTypeName;
 import org.eigenbase.sql.util.SqlShuttle;
 import org.eigenbase.sql.SqlDataTypeSpec;
@@ -71,7 +76,7 @@ public class UnsupportedOperatorsVisitor extends SqlShuttle {
   }
 
   @Override
-  public SqlNode visit(org.eigenbase.sql.SqlCall sqlCall) {
+  public SqlNode visit(SqlCall sqlCall) {
     // Disable unsupported Intersect, Except
     if(sqlCall.getKind() == SqlKind.INTERSECT || sqlCall.getKind() == SqlKind.EXCEPT) {
       unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.RELATIONAL,
@@ -82,7 +87,7 @@ public class UnsupportedOperatorsVisitor extends SqlShuttle {
     // Disable unsupported Union
     if(sqlCall.getKind() == SqlKind.UNION) {
       SqlSetOperator op = (SqlSetOperator) sqlCall.getOperator();
-      if (!op.isAll()) {
+      if(!op.isAll()) {
         unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.RELATIONAL,
             "1921", sqlCall.getOperator().getName());
         throw new UnsupportedOperationException();

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/main/java/org/apache/drill/exec/record/VectorContainer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/record/VectorContainer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/record/VectorContainer.java
index baf74b1..2d60567 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/record/VectorContainer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/record/VectorContainer.java
@@ -318,5 +318,4 @@ public class VectorContainer implements Iterable<VectorWrapper<?>>, VectorAccess
     }
     return true;
   }
-
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
index f5b0de4..8fc6612 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
@@ -786,7 +786,25 @@ public class TypeCastRules {
         (rules.get(to) == null ? false : rules.get(to).contains(from));
   }
 
-  /*
+  public static DataMode getLeastRestrictiveDataMode(List<DataMode> dataModes) {
+    boolean hasOptional = false;
+    for(DataMode dataMode : dataModes) {
+      switch (dataMode) {
+        case REPEATED:
+          return dataMode;
+        case OPTIONAL:
+          hasOptional = true;
+      }
+    }
+
+    if(hasOptional) {
+      return DataMode.OPTIONAL;
+    } else {
+      return DataMode.REQUIRED;
+    }
+  }
+
+    /*
    * Function checks if casting is allowed from the 'from' -> 'to' minor type. If its allowed
    * we also check if the precedence map allows such a cast and return true if both cases are satisfied
    */

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
index 225b21e..8ae0ae4 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
@@ -691,5 +691,4 @@ public class TestExampleQueries extends BaseTestQuery{
 
     test("alter session set `planner.slice_target` = " + ExecConstants.SLICE_TARGET_DEFAULT);
   }
-
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java b/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java
index 36b062b..520c204 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestUnionAll.java
@@ -17,65 +17,341 @@
  */
 package org.apache.drill;
 
-import org.apache.drill.common.util.TestTools;
+import org.apache.drill.common.types.TypeProtos;
+import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.work.foreman.SqlUnsupportedException;
+import org.apache.drill.exec.work.foreman.UnsupportedRelOperatorException;
 import org.junit.Test;
 
 public class TestUnionAll extends BaseTestQuery{
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestUnionAll.class);
-  static final String WORKING_PATH = TestTools.getWorkingPath();
-  static final String TEST_RES_PATH = WORKING_PATH + "/src/test/resources";
 
-  @Test    // Simple Union-All over two scans
+  @Test  // Simple Union-All over two scans
   public void testUnionAll1() throws Exception {
-    test("select n_regionkey from cp.`tpch/nation.parquet` union all select r_regionkey from cp.`tpch/region.parquet`");
+    String query = "(select n_regionkey from cp.`tpch/nation.parquet`) union all (select r_regionkey from cp.`tpch/region.parquet`)";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q1.tsv")
+        .baselineTypes(TypeProtos.MinorType.INT)
+        .baselineColumns("n_regionkey")
+        .build().run();
   }
 
   @Test  // Union-All over inner joins
   public void testUnionAll2() throws Exception {
-    test("select n1.n_nationkey from cp.`tpch/nation.parquet` n1 inner join cp.`tpch/region.parquet` r1 on n1.n_regionkey = r1.r_regionkey where n1.n_nationkey in (1, 2)  union all select n2.n_nationkey from cp.`tpch/nation.parquet` n2 inner join cp.`tpch/region.parquet` r2 on n2.n_regionkey = r2.r_regionkey where n2.n_nationkey in (3, 4)");
+    String query =
+         "select n1.n_nationkey from cp.`tpch/nation.parquet` n1 inner join cp.`tpch/region.parquet` r1 on n1.n_regionkey = r1.r_regionkey where n1.n_nationkey in (1, 2) " +
+         "union all " +
+         "select n2.n_nationkey from cp.`tpch/nation.parquet` n2 inner join cp.`tpch/region.parquet` r2 on n2.n_regionkey = r2.r_regionkey where n2.n_nationkey in (3, 4)";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q2.tsv")
+        .baselineTypes(TypeProtos.MinorType.INT)
+        .baselineColumns("n_nationkey")
+        .build().run();
   }
 
   @Test  // Union-All over grouped aggregates
   public void testUnionAll3() throws Exception {
-    test("select n1.n_nationkey from cp.`tpch/nation.parquet` n1 where n1.n_nationkey in (1, 2) group by n1.n_nationkey union all select r1.r_regionkey from cp.`tpch/region.parquet` r1 group by r1.r_regionkey");
+    String query = "select n1.n_nationkey from cp.`tpch/nation.parquet` n1 where n1.n_nationkey in (1, 2) group by n1.n_nationkey union all select r1.r_regionkey from cp.`tpch/region.parquet` r1 group by r1.r_regionkey";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q3.tsv")
+        .baselineTypes(TypeProtos.MinorType.INT)
+        .baselineColumns("n_nationkey")
+        .build().run();
   }
 
   @Test    // Chain of Union-Alls
   public void testUnionAll4() throws Exception {
-    test("select n_regionkey from cp.`tpch/nation.parquet` union all select r_regionkey from cp.`tpch/region.parquet` union all select n_nationkey from cp.`tpch/nation.parquet` union all select c_custkey from cp.`tpch/customer.parquet` where c_custkey < 5");
+    String query = "select n_regionkey from cp.`tpch/nation.parquet` union all select r_regionkey from cp.`tpch/region.parquet` union all select n_nationkey from cp.`tpch/nation.parquet` union all select c_custkey from cp.`tpch/customer.parquet` where c_custkey < 5";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q4.tsv")
+        .baselineTypes(TypeProtos.MinorType.INT)
+        .baselineColumns("n_regionkey")
+        .build().run();
   }
 
   @Test  // Union-All of all columns in the table
   public void testUnionAll5() throws Exception {
-    test("select * from cp.`tpch/region.parquet` r1 union all select * from cp.`tpch/region.parquet` r2");
+    String query = "select r_name, r_comment, r_regionkey from cp.`tpch/region.parquet` r1 " +
+                     "union all " +
+                     "select r_name, r_comment, r_regionkey from cp.`tpch/region.parquet` r2";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q5.tsv")
+        .baselineTypes(TypeProtos.MinorType.VARCHAR, TypeProtos.MinorType.VARCHAR, TypeProtos.MinorType.INT)
+        .baselineColumns("r_name", "r_comment", "r_regionkey")
+        .build().run();
   }
 
   @Test // Union-All where same column is projected twice in right child
   public void testUnionAll6() throws Exception {
-    test("select n_nationkey, n_regionkey from cp.`tpch/nation.parquet` where n_regionkey = 1 union all select r_regionkey, r_regionkey from cp.`tpch/region.parquet` where r_regionkey = 2");
+    String query = "select n_nationkey, n_regionkey from cp.`tpch/nation.parquet` where n_regionkey = 1 union all select r_regionkey, r_regionkey from cp.`tpch/region.parquet` where r_regionkey = 2";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q6.tsv")
+        .baselineTypes(TypeProtos.MinorType.INT, TypeProtos.MinorType.INT)
+        .baselineColumns("n_nationkey", "n_regionkey")
+        .build().run();
   }
 
   @Test // Union-All where same column is projected twice in left and right child
   public void testUnionAll6_1() throws Exception {
-    test("select n_nationkey, n_nationkey from cp.`tpch/nation.parquet` union all select r_regionkey, r_regionkey from cp.`tpch/region.parquet`");
+    String query = "select n_nationkey, n_nationkey from cp.`tpch/nation.parquet` union all select r_regionkey, r_regionkey from cp.`tpch/region.parquet`";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q6_1.tsv")
+        .baselineTypes(TypeProtos.MinorType.INT, TypeProtos.MinorType.INT)
+        .baselineColumns("n_nationkey", "n_nationkey0")
+        .build().run();
   }
 
   @Test  // Union-all of two string literals of different lengths
   public void testUnionAll7() throws Exception {
-    test("select 'abc' from cp.`tpch/region.parquet` union all select 'abcdefgh' from cp.`tpch/region.parquet`");
+    String query = "select 'abc' from cp.`tpch/region.parquet` union all select 'abcdefgh' from cp.`tpch/region.parquet`";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q7.tsv")
+        .baselineTypes(TypeProtos.MinorType.VARCHAR)
+        .baselineColumns("EXPR$0")
+        .build().run();
   }
 
   @Test  // Union-all of two character columns of different lengths
   public void testUnionAll8() throws Exception {
-    test("select n_name from cp.`tpch/nation.parquet` union all select r_comment from cp.`tpch/region.parquet`");
+    String query = "select n_name, n_nationkey from cp.`tpch/nation.parquet` union all select r_comment, r_regionkey  from cp.`tpch/region.parquet`";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q8.tsv")
+        .baselineTypes(TypeProtos.MinorType.VARCHAR, TypeProtos.MinorType.INT)
+        .baselineColumns("n_name", "n_nationkey")
+        .build().run();
   }
 
   @Test // DRILL-1905: Union-all of * column from JSON files in different directories
   public void testUnionAll9() throws Exception {
-    String query1 = String.format("select * from dfs_test.`%s/multilevel/json/1994/Q1/orders_94_q1.json` " +
-             " union all select * from dfs_test.`%s/multilevel/json/1995/Q1/orders_95_q1.json`",
-             TEST_RES_PATH, TEST_RES_PATH);
-    test(query1);
+    String file0 = FileUtils.getResourceAsFile("/multilevel/json/1994/Q1/orders_94_q1.json").toURI().toString();
+    String file1 = FileUtils.getResourceAsFile("/multilevel/json/1995/Q1/orders_95_q1.json").toURI().toString();
+    String query = String.format("select o_custkey, o_orderstatus, o_totalprice, o_orderdate, o_orderpriority, o_clerk, o_shippriority, o_comment, o_orderkey from dfs_test.`%s` union all " +
+                                 "select o_custkey, o_orderstatus, o_totalprice, o_orderdate, o_orderpriority, o_clerk, o_shippriority, o_comment, o_orderkey from dfs_test.`%s`", file0, file1);
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q9.tsv")
+        .baselineTypes(TypeProtos.MinorType.BIGINT, TypeProtos.MinorType.VARCHAR, TypeProtos.MinorType.FLOAT8, TypeProtos.MinorType.VARCHAR,
+                       TypeProtos.MinorType.VARCHAR, TypeProtos.MinorType.VARCHAR, TypeProtos.MinorType.BIGINT,TypeProtos.MinorType.VARCHAR, TypeProtos.MinorType.BIGINT)
+        .baselineColumns("o_custkey", "o_orderstatus", "o_totalprice", "o_orderdate",
+                         "o_orderpriority", "o_clerk", "o_shippriority", "o_comment", "o_orderkey")
+        .build().run();
+  }
+
+  @Test // Union All constant literals
+  public void testUnionAll10() throws Exception {
+    String query = "(select n_name, 'LEFT' as LiteralConstant, n_nationkey, '1' as NumberConstant from cp.`tpch/nation.parquet`) " +
+              "union all " +
+              "(select 'RIGHT', r_name, '2', r_regionkey from cp.`tpch/region.parquet`)";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q10.tsv")
+        .baselineTypes(TypeProtos.MinorType.VARCHAR, TypeProtos.MinorType.VARCHAR, TypeProtos.MinorType.INT, TypeProtos.MinorType.INT)
+        .baselineColumns("n_name", "LiteralConstant", "n_nationkey", "NumberConstant")
+        .build().run();
+  }
+
+  @Test
+  public void testUnionAllViewExpandableStar() throws Exception {
+    test("use dfs.tmp");
+    test("create view nation_view as select n_name, n_nationkey from cp.`tpch/nation.parquet`;");
+    test("create view region_view as select r_name, r_regionkey from cp.`tpch/region.parquet`;");
+
+    String query1 = "(select * from dfs.tmp.`nation_view`) " +
+                    "union all " +
+                    "(select * from dfs.tmp.`region_view`) ";
+
+    String query2 =  "(select r_name, r_regionkey from cp.`tpch/region.parquet`) " +
+                     "union all " +
+                     "(select * from dfs.tmp.`nation_view`)";
+
+    try {
+      testBuilder()
+          .sqlQuery(query1)
+          .unOrdered()
+          .csvBaselineFile("testframework/testUnionAllQueries/q11.tsv")
+          .baselineTypes(TypeProtos.MinorType.VARCHAR, TypeProtos.MinorType.INT)
+          .baselineColumns("n_name", "n_nationkey")
+          .build().run();
+
+      testBuilder()
+          .sqlQuery(query2)
+          .unOrdered()
+          .csvBaselineFile("testframework/testUnionAllQueries/q12.tsv")
+          .baselineTypes(TypeProtos.MinorType.VARCHAR, TypeProtos.MinorType.INT)
+          .baselineColumns("r_name", "r_regionkey")
+          .build().run();
+    } finally {
+      test("drop view nation_view");
+      test("drop view region_view");
+    }
+  }
+
+  @Test(expected = UnsupportedRelOperatorException.class) // see DRILL-2002
+  public void testUnionAllViewUnExpandableStar() throws Exception {
+    test("use dfs.tmp");
+    test("create view nation_view as select * from cp.`tpch/nation.parquet`;");
+
+    try {
+      String query = "(select * from dfs.tmp.`nation_view`) " +
+                     "union all (select * from cp.`tpch/region.parquet`)";
+      test(query);
+    } catch(Exception ex) {
+      SqlUnsupportedException.errorMessageToException(ex.getMessage());
+      throw ex;
+    } finally {
+      test("drop view nation_view");
+    }
+  }
+
+  @Test
+  public void testDiffDataTypesAndModes() throws Exception {
+    test("use dfs.tmp");
+    test("create view nation_view as select n_name, n_nationkey from cp.`tpch/nation.parquet`;");
+    test("create view region_view as select r_name, r_regionkey from cp.`tpch/region.parquet`;");
+
+    String t1 = "(select n_comment, n_regionkey from cp.`tpch/nation.parquet` limit 5)";
+    String t2 = "(select * from nation_view  limit 5)";
+    String t3 = "(select full_name, store_id from cp.`employee.json` limit 5)";
+    String t4 = "(select * from region_view  limit 5)";
+
+    String query1 = t1 + " union all " + t2 + " union all " + t3 + " union all " + t4;
+
+    try {
+      testBuilder()
+          .sqlQuery(query1)
+          .unOrdered()
+          .csvBaselineFile("testframework/testUnionAllQueries/q13.tsv")
+          .baselineTypes(TypeProtos.MinorType.VARCHAR, TypeProtos.MinorType.BIGINT)
+          .baselineColumns("n_comment", "n_regionkey")
+          .build().run();
+    } finally {
+      test("drop view nation_view");
+      test("drop view region_view");
+    }
   }
 
-}
+  @Test // see DRILL-2203
+  public void testDistinctOverUnionAllwithFullyQualifiedColumnNames() throws Exception {
+    String query = "select distinct sq.x1, sq.x2 " +
+        "from " +
+        "((select n_regionkey as a1, n_name as b1 from cp.`tpch/nation.parquet`) " +
+        "union all " +
+        "(select r_regionkey as a2, r_name as b2 from cp.`tpch/region.parquet`)) as sq(x1,x2)";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q14.tsv")
+        .baselineTypes(TypeProtos.MinorType.INT, TypeProtos.MinorType.VARCHAR)
+        .baselineColumns("x1", "x2")
+        .build().run();
+  }
+
+  @Test // see DRILL-1923
+  public void testUnionAllContainsColumnANumericConstant() throws Exception {
+    String query = "(select n_nationkey, n_regionkey, n_name from cp.`tpch/nation.parquet`  limit 5) " +
+        "union all " +
+        "(select 1, n_regionkey, 'abc' from cp.`tpch/nation.parquet` limit 5)";
+
+    testBuilder()
+        .sqlQuery(query)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q15.tsv")
+        .baselineTypes(TypeProtos.MinorType.INT, TypeProtos.MinorType.INT, TypeProtos.MinorType.VARCHAR)
+        .baselineColumns("n_nationkey", "n_regionkey", "n_name")
+        .build().run();
+  }
+
+  @Test // see DRILL-2207
+  public void testUnionAllEmptySides() throws Exception {
+    String query1 = "(select n_nationkey, n_regionkey, n_name from cp.`tpch/nation.parquet`  limit 0) " +
+        "union all " +
+        "(select 1, n_regionkey, 'abc' from cp.`tpch/nation.parquet` limit 5)";
+
+    String query2 = "(select n_nationkey, n_regionkey, n_name from cp.`tpch/nation.parquet`  limit 5) " +
+        "union all " +
+        "(select 1, n_regionkey, 'abc' from cp.`tpch/nation.parquet` limit 0)";
+
+    testBuilder()
+        .sqlQuery(query1)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q16.tsv")
+        .baselineTypes(TypeProtos.MinorType.INT, TypeProtos.MinorType.INT, TypeProtos.MinorType.VARCHAR)
+        .baselineColumns("n_nationkey", "n_regionkey", "n_name")
+        .build().run();
+
+
+    testBuilder()
+        .sqlQuery(query2)
+        .unOrdered()
+        .csvBaselineFile("testframework/testUnionAllQueries/q17.tsv")
+        .baselineTypes(TypeProtos.MinorType.INT, TypeProtos.MinorType.INT, TypeProtos.MinorType.VARCHAR)
+        .baselineColumns("n_nationkey", "n_regionkey", "n_name")
+        .build().run();
+    }
+
+  @Test // see DRILL-1977, DRILL-2376, DRILL-2377, DRILL-2378, DRILL-2379
+  public void testAggregationOnUnionAllOperator() throws Exception {
+    String root = FileUtils.getResourceAsFile("/store/text/data/t.json").toURI().toString();
+    String query1 = String.format(
+        "(select calc1, max(b1) as `max`, min(b1) as `min`, count(c1) as `count` " +
+        "from (select a1 + 10 as calc1, b1, c1 from dfs_test.`%s` " +
+        "union all " +
+        "select a1 + 100 as diff1, b1 as diff2, c1 as diff3 from dfs_test.`%s`) " +
+        "group by calc1 order by calc1)", root, root);
+
+    String query2 = String.format(
+        "(select calc1, min(b1) as `min`, max(b1) as `max`, count(c1) as `count` " +
+        "from (select a1 + 10 as calc1, b1, c1 from dfs_test.`%s` " +
+        "union all " +
+        "select a1 + 100 as diff1, b1 as diff2, c1 as diff3 from dfs_test.`%s`) " +
+        "group by calc1 order by calc1)", root, root);
+
+    testBuilder()
+        .sqlQuery(query1)
+        .ordered()
+        .csvBaselineFile("testframework/testExampleQueries/testAggregationOnUnionAllOperator/q1.tsv")
+        .baselineTypes(TypeProtos.MinorType.BIGINT, TypeProtos.MinorType.BIGINT, TypeProtos.MinorType.BIGINT, TypeProtos.MinorType.BIGINT)
+        .baselineColumns("calc1", "max", "min", "count")
+        .build().run();
+
+    testBuilder()
+        .sqlQuery(query2)
+        .ordered()
+        .csvBaselineFile("testframework/testExampleQueries/testAggregationOnUnionAllOperator/q2.tsv")
+        .baselineTypes(TypeProtos.MinorType.BIGINT, TypeProtos.MinorType.BIGINT, TypeProtos.MinorType.BIGINT, TypeProtos.MinorType.BIGINT)
+        .baselineColumns("calc1", "min", "max", "count")
+        .build().run();
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/store/text/data/t.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/store/text/data/t.json b/exec/java-exec/src/test/resources/store/text/data/t.json
new file mode 100644
index 0000000..15d2272
--- /dev/null
+++ b/exec/java-exec/src/test/resources/store/text/data/t.json
@@ -0,0 +1,10 @@
+{ "a1": 0, "b1": 1, "c1": "true",   "d1" : "2015-01-02"}
+{ "a1": 0, "b1": 1, "c1": "false" , "d1" : "2015-01-03"}
+{ "a1": 0, "b1": 2, "c1": "false" , "d1" : "2015-01-04"}
+{ "a1": 0, "b1": 2, "c1": "true" ,  "d1" : "2015-01-05"}
+{ "a1": 0, "b1": 2, "c1": "true" ,  "d1" : "2015-01-06"}
+{ "a1": 10, "b1": 3, "c1": "true",   "d1" : "2015-01-02"}
+{ "a1": 10, "b1": 3, "c1": "false" , "d1" : "2015-01-03"}
+{ "a1": 10, "b1": 5, "c1": "false" , "d1" : "2015-01-04"}
+{ "a1": 10, "b1": 5, "c1": "true" ,  "d1" : "2015-01-05"}
+{ "a1": 10, "b1": 5, "c1": "true" ,  "d1" : "2015-01-06"}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testExampleQueries/testAggregationOnUnionAllOperator/q1.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testExampleQueries/testAggregationOnUnionAllOperator/q1.tsv b/exec/java-exec/src/test/resources/testframework/testExampleQueries/testAggregationOnUnionAllOperator/q1.tsv
new file mode 100644
index 0000000..cefc66d
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testExampleQueries/testAggregationOnUnionAllOperator/q1.tsv
@@ -0,0 +1,4 @@
+10	2	1	5
+20	5	3	5
+100	2	1	5
+110	5	3	5
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testExampleQueries/testAggregationOnUnionAllOperator/q2.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testExampleQueries/testAggregationOnUnionAllOperator/q2.tsv b/exec/java-exec/src/test/resources/testframework/testExampleQueries/testAggregationOnUnionAllOperator/q2.tsv
new file mode 100644
index 0000000..c5d996d
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testExampleQueries/testAggregationOnUnionAllOperator/q2.tsv
@@ -0,0 +1,4 @@
+10	1	2	5
+20	3	5	5
+100	1	2	5
+110	3	5	5
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q1.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q1.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q1.tsv
new file mode 100644
index 0000000..168c43d
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q1.tsv
@@ -0,0 +1,30 @@
+0
+1
+1
+1
+4
+0
+3
+3
+2
+2
+4
+4
+2
+4
+0
+0
+0
+1
+2
+3
+4
+2
+3
+3
+1
+0
+1
+2
+3
+4
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q10.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q10.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q10.tsv
new file mode 100644
index 0000000..c883125
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q10.tsv
@@ -0,0 +1,30 @@
+ALGERIA	LEFT	0	1
+ARGENTINA	LEFT	1	1
+BRAZIL	LEFT	2	1
+CANADA	LEFT	3	1
+EGYPT	LEFT	4	1
+ETHIOPIA	LEFT	5	1
+FRANCE	LEFT	6	1
+GERMANY	LEFT	7	1
+INDIA	LEFT	8	1
+INDONESIA	LEFT	9	1
+IRAN	LEFT	10	1
+IRAQ	LEFT	11	1
+JAPAN	LEFT	12	1
+JORDAN	LEFT	13	1
+KENYA	LEFT	14	1
+MOROCCO	LEFT	15	1
+MOZAMBIQUE	LEFT	16	1
+PERU	LEFT	17	1
+CHINA	LEFT	18	1
+ROMANIA	LEFT	19	1
+SAUDI ARABIA	LEFT	20	1
+VIETNAM	LEFT	21	1
+RUSSIA	LEFT	22	1
+UNITED KINGDOM	LEFT	23	1
+UNITED STATES	LEFT	24	1
+RIGHT	AFRICA	2	0
+RIGHT	AMERICA	2	1
+RIGHT	ASIA	2	2
+RIGHT	EUROPE	2	3
+RIGHT	MIDDLE EAST	2	4
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q11.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q11.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q11.tsv
new file mode 100644
index 0000000..2d5b701
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q11.tsv
@@ -0,0 +1,30 @@
+ALGERIA	0
+ARGENTINA	1
+BRAZIL	2
+CANADA	3
+EGYPT	4
+ETHIOPIA	5
+FRANCE	6
+GERMANY	7
+INDIA	8
+INDONESIA	9
+IRAN	10
+IRAQ	11
+JAPAN	12
+JORDAN	13
+KENYA	14
+MOROCCO	15
+MOZAMBIQUE	16
+PERU	17
+CHINA	18
+ROMANIA	19
+SAUDI ARABIA	20
+VIETNAM	21
+RUSSIA	22
+UNITED KINGDOM	23
+UNITED STATES	24
+AFRICA	0
+AMERICA	1
+ASIA	2
+EUROPE	3
+MIDDLE EAST	4
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q12.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q12.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q12.tsv
new file mode 100644
index 0000000..44f9209
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q12.tsv
@@ -0,0 +1,30 @@
+AFRICA	0
+AMERICA	1
+ASIA	2
+EUROPE	3
+MIDDLE EAST	4
+ALGERIA	0
+ARGENTINA	1
+BRAZIL	2
+CANADA	3
+EGYPT	4
+ETHIOPIA	5
+FRANCE	6
+GERMANY	7
+INDIA	8
+INDONESIA	9
+IRAN	10
+IRAQ	11
+JAPAN	12
+JORDAN	13
+KENYA	14
+MOROCCO	15
+MOZAMBIQUE	16
+PERU	17
+CHINA	18
+ROMANIA	19
+SAUDI ARABIA	20
+VIETNAM	21
+RUSSIA	22
+UNITED KINGDOM	23
+UNITED STATES	24
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q13.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q13.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q13.tsv
new file mode 100644
index 0000000..a207902
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q13.tsv
@@ -0,0 +1,20 @@
+ haggle. carefully final deposits detect slyly agai	0
+al foxes promise slyly according to the regular accounts. bold requests alon	1
+y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special 	1
+eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold	1
+y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d	4
+ALGERIA	0
+ARGENTINA	1
+BRAZIL	2
+CANADA	3
+EGYPT	4
+Sheri Nowmer	0
+Derrick Whelply	0
+Michael Spence	0
+Maya Gutierrez	0
+Roberta Damstra	0
+AFRICA	0
+AMERICA	1
+ASIA	2
+EUROPE	3
+MIDDLE EAST	4
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q14.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q14.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q14.tsv
new file mode 100644
index 0000000..754dca8
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q14.tsv
@@ -0,0 +1,30 @@
+0	ALGERIA
+1	ARGENTINA
+1	BRAZIL
+1	CANADA
+4	EGYPT
+0	ETHIOPIA
+3	FRANCE
+3	GERMANY
+2	INDIA
+2	INDONESIA
+4	IRAN
+4	IRAQ
+2	JAPAN
+4	JORDAN
+0	KENYA
+0	MOROCCO
+0	MOZAMBIQUE
+1	PERU
+2	CHINA
+3	ROMANIA
+4	SAUDI ARABIA
+2	VIETNAM
+3	RUSSIA
+3	UNITED KINGDOM
+1	UNITED STATES
+0	AFRICA
+1	AMERICA
+2	ASIA
+3	EUROPE
+4	MIDDLE EAST
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q15.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q15.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q15.tsv
new file mode 100644
index 0000000..64d2c1a
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q15.tsv
@@ -0,0 +1,10 @@
+0	0	ALGERIA
+1	1	ARGENTINA
+2	1	BRAZIL
+3	1	CANADA
+4	4	EGYPT
+1	0	abc
+1	1	abc
+1	1	abc
+1	1	abc
+1	4	abc
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q16.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q16.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q16.tsv
new file mode 100644
index 0000000..7588566
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q16.tsv
@@ -0,0 +1,5 @@
+1	0	abc
+1	1	abc
+1	1	abc
+1	1	abc
+1	4	abc
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q17.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q17.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q17.tsv
new file mode 100644
index 0000000..27aa989
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q17.tsv
@@ -0,0 +1,5 @@
+0	0	ALGERIA
+1	1	ARGENTINA
+2	1	BRAZIL
+3	1	CANADA
+4	4	EGYPT
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q2.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q2.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q2.tsv
new file mode 100644
index 0000000..b178657
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q2.tsv
@@ -0,0 +1,4 @@
+1
+2
+3
+4
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q3.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q3.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q3.tsv
new file mode 100644
index 0000000..5a7d813
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q3.tsv
@@ -0,0 +1,7 @@
+1
+2
+0
+1
+2
+3
+4
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q4.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q4.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q4.tsv
new file mode 100644
index 0000000..7988d37
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q4.tsv
@@ -0,0 +1,59 @@
+0
+1
+1
+1
+4
+0
+3
+3
+2
+2
+4
+4
+2
+4
+0
+0
+0
+1
+2
+3
+4
+2
+3
+3
+1
+0
+1
+2
+3
+4
+0
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+1
+2
+3
+4
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q5.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q5.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q5.tsv
new file mode 100644
index 0000000..e79abc2
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q5.tsv
@@ -0,0 +1,10 @@
+AFRICA	lar deposits. blithely final packages cajole. regular waters are final requests. regular accounts are according to 	0
+AMERICA	hs use ironic, even requests. s	1
+ASIA	ges. thinly even pinto beans ca	2
+EUROPE	ly final courts cajole furiously final excuse	3
+MIDDLE EAST	uickly special accounts cajole carefully blithely close requests. carefully final asymptotes haggle furiousl	4
+AFRICA	lar deposits. blithely final packages cajole. regular waters are final requests. regular accounts are according to 	0
+AMERICA	hs use ironic, even requests. s	1
+ASIA	ges. thinly even pinto beans ca	2
+EUROPE	ly final courts cajole furiously final excuse	3
+MIDDLE EAST	uickly special accounts cajole carefully blithely close requests. carefully final asymptotes haggle furiousl	4
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q6.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q6.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q6.tsv
new file mode 100644
index 0000000..e7127dd
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q6.tsv
@@ -0,0 +1,6 @@
+1	1
+2	1
+3	1
+17	1
+24	1
+2	2
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q6_1.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q6_1.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q6_1.tsv
new file mode 100644
index 0000000..408a141
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q6_1.tsv
@@ -0,0 +1,30 @@
+0	0
+1	1
+2	2
+3	3
+4	4
+5	5
+6	6
+7	7
+8	8
+9	9
+10	10
+11	11
+12	12
+13	13
+14	14
+15	15
+16	16
+17	17
+18	18
+19	19
+20	20
+21	21
+22	22
+23	23
+24	24
+0	0
+1	1
+2	2
+3	3
+4	4
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q7.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q7.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q7.tsv
new file mode 100644
index 0000000..995d6a6
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q7.tsv
@@ -0,0 +1,10 @@
+abc
+abc
+abc
+abc
+abc
+abcdefgh
+abcdefgh
+abcdefgh
+abcdefgh
+abcdefgh
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q8.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q8.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q8.tsv
new file mode 100644
index 0000000..4e9cb34
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q8.tsv
@@ -0,0 +1,30 @@
+ALGERIA	0
+ARGENTINA	1
+BRAZIL	2
+CANADA	3
+EGYPT	4
+ETHIOPIA	5
+FRANCE	6
+GERMANY	7
+INDIA	8
+INDONESIA	9
+IRAN	10
+IRAQ	11
+JAPAN	12
+JORDAN	13
+KENYA	14
+MOROCCO	15
+MOZAMBIQUE	16
+PERU	17
+CHINA	18
+ROMANIA	19
+SAUDI ARABIA	20
+VIETNAM	21
+RUSSIA	22
+UNITED KINGDOM	23
+UNITED STATES	24
+lar deposits. blithely final packages cajole. regular waters are final requests. regular accounts are according to 	0
+hs use ironic, even requests. s	1
+ges. thinly even pinto beans ca	2
+ly final courts cajole furiously final excuse	3
+uickly special accounts cajole carefully blithely close requests. carefully final asymptotes haggle furiousl	4
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/0368adf0/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q9.tsv
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q9.tsv b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q9.tsv
new file mode 100644
index 0000000..2fd5e7b
--- /dev/null
+++ b/exec/java-exec/src/test/resources/testframework/testUnionAllQueries/q9.tsv
@@ -0,0 +1,20 @@
+1292	F	104190.66	1994-01-20T00:00:00.000-08:00	5-LOW	Clerk#000000743	0	y pending requests integrate	66
+890	F	108594.87	1994-03-13T00:00:00.000-08:00	4-NOT SPECIFIED	Clerk#000000973	0	e carefully ironic packages. pending	99
+1180	F	67636.54	1994-01-01T00:00:00.000-08:00	4-NOT SPECIFIED	Clerk#000000735	0	efully dogged deposits. furiou	290
+1411	F	88375.89	1994-03-13T00:00:00.000-08:00	1-URGENT	Clerk#000000923	0	dolites. carefully regular pinto beans cajol	291
+392	F	121127.17	1994-03-26T00:00:00.000-08:00	1-URGENT	Clerk#000000959	0	arefully pending foxes sleep blithely. slyly express accoun	323
+1066	F	25542.02	1994-03-08T00:00:00.000-08:00	2-HIGH	Clerk#000000932	0	ke slyly bold pinto beans. blithely regular accounts against the spe	352
+1270	F	3266.69	1994-02-17T00:00:00.000-08:00	2-HIGH	Clerk#000000062	0	ing to the regular asymptotes. final, pending foxes about the blithely sil	389
+547	F	132531.73	1994-02-06T00:00:00.000-08:00	3-MEDIUM	Clerk#000000468	0	ironic, even packages. thinly unusual accounts sleep along the slyly unusual 	417
+793	F	34950.94	1994-03-10T00:00:00.000-08:00	1-URGENT	Clerk#000000448	0	 special pinto beans use quickly furiously even depende	673
+553	F	53948.73	1994-02-13T00:00:00.000-08:00	3-MEDIUM	Clerk#000000437	0	ts haggle quickly across the slyl	833
+163	P	95469.44	1995-03-18T00:00:00.000-08:00	1-URGENT	Clerk#000000632	0	ular requests are blithely pending orbits-- even requests against the deposit	65
+602	F	119718.02	1995-01-25T00:00:00.000-08:00	2-HIGH	Clerk#000000648	0	 haggle quickly. stealthily bold asymptotes haggle among the furiously even re	386
+475	P	213638.07	1995-03-05T00:00:00.000-08:00	4-NOT SPECIFIED	Clerk#000000293	0	d theodolites. boldly bold foxes since the pack	450
+578	P	261882.19	1995-03-25T00:00:00.000-08:00	2-HIGH	Clerk#000000354	0	g dependencies. regular accounts 	643
+1333	F	75392.93	1995-03-18T00:00:00.000-08:00	1-URGENT	Clerk#000000191	0	kly express requests. fluffily silent accounts poach furiously	775
+1367	F	192178.48	1995-01-05T00:00:00.000-08:00	1-URGENT	Clerk#000000516	0	posits. ironic, pending requests cajole. even theodol	802
+490	P	88281.28	1995-03-20T00:00:00.000-08:00	1-URGENT	Clerk#000000316	0	 wake quickly against 	897
+658	F	315638.02	1995-03-02T00:00:00.000-08:00	5-LOW	Clerk#000000450	0	ithely express pinto beans. 	928
+275	F	41838.38	1995-02-11T00:00:00.000-08:00	1-URGENT	Clerk#000000125	0	t, even deposits hang about the slyly special i	1056
+1232	P	131664.83	1995-03-04T00:00:00.000-08:00	3-MEDIUM	Clerk#000000006	0	re quickly along the blithe	1092
\ No newline at end of file


Mime
View raw message