You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by ja...@apache.org on 2013/07/20 03:58:00 UTC

[39/53] [abbrv] Types transition

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/store/JSONRecordReaderTest.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/store/JSONRecordReaderTest.java b/sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/store/JSONRecordReaderTest.java
index 4b35313..d8966ae 100644
--- a/sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/store/JSONRecordReaderTest.java
+++ b/sandbox/prototype/exec/java-exec/src/test/java/org/apache/drill/exec/store/JSONRecordReaderTest.java
@@ -12,6 +12,7 @@ import mockit.Expectations;
 import mockit.Injectable;
 
 import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.common.types.TypeProtos.MinorType;
 import org.apache.drill.exec.exception.SchemaChangeException;
 import org.apache.drill.exec.memory.DirectBufferAllocator;
 import org.apache.drill.exec.ops.FragmentContext;
@@ -25,270 +26,240 @@ import org.junit.Test;
 import com.beust.jcommander.internal.Lists;
 
 public class JSONRecordReaderTest {
-    private static final Charset UTF_8 = Charset.forName("UTF-8");
+  private static final Charset UTF_8 = Charset.forName("UTF-8");
 
-    private String getResource(String resourceName) {
-        return "resource:" + resourceName;
-    }
-
-    class MockOutputMutator implements OutputMutator {
-        List<Integer> removedFields = Lists.newArrayList();
-        List<ValueVector> addFields = Lists.newArrayList();
-
-        @Override
-        public void removeField(int fieldId) throws SchemaChangeException {
-            removedFields.add(fieldId);
-        }
-
-        @Override
-        public void addField(int fieldId, ValueVector vector) throws SchemaChangeException {
-            addFields.add(vector);
-        }
-
-        @Override
-        public void setNewSchema() throws SchemaChangeException {
-        }
-
-        List<Integer> getRemovedFields() {
-            return removedFields;
-        }
-
-        List<ValueVector> getAddFields() {
-            return addFields;
-        }
-    }
+  private String getResource(String resourceName) {
+    return "resource:" + resourceName;
+  }
 
-    private <T> void assertField(ValueVector valueVector, int index, SchemaDefProtos.MinorType expectedMinorType, T value, String name) {
-        assertField(valueVector, index, expectedMinorType, value, name, 0);
-    }
-
-    private <T> void assertField(ValueVector valueVector, int index, SchemaDefProtos.MinorType expectedMinorType, T value, String name, int parentFieldId) {
-        UserBitShared.FieldMetadata metadata = valueVector.getMetadata();
-        SchemaDefProtos.FieldDef def = metadata.getDef();
-        assertEquals(expectedMinorType, def.getMajorType().getMinorType());
-        assertEquals(name, def.getNameList().get(0).getName());
-        assertEquals(parentFieldId, def.getParentId());
-
-        if(expectedMinorType == SchemaDefProtos.MinorType.MAP) {
-            return;
-        }
-
-        T val = (T) valueVector.getAccessor().getObject(index);
-        if (val instanceof byte[]) {
-            assertTrue(Arrays.equals((byte[]) value, (byte[]) val));
-        } else {
-            assertEquals(value, val);
-        }
-    }
-
-    @Test
-    public void testSameSchemaInSameBatch(@Injectable final FragmentContext context) throws IOException, ExecutionSetupException {
-        new Expectations() {
-            {
-                context.getAllocator();
-                returns(new DirectBufferAllocator());
-            }
-        };
-        JSONRecordReader jr = new JSONRecordReader(context, getResource("scan_json_test_1.json"));
-
-        MockOutputMutator mutator = new MockOutputMutator();
-        List<ValueVector> addFields = mutator.getAddFields();
-        jr.setup(mutator);
-        assertEquals(2, jr.next());
-        assertEquals(3, addFields.size());
-        assertField(addFields.get(0), 0, SchemaDefProtos.MinorType.INT, 123, "test");
-        assertField(addFields.get(1), 0, SchemaDefProtos.MinorType.BOOLEAN, true, "b");
-        assertField(addFields.get(2), 0, SchemaDefProtos.MinorType.VARCHAR4, "hi!".getBytes(UTF_8), "c");
-        assertField(addFields.get(0), 1, SchemaDefProtos.MinorType.INT, 1234, "test");
-        assertField(addFields.get(1), 1, SchemaDefProtos.MinorType.BOOLEAN, false, "b");
-        assertField(addFields.get(2), 1, SchemaDefProtos.MinorType.VARCHAR4, "drill!".getBytes(UTF_8), "c");
-
-        assertEquals(0, jr.next());
-        assertTrue(mutator.getRemovedFields().isEmpty());
-    }
-
-    @Test
-    public void testChangedSchemaInSameBatch(@Injectable final FragmentContext context) throws IOException, ExecutionSetupException {
-        new Expectations() {
-            {
-                context.getAllocator();
-                returns(new DirectBufferAllocator());
-            }
-        };
-
-        JSONRecordReader jr = new JSONRecordReader(context, getResource("scan_json_test_2.json"));
-        MockOutputMutator mutator = new MockOutputMutator();
-        List<ValueVector> addFields = mutator.getAddFields();
-
-        jr.setup(mutator);
-        assertEquals(3, jr.next());
-        assertEquals(7, addFields.size());
-        assertField(addFields.get(0), 0, SchemaDefProtos.MinorType.INT, 123, "test");
-        assertField(addFields.get(1), 0, SchemaDefProtos.MinorType.INT, 1, "b");
-        assertField(addFields.get(2), 0, SchemaDefProtos.MinorType.FLOAT4, (float) 2.15, "c");
-        assertField(addFields.get(3), 0, SchemaDefProtos.MinorType.BOOLEAN, true, "bool");
-        assertField(addFields.get(4), 0, SchemaDefProtos.MinorType.VARCHAR4, "test1".getBytes(UTF_8), "str1");
-
-        assertField(addFields.get(0), 1, SchemaDefProtos.MinorType.INT, 1234, "test");
-        assertField(addFields.get(1), 1, SchemaDefProtos.MinorType.INT, 3, "b");
-        assertField(addFields.get(3), 1, SchemaDefProtos.MinorType.BOOLEAN, false, "bool");
-        assertField(addFields.get(4), 1, SchemaDefProtos.MinorType.VARCHAR4, "test2".getBytes(UTF_8), "str1");
-        assertField(addFields.get(5), 1, SchemaDefProtos.MinorType.INT, 4, "d");
-
-        assertField(addFields.get(0), 2, SchemaDefProtos.MinorType.INT, 12345, "test");
-        assertField(addFields.get(2), 2, SchemaDefProtos.MinorType.FLOAT4, (float) 5.16, "c");
-        assertField(addFields.get(3), 2, SchemaDefProtos.MinorType.BOOLEAN, true, "bool");
-        assertField(addFields.get(5), 2, SchemaDefProtos.MinorType.INT, 6, "d");
-        assertField(addFields.get(6), 2, SchemaDefProtos.MinorType.VARCHAR4, "test3".getBytes(UTF_8), "str2");
-        assertTrue(mutator.getRemovedFields().isEmpty());
-        assertEquals(0, jr.next());
-    }
+  class MockOutputMutator implements OutputMutator {
+    List<MaterializedField> removedFields = Lists.newArrayList();
+    List<ValueVector<?>> addFields = Lists.newArrayList();
 
-    @Test @Ignore
-    public void testChangedSchemaInTwoBatches(@Injectable final FragmentContext context) throws IOException, ExecutionSetupException {
-        new Expectations() {
-            {
-                context.getAllocator();
-                returns(new DirectBufferAllocator());
-            }
-        };
-
-        JSONRecordReader jr = new JSONRecordReader(context, getResource("scan_json_test_2.json"), 64); // batch only fits 1 int
-        MockOutputMutator mutator = new MockOutputMutator();
-        List<ValueVector> addFields = mutator.getAddFields();
-        List<Integer> removedFields = mutator.getRemovedFields();
-
-        jr.setup(mutator);
-        assertEquals(1, jr.next());
-        assertEquals(5, addFields.size());
-        assertField(addFields.get(0), 0, SchemaDefProtos.MinorType.INT, 123, "test");
-        assertField(addFields.get(1), 0, SchemaDefProtos.MinorType.INT, 1, "b");
-        assertField(addFields.get(2), 0, SchemaDefProtos.MinorType.FLOAT4, (float) 2.15, "c");
-        assertField(addFields.get(3), 0, SchemaDefProtos.MinorType.BOOLEAN, true, "bool");
-        assertField(addFields.get(4), 0, SchemaDefProtos.MinorType.VARCHAR4, "test1".getBytes(UTF_8), "str1");
-        assertTrue(removedFields.isEmpty());
-        assertEquals(1, jr.next());
-        assertEquals(6, addFields.size());
-        assertField(addFields.get(0), 0, SchemaDefProtos.MinorType.INT, 1234, "test");
-        assertField(addFields.get(1), 0, SchemaDefProtos.MinorType.INT, 3, "b");
-        assertField(addFields.get(3), 0, SchemaDefProtos.MinorType.BOOLEAN, false, "bool");
-        assertField(addFields.get(4), 0, SchemaDefProtos.MinorType.VARCHAR4, "test2".getBytes(UTF_8), "str1");
-        assertField(addFields.get(5), 0, SchemaDefProtos.MinorType.INT, 4, "d");
-        assertEquals(1, removedFields.size());
-        assertEquals(3, (int) removedFields.get(0));
-        removedFields.clear();
-        assertEquals(1, jr.next());
-        assertEquals(8, addFields.size()); // The reappearing of field 'c' is also included
-        assertField(addFields.get(0), 0, SchemaDefProtos.MinorType.INT, 12345, "test");
-        assertField(addFields.get(3), 0, SchemaDefProtos.MinorType.BOOLEAN, true, "bool");
-        assertField(addFields.get(5), 0, SchemaDefProtos.MinorType.INT, 6, "d");
-        assertField(addFields.get(6), 0, SchemaDefProtos.MinorType.FLOAT4, (float) 5.16, "c");
-        assertField(addFields.get(7), 0, SchemaDefProtos.MinorType.VARCHAR4, "test3".getBytes(UTF_8), "str2");
-        assertEquals(2, removedFields.size());
-        assertTrue(removedFields.contains(5));
-        assertTrue(removedFields.contains(2));
-        assertEquals(0, jr.next());
+    @Override
+    public void removeField(MaterializedField field) throws SchemaChangeException {
+      removedFields.add(field);
     }
 
-    @Ignore("Pending repeated map implementation")
-    @Test
-    public void testNestedFieldInSameBatch(@Injectable final FragmentContext context) throws ExecutionSetupException {
-        new Expectations() {
-            {
-                context.getAllocator();
-                returns(new DirectBufferAllocator());
-            }
-        };
-
-        JSONRecordReader jr = new JSONRecordReader(context, getResource("scan_json_test_3.json"));
-
-        MockOutputMutator mutator = new MockOutputMutator();
-        List<ValueVector> addFields = mutator.getAddFields();
-        jr.setup(mutator);
-        assertEquals(2, jr.next());
-        assertEquals(5, addFields.size());
-        assertField(addFields.get(0), 0, SchemaDefProtos.MinorType.INT, 123, "test");
-        assertField(addFields.get(1), 0, SchemaDefProtos.MinorType.MAP, null, "a");
-        assertField(addFields.get(2), 0, SchemaDefProtos.MinorType.VARCHAR4, "test".getBytes(UTF_8), "b", 2);
-        assertField(addFields.get(3), 0, SchemaDefProtos.MinorType.MAP, null, "a", 2);
-        assertField(addFields.get(4), 0, SchemaDefProtos.MinorType.BOOLEAN, 1, "d", 4);
-        assertField(addFields.get(0), 1, SchemaDefProtos.MinorType.INT, 1234, "test");
-        assertField(addFields.get(1), 1, SchemaDefProtos.MinorType.MAP, null, "a");
-        assertField(addFields.get(2), 1, SchemaDefProtos.MinorType.VARCHAR4, "test2".getBytes(UTF_8), "b", 2);
-        assertField(addFields.get(3), 1, SchemaDefProtos.MinorType.MAP, null, "a", 2);
-        assertField(addFields.get(4), 1, SchemaDefProtos.MinorType.BOOLEAN, 0, "d", 4);
-
-        assertEquals(0, jr.next());
-        assertTrue(mutator.getRemovedFields().isEmpty());
+    @Override
+    public void addField(ValueVector<?> vector) throws SchemaChangeException {
+      addFields.add(vector);
     }
 
-    /*
-
-    @Test
-    public void testScanJsonRemovedOneField() throws IOException {
-        ScanJson sj = new ScanJson(getResource("scan_json_test_3.json"));
-        PhysicalOperatorIterator iterator = sj.getIterator();
-        expectSchemaChanged(iterator);
-        DiffSchema diffSchema = expectSchemaChanged(iterator).getSchemaChanges();
-        assertEquals(0, diffSchema.getAddedFields().size());
-        assertEquals(1, diffSchema.getRemovedFields().size());
-        assertEquals(PhysicalOperatorIterator.NextOutcome.NONE_LEFT, iterator.next());
+    @Override
+    public void setNewSchema() throws SchemaChangeException {
     }
 
-    @Test
-    public void testScanJsonAddOneRemoveOne() throws IOException {
-        ScanJson sj = new ScanJson(getResource("scan_json_test_4.json"));
-        PhysicalOperatorIterator iterator = sj.getIterator();
-        expectSchemaChanged(iterator);
-        DiffSchema diffSchema = expectSchemaChanged(iterator).getSchemaChanges();
-        assertEquals(1, diffSchema.getAddedFields().size());
-        assertEquals(1, diffSchema.getRemovedFields().size());
-        assertEquals(PhysicalOperatorIterator.NextOutcome.NONE_LEFT, iterator.next());
+    List<MaterializedField> getRemovedFields() {
+      return removedFields;
     }
 
-    @Test
-    public void testScanJsonCycleAdditions() throws IOException {
-        ScanJson sj = new ScanJson(getResource("scan_json_test_5.json"));
-        PhysicalOperatorIterator iterator = sj.getIterator();
-        expectSchemaChanged(iterator);
-        DiffSchema diffSchema = expectSchemaChanged(iterator).getSchemaChanges();
-        assertEquals(1, diffSchema.getAddedFields().size());
-        assertEquals(1, diffSchema.getRemovedFields().size());
-        diffSchema = expectSchemaChanged(iterator).getSchemaChanges();
-        assertEquals(1, diffSchema.getAddedFields().size());
-        assertEquals(Field.FieldType.FLOAT, diffSchema.getAddedFields().get(0).getFieldType());
-        assertEquals("test2", diffSchema.getAddedFields().get(0).getFieldName());
-        assertEquals(1, diffSchema.getRemovedFields().size());
-        assertEquals(Field.FieldType.BOOLEAN, diffSchema.getRemovedFields().get(0).getFieldType());
-        assertEquals("test3", diffSchema.getRemovedFields().get(0).getFieldName());
-        assertEquals(PhysicalOperatorIterator.NextOutcome.NONE_LEFT, iterator.next());
+    List<ValueVector<?>> getAddFields() {
+      return addFields;
     }
+  }
 
-    @Test
-    public void testScanJsonModifiedOneFieldType() throws IOException {
-        ScanJson sj = new ScanJson(getResource("scan_json_test_6.json"));
-        PhysicalOperatorIterator iterator = sj.getIterator();
-        expectSchemaChanged(iterator);
-        DiffSchema diffSchema = expectSchemaChanged(iterator).getSchemaChanges();
-        List<Field> addedFields = diffSchema.getAddedFields();
-        assertEquals(4, addedFields.size());
-        List<Field> removedFields = diffSchema.getRemovedFields();
-        assertEquals(4, removedFields.size());
-        assertFieldExists("test", Field.FieldType.STRING, addedFields);
-        assertFieldExists("test2", Field.FieldType.BOOLEAN, addedFields);
-        assertFieldExists("b", Field.FieldType.ARRAY, addedFields);
-        assertFieldExists("[0]", Field.FieldType.INTEGER, addedFields);
-        assertFieldExists("test", Field.FieldType.INTEGER, removedFields);
-        assertFieldExists("test2", Field.FieldType.ARRAY, removedFields);
-        assertFieldExists("b", Field.FieldType.INTEGER, removedFields);
-        assertFieldExists("[0]", Field.FieldType.INTEGER, removedFields);
-        assertEquals(PhysicalOperatorIterator.NextOutcome.NONE_LEFT, iterator.next());
-    }
+  private <T> void assertField(ValueVector valueVector, int index, MinorType expectedMinorType, T value, String name) {
+    UserBitShared.FieldMetadata metadata = valueVector.getMetadata();
+    SchemaDefProtos.FieldDef def = metadata.getDef();
+    assertEquals(expectedMinorType, def.getMajorType().getMinorType());
+    assertEquals(name, def.getNameList().get(0).getName());
 
-    private void expectSchemaChanged(PhysicalOperatorIterator iterator) throws IOException {
+    if (expectedMinorType == MinorType.MAP) {
+      return;
     }
 
-    private void expectDataRecord(PhysicalOperatorIterator iterator) throws IOException {
+    T val = (T) valueVector.getObject(index);
+    if (val instanceof byte[]) {
+      assertTrue(Arrays.equals((byte[]) value, (byte[]) val));
+    } else {
+      assertEquals(value, val);
     }
-*/
+  }
+
+  @Test
+  public void testSameSchemaInSameBatch(@Injectable final FragmentContext context) throws IOException,
+      ExecutionSetupException {
+    new Expectations() {
+      {
+        context.getAllocator();
+        returns(new DirectBufferAllocator());
+      }
+    };
+    JSONRecordReader jr = new JSONRecordReader(context, getResource("scan_json_test_1.json"));
+
+    MockOutputMutator mutator = new MockOutputMutator();
+    List<ValueVector<?>> addFields = mutator.getAddFields();
+    jr.setup(mutator);
+    assertEquals(2, jr.next());
+    assertEquals(3, addFields.size());
+    assertField(addFields.get(0), 0, MinorType.INT, 123, "test");
+    assertField(addFields.get(1), 0, MinorType.BOOLEAN, 1, "b");
+    assertField(addFields.get(2), 0, MinorType.VARCHAR4, "hi!".getBytes(UTF_8), "c");
+    assertField(addFields.get(0), 1, MinorType.INT, 1234, "test");
+    assertField(addFields.get(1), 1, MinorType.BOOLEAN, 0, "b");
+    assertField(addFields.get(2), 1, MinorType.VARCHAR4, "drill!".getBytes(UTF_8), "c");
+
+    assertEquals(0, jr.next());
+    assertTrue(mutator.getRemovedFields().isEmpty());
+  }
+
+  @Test
+  public void testChangedSchemaInSameBatch(@Injectable final FragmentContext context) throws IOException,
+      ExecutionSetupException {
+    new Expectations() {
+      {
+        context.getAllocator();
+        returns(new DirectBufferAllocator());
+      }
+    };
+
+    JSONRecordReader jr = new JSONRecordReader(context, getResource("scan_json_test_2.json"));
+    MockOutputMutator mutator = new MockOutputMutator();
+    List<ValueVector<?>> addFields = mutator.getAddFields();
+
+    jr.setup(mutator);
+    assertEquals(3, jr.next());
+    assertEquals(7, addFields.size());
+    assertField(addFields.get(0), 0, MinorType.INT, 123, "test");
+    assertField(addFields.get(1), 0, MinorType.INT, 1, "b");
+    assertField(addFields.get(2), 0, MinorType.FLOAT4, (float) 2.15, "c");
+    assertField(addFields.get(3), 0, MinorType.BOOLEAN, 1, "bool");
+    assertField(addFields.get(4), 0, MinorType.VARCHAR4, "test1".getBytes(UTF_8), "str1");
+
+    assertField(addFields.get(0), 1, MinorType.INT, 1234, "test");
+    assertField(addFields.get(1), 1, MinorType.INT, 3, "b");
+    assertField(addFields.get(3), 1, MinorType.BOOLEAN, 0, "bool");
+    assertField(addFields.get(4), 1, MinorType.VARCHAR4, "test2".getBytes(UTF_8), "str1");
+    assertField(addFields.get(5), 1, MinorType.INT, 4, "d");
+
+    assertField(addFields.get(0), 2, MinorType.INT, 12345, "test");
+    assertField(addFields.get(2), 2, MinorType.FLOAT4, (float) 5.16, "c");
+    assertField(addFields.get(3), 2, MinorType.BOOLEAN, 1, "bool");
+    assertField(addFields.get(5), 2, MinorType.INT, 6, "d");
+    assertField(addFields.get(6), 2, MinorType.VARCHAR4, "test3".getBytes(UTF_8), "str2");
+    assertTrue(mutator.getRemovedFields().isEmpty());
+    assertEquals(0, jr.next());
+  }
+
+  @Test
+  public void testChangedSchemaInTwoBatches(@Injectable final FragmentContext context) throws IOException,
+      ExecutionSetupException {
+    new Expectations() {
+      {
+        context.getAllocator();
+        returns(new DirectBufferAllocator());
+      }
+    };
+
+    JSONRecordReader jr = new JSONRecordReader(context, getResource("scan_json_test_2.json"), 64); // batch only fits 1
+                                                                                                   // int
+    MockOutputMutator mutator = new MockOutputMutator();
+    List<ValueVector<?>> addFields = mutator.getAddFields();
+    List<MaterializedField> removedFields = mutator.getRemovedFields();
+
+    jr.setup(mutator);
+    assertEquals(1, jr.next());
+    assertEquals(5, addFields.size());
+    assertField(addFields.get(0), 0, MinorType.INT, 123, "test");
+    assertField(addFields.get(1), 0, MinorType.INT, 1, "b");
+    assertField(addFields.get(2), 0, MinorType.FLOAT4, (float) 2.15, "c");
+    assertField(addFields.get(3), 0, MinorType.BOOLEAN, 1, "bool");
+    assertField(addFields.get(4), 0, MinorType.VARCHAR4, "test1".getBytes(UTF_8), "str1");
+    assertTrue(removedFields.isEmpty());
+    assertEquals(1, jr.next());
+    assertEquals(6, addFields.size());
+    assertField(addFields.get(0), 0, MinorType.INT, 1234, "test");
+    assertField(addFields.get(1), 0, MinorType.INT, 3, "b");
+    assertField(addFields.get(3), 0, MinorType.BOOLEAN, 0, "bool");
+    assertField(addFields.get(4), 0, MinorType.VARCHAR4, "test2".getBytes(UTF_8), "str1");
+    assertField(addFields.get(5), 0, MinorType.INT, 4, "d");
+    assertEquals(1, removedFields.size());
+    //assertEquals(3, (int) removedFields.get(0));
+    removedFields.clear();
+    assertEquals(1, jr.next());
+    assertEquals(8, addFields.size()); // The reappearing of field 'c' is also included
+    assertField(addFields.get(0), 0, MinorType.INT, 12345, "test");
+    assertField(addFields.get(3), 0, MinorType.BOOLEAN, 1, "bool");
+    assertField(addFields.get(5), 0, MinorType.INT, 6, "d");
+    assertField(addFields.get(6), 0, MinorType.FLOAT4, (float) 5.16, "c");
+    assertField(addFields.get(7), 0, MinorType.VARCHAR4, "test3".getBytes(UTF_8), "str2");
+    assertEquals(2, removedFields.size());
+//    assertTrue(removedFields.contains(5));
+//    assertTrue(removedFields.contains(2));
+    assertEquals(0, jr.next());
+  }
+
+  @Test
+  public void testNestedFieldInSameBatch(@Injectable final FragmentContext context) throws ExecutionSetupException {
+    new Expectations() {
+      {
+        context.getAllocator();
+        returns(new DirectBufferAllocator());
+      }
+    };
+
+    JSONRecordReader jr = new JSONRecordReader(context, getResource("scan_json_test_3.json"));
+
+    MockOutputMutator mutator = new MockOutputMutator();
+    List<ValueVector<?>> addFields = mutator.getAddFields();
+    jr.setup(mutator);
+    assertEquals(2, jr.next());
+    assertEquals(5, addFields.size());
+    assertField(addFields.get(0), 0, MinorType.INT, 123, "test");
+    assertField(addFields.get(1), 0, MinorType.MAP, null, "a");
+    assertField(addFields.get(2), 0, MinorType.VARCHAR4, "test".getBytes(UTF_8), "b");
+    assertField(addFields.get(3), 0, MinorType.MAP, null, "a");
+    assertField(addFields.get(4), 0, MinorType.BOOLEAN, 1, "d");
+    assertField(addFields.get(0), 1, MinorType.INT, 1234, "test");
+    assertField(addFields.get(1), 1, MinorType.MAP, null, "a");
+    assertField(addFields.get(2), 1, MinorType.VARCHAR4, "test2".getBytes(UTF_8), "b");
+    assertField(addFields.get(3), 1, MinorType.MAP, null, "a");
+    assertField(addFields.get(4), 1, MinorType.BOOLEAN, 0, "d");
+
+    assertEquals(0, jr.next());
+    assertTrue(mutator.getRemovedFields().isEmpty());
+  }
+
+  /*
+   * 
+   * @Test public void testScanJsonRemovedOneField() throws IOException { ScanJson sj = new
+   * ScanJson(getResource("scan_json_test_3.json")); PhysicalOperatorIterator iterator = sj.getIterator();
+   * expectSchemaChanged(iterator); DiffSchema diffSchema = expectSchemaChanged(iterator).getSchemaChanges();
+   * assertEquals(0, diffSchema.getAddedFields().size()); assertEquals(1, diffSchema.getRemovedFields().size());
+   * assertEquals(PhysicalOperatorIterator.NextOutcome.NONE_LEFT, iterator.next()); }
+   * 
+   * @Test public void testScanJsonAddOneRemoveOne() throws IOException { ScanJson sj = new
+   * ScanJson(getResource("scan_json_test_4.json")); PhysicalOperatorIterator iterator = sj.getIterator();
+   * expectSchemaChanged(iterator); DiffSchema diffSchema = expectSchemaChanged(iterator).getSchemaChanges();
+   * assertEquals(1, diffSchema.getAddedFields().size()); assertEquals(1, diffSchema.getRemovedFields().size());
+   * assertEquals(PhysicalOperatorIterator.NextOutcome.NONE_LEFT, iterator.next()); }
+   * 
+   * @Test public void testScanJsonCycleAdditions() throws IOException { ScanJson sj = new
+   * ScanJson(getResource("scan_json_test_5.json")); PhysicalOperatorIterator iterator = sj.getIterator();
+   * expectSchemaChanged(iterator); DiffSchema diffSchema = expectSchemaChanged(iterator).getSchemaChanges();
+   * assertEquals(1, diffSchema.getAddedFields().size()); assertEquals(1, diffSchema.getRemovedFields().size());
+   * diffSchema = expectSchemaChanged(iterator).getSchemaChanges(); assertEquals(1, diffSchema.getAddedFields().size());
+   * assertEquals(Field.FieldType.FLOAT, diffSchema.getAddedFields().get(0).getFieldType()); assertEquals("test2",
+   * diffSchema.getAddedFields().get(0).getFieldName()); assertEquals(1, diffSchema.getRemovedFields().size());
+   * assertEquals(Field.FieldType.BOOLEAN, diffSchema.getRemovedFields().get(0).getFieldType()); assertEquals("test3",
+   * diffSchema.getRemovedFields().get(0).getFieldName()); assertEquals(PhysicalOperatorIterator.NextOutcome.NONE_LEFT,
+   * iterator.next()); }
+   * 
+   * @Test public void testScanJsonModifiedOneFieldType() throws IOException { ScanJson sj = new
+   * ScanJson(getResource("scan_json_test_6.json")); PhysicalOperatorIterator iterator = sj.getIterator();
+   * expectSchemaChanged(iterator); DiffSchema diffSchema = expectSchemaChanged(iterator).getSchemaChanges();
+   * List<Field> addedFields = diffSchema.getAddedFields(); assertEquals(4, addedFields.size()); List<Field>
+   * removedFields = diffSchema.getRemovedFields(); assertEquals(4, removedFields.size()); assertFieldExists("test",
+   * Field.FieldType.STRING, addedFields); assertFieldExists("test2", Field.FieldType.BOOLEAN, addedFields);
+   * assertFieldExists("b", Field.FieldType.ARRAY, addedFields); assertFieldExists("[0]", Field.FieldType.INTEGER,
+   * addedFields); assertFieldExists("test", Field.FieldType.INTEGER, removedFields); assertFieldExists("test2",
+   * Field.FieldType.ARRAY, removedFields); assertFieldExists("b", Field.FieldType.INTEGER, removedFields);
+   * assertFieldExists("[0]", Field.FieldType.INTEGER, removedFields);
+   * assertEquals(PhysicalOperatorIterator.NextOutcome.NONE_LEFT, iterator.next()); }
+   * 
+   * private void expectSchemaChanged(PhysicalOperatorIterator iterator) throws IOException { }
+   * 
+   * private void expectDataRecord(PhysicalOperatorIterator iterator) throws IOException { }
+   */
 }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/RunOutcome.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/RunOutcome.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/RunOutcome.java
index 069892a..1e5b226 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/RunOutcome.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/RunOutcome.java
@@ -31,6 +31,7 @@ public class RunOutcome {
   
   public RunOutcome(OutcomeType outcome, long bytes, long records, Throwable exception) {
     super();
+    if(outcome != OutcomeType.SUCCESS) logger.warn("Creating failed outcome.", exception);
     this.outcome = outcome;
     this.bytes = bytes;
     this.records = records;

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/BasicEvaluatorFactory.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/BasicEvaluatorFactory.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/BasicEvaluatorFactory.java
index 2718db7..ad86b73 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/BasicEvaluatorFactory.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/BasicEvaluatorFactory.java
@@ -20,6 +20,7 @@ package org.apache.drill.exec.ref.eval;
 import org.apache.drill.common.expression.LogicalExpression;
 import org.apache.drill.common.expression.SchemaPath;
 import org.apache.drill.common.expression.visitors.ExprVisitor;
+import org.apache.drill.common.expression.visitors.SimpleExprVisitor;
 import org.apache.drill.common.logical.data.NamedExpression;
 import org.apache.drill.exec.ref.IteratorRegistry;
 import org.apache.drill.exec.ref.RecordPointer;
@@ -38,13 +39,13 @@ public class BasicEvaluatorFactory extends EvaluatorFactory{
     
   }
   
-  private ExprVisitor<BasicEvaluator> get(RecordPointer record){
+  private SimpleExprVisitor<BasicEvaluator> get(RecordPointer record){
     return new SimpleEvaluationVisitor(record);
   }
   
   @Override
   public BasicEvaluator getBasicEvaluator(RecordPointer inputRecord, LogicalExpression e) {
-    return e.accept(get(inputRecord));
+    return e.accept(get(inputRecord), null);
   }
   
 
@@ -52,13 +53,13 @@ public class BasicEvaluatorFactory extends EvaluatorFactory{
   @Override
   public AggregatingEvaluator getAggregatingOperator(RecordPointer record, LogicalExpression e) {
     SimpleEvaluationVisitor visitor = new SimpleEvaluationVisitor(record);
-    BasicEvaluator b = e.accept(visitor);
+    BasicEvaluator b = e.accept(visitor, null);
     return new AggregatingWrapperEvaluator(visitor.getAggregators(), b);
   }
 
   @Override
   public BooleanEvaluator getBooleanEvaluator(RecordPointer record, LogicalExpression e) {
-    return new BooleanEvaluatorImpl(e.accept(get(record)));
+    return new BooleanEvaluatorImpl(e.accept(get(record),  null));
   }
 
   @Override
@@ -89,7 +90,7 @@ public class BasicEvaluatorFactory extends EvaluatorFactory{
     public ConnectedEvaluatorImpl(RecordPointer record, NamedExpression e){
       this.outputPath = e.getRef();
       this.record = record;
-      this.eval = e.getExpr().accept(get(record));
+      this.eval = e.getExpr().accept(get(record), null);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/IfEvaluator.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/IfEvaluator.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/IfEvaluator.java
index 2e5770b..c78980a 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/IfEvaluator.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/IfEvaluator.java
@@ -31,12 +31,12 @@ public class IfEvaluator implements BasicEvaluator{
   private final IfCond[] conditions;
   private final BasicEvaluator elseExpression;
   
-  public IfEvaluator(IfExpression expression, ExprVisitor<BasicEvaluator> evalBuilder, RecordPointer record){
+  public IfEvaluator(IfExpression expression, ExprVisitor<BasicEvaluator, Void, RuntimeException> evalBuilder, RecordPointer record){
     this.conditions = new IfCond[expression.conditions.size()];
     for(int i =0; i < conditions.length; i++){
       conditions[i] = new IfCond(expression.conditions.get(i), evalBuilder);
     }
-    elseExpression = expression.elseExpression.accept(evalBuilder);
+    elseExpression = expression.elseExpression.accept(evalBuilder, null);
   }
   
   @Override
@@ -51,9 +51,9 @@ public class IfEvaluator implements BasicEvaluator{
     private final BasicEvaluator condition;
     private final BasicEvaluator valueExpression;
 
-    public IfCond(IfCondition c, ExprVisitor<BasicEvaluator> evalBuilder){
-      this.condition = c.condition.accept(evalBuilder);
-      this.valueExpression = c.expression.accept(evalBuilder);
+    public IfCond(IfCondition c, ExprVisitor<BasicEvaluator, Void, RuntimeException> evalBuilder){
+      this.condition = c.condition.accept(evalBuilder, null);
+      this.valueExpression = c.expression.accept(evalBuilder, null);
     }
     
     public boolean matches(RecordPointer r){

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/SimpleEvaluationVisitor.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/SimpleEvaluationVisitor.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/SimpleEvaluationVisitor.java
index f03648b..5b2c781 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/SimpleEvaluationVisitor.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/SimpleEvaluationVisitor.java
@@ -22,6 +22,7 @@ import java.util.List;
 
 import org.antlr.runtime.ANTLRStringStream;
 import org.antlr.runtime.CommonTokenStream;
+import org.apache.drill.common.expression.ExpressionPosition;
 import org.apache.drill.common.expression.FunctionCall;
 import org.apache.drill.common.expression.IfExpression;
 import org.apache.drill.common.expression.LogicalExpression;
@@ -34,7 +35,7 @@ import org.apache.drill.common.expression.parser.ExprLexer;
 import org.apache.drill.common.expression.parser.ExprParser;
 import org.apache.drill.common.expression.visitors.AggregateChecker;
 import org.apache.drill.common.expression.visitors.ConstantChecker;
-import org.apache.drill.common.expression.visitors.ExprVisitor;
+import org.apache.drill.common.expression.visitors.SimpleExprVisitor;
 import org.apache.drill.exec.ref.RecordPointer;
 import org.apache.drill.exec.ref.UnbackedRecord;
 import org.apache.drill.exec.ref.eval.EvaluatorTypes.AggregatingEvaluator;
@@ -49,7 +50,7 @@ import org.apache.drill.exec.ref.values.ScalarValues.IntegerScalar;
 import org.apache.drill.exec.ref.values.ScalarValues.LongScalar;
 import org.apache.drill.exec.ref.values.ScalarValues.StringScalar;
 
-public class SimpleEvaluationVisitor implements ExprVisitor<BasicEvaluator>{
+public class SimpleEvaluationVisitor extends SimpleExprVisitor<BasicEvaluator>{
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SimpleEvaluationVisitor.class);
 
   private RecordPointer record;
@@ -72,7 +73,7 @@ public class SimpleEvaluationVisitor implements ExprVisitor<BasicEvaluator>{
     for(LogicalExpression e : call){
       if(AggregateChecker.isAggregating(e)) includesAggregates = true;
       if(!ConstantChecker.onlyIncludesConstants(e)) onlyConstants = false;
-      evals.add(e.accept(this));
+      evals.add(e.accept(this, null));
     }
     FunctionArguments args = new FunctionArguments(onlyConstants, includesAggregates, evals, call);
 
@@ -102,26 +103,31 @@ public class SimpleEvaluationVisitor implements ExprVisitor<BasicEvaluator>{
   }
 
   @Override
-  public BasicEvaluator visitLongExpression(LongExpression longExpr) {
+  public BasicEvaluator visitLongConstant(LongExpression longExpr) {
     return new LongScalar(longExpr.getLong());
   }
 
   @Override
-  public BasicEvaluator visitDoubleExpression(DoubleExpression dExpr) {
+  public BasicEvaluator visitDoubleConstant(DoubleExpression dExpr) {
     return new DoubleScalar(dExpr.getDouble());
   }
 
   @Override
-  public BasicEvaluator visitBoolean(BooleanExpression e) {
+  public BasicEvaluator visitBooleanConstant(BooleanExpression e) {
     return new BooleanScalar(e.getBoolean());
   }
 
   @Override
-  public BasicEvaluator visitQuotedString(QuotedString e) {
+  public BasicEvaluator visitQuotedStringConstant(QuotedString e) {
     return new StringScalar(e.value);
   }
   
   
+  @Override
+  public BasicEvaluator visitUnknown(LogicalExpression e, Void value) throws RuntimeException {
+    throw new UnsupportedOperationException();
+  }
+
   public static void main(String[] args) throws Exception {
     String expr = "if( a == 1) then 4 else 2 end";
     ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
@@ -129,9 +135,9 @@ public class SimpleEvaluationVisitor implements ExprVisitor<BasicEvaluator>{
     ExprParser parser = new ExprParser(tokens);
     LogicalExpression e = parser.parse().e;
     RecordPointer r = new UnbackedRecord();
-    r.addField(new SchemaPath("a"), new IntegerScalar(3));
+    r.addField(new SchemaPath("a", ExpressionPosition.UNKNOWN), new IntegerScalar(3));
     SimpleEvaluationVisitor builder = new SimpleEvaluationVisitor(r);
-    BasicEvaluator eval = e.accept(builder);
+    BasicEvaluator eval = e.accept(builder, null);
     DataValue v = eval.eval();
     System.out.println(v);
   }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/fn/MathEvaluators.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/fn/MathEvaluators.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/fn/MathEvaluators.java
index bdf9de7..d080cd3 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/fn/MathEvaluators.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/eval/fn/MathEvaluators.java
@@ -17,6 +17,7 @@
  ******************************************************************************/
 package org.apache.drill.exec.ref.eval.fn;
 
+import org.apache.drill.common.types.Types;
 import org.apache.drill.exec.ref.RecordPointer;
 import org.apache.drill.exec.ref.eval.BaseBasicEvaluator;
 import org.apache.drill.exec.ref.eval.EvaluatorTypes.BasicEvaluator;
@@ -43,7 +44,7 @@ public class MathEvaluators {
       NumericValue[] values = new NumericValue[args.length];
       for(int i =0; i < values.length; i++){
         DataValue v = args[i].eval();
-        if(v.getDataType().isNumericType()){
+        if(Types.isNumericType(v.getDataType())){
           values[i] = v.getAsNumeric();
         }
       }
@@ -71,7 +72,7 @@ public class MathEvaluators {
       for(int i =0; i < args.length; i++){
         final DataValue v = args[i].eval();
 //        logger.debug("DataValue {}", v);
-        if(v.getDataType().isNumericType()){
+        if(Types.isNumericType(v.getDataType())){
           NumericValue n = v.getAsNumeric();
           NumericType nt = n.getNumericType();
 //          logger.debug("Numeric Type: {}", nt);

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/CollapsingAggregateROP.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/CollapsingAggregateROP.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/CollapsingAggregateROP.java
index 4861bc6..e2160b5 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/CollapsingAggregateROP.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/CollapsingAggregateROP.java
@@ -19,8 +19,8 @@ package org.apache.drill.exec.ref.rops;
 
 import org.apache.drill.common.expression.FieldReference;
 import org.apache.drill.common.expression.SchemaPath;
-import org.apache.drill.common.expression.types.DataType;
 import org.apache.drill.common.logical.data.CollapsingAggregate;
+import org.apache.drill.common.types.TypeProtos.MinorType;
 import org.apache.drill.exec.ref.RecordIterator;
 import org.apache.drill.exec.ref.RecordPointer;
 import org.apache.drill.exec.ref.UnbackedRecord;
@@ -159,7 +159,7 @@ public class CollapsingAggregateROP extends SingleInputROPBase<CollapsingAggrega
       // if we're in target mode and this row matches the target criteria, we're going to copy carry over values and mark foundTarget = true.
       if(targetMode){
         DataValue v = targetEvaluator.eval();
-        if(v.getDataType() == DataType.BOOLEAN && v.getAsBooleanValue().getBoolean()){
+        if(v.getDataType().getMinorType() == MinorType.BOOLEAN && v.getAsBooleanValue().getBoolean()){
           foundTarget = true;
           for(int i =0 ; i < carryovers.length; i++){
             carryoverValues[i] = carryovers[i].eval();

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/ConstantROP.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/ConstantROP.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/ConstantROP.java
index ffc6cc8..5d6f91f 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/ConstantROP.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/ConstantROP.java
@@ -17,7 +17,6 @@
  ******************************************************************************/
 package org.apache.drill.exec.ref.rops;
 
-import java.io.IOException;
 import java.util.Iterator;
 
 import org.apache.drill.common.logical.data.Constant;
@@ -28,14 +27,12 @@ import org.apache.drill.exec.ref.RunOutcome.OutcomeType;
 import org.apache.drill.exec.ref.UnbackedRecord;
 import org.apache.drill.exec.ref.exceptions.SetupException;
 import org.apache.drill.exec.ref.rse.JSONRecordReader;
-import org.apache.drill.exec.ref.rse.RecordReader;
 
 import com.fasterxml.jackson.databind.JsonNode;
 
 public class ConstantROP extends ROPBase<Constant>{
     static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ScanROP.class);
 
-    private ConstantIterator iter;
     private UnbackedRecord record;
 
     public ConstantROP(Constant config) {

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/FlattenROP.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/FlattenROP.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/FlattenROP.java
index 64eca8b..f6e6907 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/FlattenROP.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/FlattenROP.java
@@ -17,12 +17,9 @@
  ******************************************************************************/
 package org.apache.drill.exec.ref.rops;
 
-import org.apache.drill.common.expression.FieldReference;
-import org.apache.drill.common.expression.PathSegment;
 import org.apache.drill.common.expression.SchemaPath;
-import org.apache.drill.common.expression.types.DataType;
-import org.apache.drill.common.logical.data.NamedExpression;
 import org.apache.drill.common.logical.data.Flatten;
+import org.apache.drill.common.types.TypeProtos.DataMode;
 import org.apache.drill.exec.ref.RecordIterator;
 import org.apache.drill.exec.ref.RecordPointer;
 import org.apache.drill.exec.ref.UnbackedRecord;
@@ -109,7 +106,7 @@ public class FlattenROP extends SingleInputROPBase<Flatten> {
 
 
       if (currentOutcome != NextOutcome.NONE_LEFT) {
-        if (evaluator.eval().getDataType() == DataType.ARRAY) {
+        if (evaluator.eval().getDataType().getMode() == DataMode.REPEATED) {
           arrayValueIterator = new ArrayValueIterator(evaluator.eval().getAsContainer().getAsArray());
 
           while ((v = arrayValueIterator.next()) != null) {

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/WindowFrameROP.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/WindowFrameROP.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/WindowFrameROP.java
index 4ed1642..e5b153e 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/WindowFrameROP.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/WindowFrameROP.java
@@ -23,6 +23,7 @@ import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Queues;
 import org.apache.drill.common.exceptions.DrillRuntimeException;
+import org.apache.drill.common.expression.ExpressionPosition;
 import org.apache.drill.common.expression.FieldReference;
 import org.apache.drill.common.logical.data.WindowFrame;
 import org.apache.drill.exec.ref.RecordIterator;
@@ -52,11 +53,11 @@ public class WindowFrameROP extends SingleInputROPBase<WindowFrame> {
         }
 
         if (positionRef == null) {
-            positionRef = new FieldReference("ref.position");
+            positionRef = new FieldReference("ref.position", ExpressionPosition.UNKNOWN);
         }
 
         if (segmentRef == null) {
-            segmentRef = new FieldReference("ref.segment");
+            segmentRef = new FieldReference("ref.segment", ExpressionPosition.UNKNOWN);
         }
 
         withinRef = config.getWithin();

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/BaseArrayValue.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/BaseArrayValue.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/BaseArrayValue.java
index 503c835..5831d37 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/BaseArrayValue.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/BaseArrayValue.java
@@ -18,13 +18,28 @@
 package org.apache.drill.exec.ref.values;
 
 import org.apache.drill.common.expression.PathSegment;
-import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.types.TypeProtos.DataMode;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.TypeProtos.MinorType;
+import org.apache.tools.ant.types.DataType;
 
 
 public abstract class BaseArrayValue extends BaseDataValue implements ContainerValue{
 
+  private MajorType initiatingType;
+  private MajorType runningType = MajorType.newBuilder().setMode(DataMode.REPEATED).setMinorType(MinorType.LATE).build();
+  
   @Override
   public void addValue(PathSegment segment, DataValue v) {
+    if(initiatingType == null){
+      initiatingType = v.getDataType();
+      runningType = initiatingType.toBuilder().setMode(DataMode.REPEATED).build();
+    }else{
+      if(!v.getDataType().equals(initiatingType)){
+        throw new RuntimeException("The reference interpreter doesn't support polymorphic types.");
+      }
+    }
+    
     DataValue fullPathValue = ValueUtils.getIntermediateValues(segment.getChild(), v);
     if(segment.isArray()){ // we need to place this object in the given position.
       int index = segment.getArraySegment().getIndex();
@@ -60,8 +75,8 @@ public abstract class BaseArrayValue extends BaseDataValue implements ContainerV
   }
 
   @Override
-  public DataType getDataType() {
-    return DataType.ARRAY;
+  public MajorType getDataType() {
+    return runningType;
   }
   
   

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/BaseMapValue.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/BaseMapValue.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/BaseMapValue.java
index 4fa7a51..87bd344 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/BaseMapValue.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/BaseMapValue.java
@@ -21,8 +21,11 @@ import java.util.Map;
 
 import org.apache.drill.common.expression.PathSegment;
 import org.apache.drill.common.expression.ValueExpressions.CollisionBehavior;
-import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.types.TypeProtos.DataMode;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.TypeProtos.MinorType;
 import org.apache.drill.exec.ref.exceptions.RecordException;
+import org.apache.tools.ant.types.DataType;
 
 public abstract class BaseMapValue extends BaseDataValue implements ContainerValue,
     Iterable<Map.Entry<CharSequence, DataValue>> {
@@ -91,8 +94,8 @@ public abstract class BaseMapValue extends BaseDataValue implements ContainerVal
   }
 
   @Override
-  public DataType getDataType() {
-    return DataType.MAP;
+  public MajorType getDataType() {
+    return MajorType.newBuilder().setMinorType(MinorType.REPEATMAP).setMode(DataMode.REPEATED).build();
   }
 
   public void merge(BaseMapValue otherMap) {

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/DataValue.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/DataValue.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/DataValue.java
index c1a2980..fca9cbb 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/DataValue.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/DataValue.java
@@ -3,7 +3,7 @@ package org.apache.drill.exec.ref.values;
 import java.io.IOException;
 
 import org.apache.drill.common.expression.PathSegment;
-import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.types.TypeProtos.MajorType;
 import org.apache.drill.exec.ref.rops.DataWriter;
 
 
@@ -15,7 +15,7 @@ public interface DataValue {
   public void addValue(PathSegment segment, DataValue v);
   public void removeValue(PathSegment segment);
   public void write(DataWriter writer) throws IOException;
-  public DataType getDataType();
+  public MajorType getDataType();
   public NumericValue getAsNumeric();
   public ContainerValue getAsContainer();
   public StringValue getAsStringValue();

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/NumericValue.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/NumericValue.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/NumericValue.java
index 88efb92..45b8174 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/NumericValue.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/NumericValue.java
@@ -21,6 +21,7 @@ import java.math.BigDecimal;
 import java.math.BigInteger;
 
 import org.apache.drill.common.exceptions.DrillRuntimeException;
+import org.apache.drill.common.types.Types;
 import org.apache.drill.exec.ref.eval.EvaluatorTypes.BasicEvaluator;
 import org.apache.drill.exec.ref.values.ScalarValues.DoubleScalar;
 import org.apache.drill.exec.ref.values.ScalarValues.FloatScalar;
@@ -83,7 +84,7 @@ public abstract class NumericValue extends BaseDataValue implements ComparableVa
   @Override
   public boolean equals(DataValue v) {
     if(v == null) return false;
-    if(v.getDataType().isNumericType()){
+    if(Types.isNumericType(v.getDataType())){
       return this.compareTo(v) == 0;
     }else{
       return false;
@@ -140,7 +141,7 @@ public abstract class NumericValue extends BaseDataValue implements ComparableVa
   
   @Override
   public boolean supportsCompare(DataValue dv2) {
-    return dv2.getDataType().isNumericType();
+    return Types.isNumericType(dv2.getDataType());
   }
 
   
@@ -152,22 +153,22 @@ public abstract class NumericValue extends BaseDataValue implements ComparableVa
   }
 
   public long getAsLong(){
-    throw new DrillRuntimeException(String.format("A %s value can not be implicitly cast to a long.", this.getDataType().getName()));
+    throw new DrillRuntimeException(String.format("A %s value can not be implicitly cast to a long.", this.getDataType()));
   }
   public int getAsInt(){
-    throw new DrillRuntimeException(String.format("A %s value can not be implicitly cast to an int.", this.getDataType().getName()));
+    throw new DrillRuntimeException(String.format("A %s value can not be implicitly cast to an int.", this.getDataType()));
   }
   public float getAsFloat(){
-    throw new DrillRuntimeException(String.format("A %s value can not be implicitly cast to an float.", this.getDataType().getName()));
+    throw new DrillRuntimeException(String.format("A %s value can not be implicitly cast to an float.", this.getDataType()));
   }
   public double getAsDouble(){
-    throw new DrillRuntimeException(String.format("A %s value can not be implicitly cast to a double.", this.getDataType().getName()));
+    throw new DrillRuntimeException(String.format("A %s value can not be implicitly cast to a double.", this.getDataType()));
   }
   public BigDecimal getAsBigDecimal(){
-    throw new DrillRuntimeException(String.format("A %s value can not be implicitly cast to an big decimal.", this.getDataType().getName()));
+    throw new DrillRuntimeException(String.format("A %s value can not be implicitly cast to an big decimal.", this.getDataType()));
   }
   public BigInteger getAsBigInteger(){
-    throw new DrillRuntimeException(String.format("A %s value can not be implicitly cast to a big integer.", this.getDataType().getName()));
+    throw new DrillRuntimeException(String.format("A %s value can not be implicitly cast to a big integer.", this.getDataType()));
   }
   
 

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ScalarValues.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ScalarValues.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ScalarValues.java
index d401927..7a72b2c 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ScalarValues.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ScalarValues.java
@@ -22,10 +22,14 @@ import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.Arrays;
 
-import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.types.TypeProtos.DataMode;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.TypeProtos.MinorType;
+import org.apache.drill.common.types.Types;
 import org.apache.drill.exec.ref.eval.EvaluatorTypes.BasicEvaluator;
 import org.apache.drill.exec.ref.rops.DataWriter;
 import org.apache.hadoop.io.BytesWritable;
+import org.apache.tools.ant.types.DataType;
 
 import com.google.common.hash.HashFunction;
 import com.google.common.hash.Hashing;
@@ -38,7 +42,8 @@ public final class ScalarValues {
   
   public static class StringScalar extends BaseDataValue implements StringValue, ComparableValue, BasicEvaluator {
     private CharSequence seq;
-
+    private MajorType type = MajorType.newBuilder().setMinorType(MinorType.VARCHAR4).setMode(DataMode.OPTIONAL).build();
+    
     public StringScalar(CharSequence seq){
       this.seq = seq;
     }
@@ -60,7 +65,7 @@ public final class ScalarValues {
 
     @Override
     public boolean supportsCompare(DataValue dv2) {
-      return dv2.getDataType() == DataType.NVARCHAR;
+      return Types.isStringScalarType(dv2.getDataType());
     }
 
     @Override
@@ -69,8 +74,8 @@ public final class ScalarValues {
     }
 
     @Override
-    public DataType getDataType() {
-      return DataType.NVARCHAR;
+    public MajorType getDataType() {
+      return type;
     }
 
     @Override
@@ -99,7 +104,7 @@ public final class ScalarValues {
 
     @Override
     public boolean equals(DataValue v) {
-      if(v.getDataType() != this.getDataType()) return false;
+      if(!v.getDataType().equals(this.getDataType())) return false;
       return seq.equals(v.getAsStringValue().getString());
     }
 
@@ -118,6 +123,8 @@ public final class ScalarValues {
   
   public static class BooleanScalar extends BaseDataValue implements BooleanValue, BasicEvaluator{
     private boolean b;
+    private MajorType type = MajorType.newBuilder().setMinorType(MinorType.BOOLEAN).setMode(DataMode.OPTIONAL).build();
+    
     public BooleanScalar(boolean b){
       this.b = b;
     }
@@ -138,8 +145,8 @@ public final class ScalarValues {
     }
 
     @Override
-    public DataType getDataType() {
-      return DataType.BOOLEAN;
+    public MajorType getDataType() {
+      return type;
     }
 
     @Override
@@ -159,7 +166,7 @@ public final class ScalarValues {
     
     @Override
     public boolean equals(DataValue v) {
-      if(v.getDataType() != this.getDataType()) return false;
+      if(v.getDataType().equals(this.getDataType())) return false;
       return b == v.getAsBooleanValue().getBoolean();
     }
 
@@ -176,6 +183,8 @@ public final class ScalarValues {
   }
   
   public static class LongScalar extends NumericValue{
+    
+    private MajorType type = MajorType.newBuilder().setMinorType(MinorType.BIGINT).setMode(DataMode.OPTIONAL).build();
     long l;
     public LongScalar(long l) {
       this.l = l;
@@ -212,8 +221,8 @@ public final class ScalarValues {
     }
 
     @Override
-    public DataType getDataType() {
-      return DataType.INT64;
+    public MajorType getDataType() {
+      return type;
     }
 
     @Override
@@ -244,6 +253,7 @@ public final class ScalarValues {
   }
   
   public static class IntegerScalar extends NumericValue{
+    private MajorType type = MajorType.newBuilder().setMinorType(MinorType.INT).setMode(DataMode.OPTIONAL).build();
     int i;
     
     public IntegerScalar(int i){
@@ -266,8 +276,8 @@ public final class ScalarValues {
     }
 
     @Override
-    public DataType getDataType() {
-      return DataType.INT32;
+    public MajorType getDataType() {
+      return type;
     }
 
     @Override
@@ -320,6 +330,8 @@ public final class ScalarValues {
 
   
   public static class FloatScalar extends NumericValue{
+    
+    private MajorType type = MajorType.newBuilder().setMinorType(MinorType.FLOAT4).setMode(DataMode.OPTIONAL).build();
     float f;
     public FloatScalar(float f){
       this.f = f;
@@ -336,8 +348,8 @@ public final class ScalarValues {
     }
 
     @Override
-    public DataType getDataType() {
-      return DataType.FLOAT32;
+    public MajorType getDataType() {
+      return type;
     }
 
     @Override
@@ -373,14 +385,16 @@ public final class ScalarValues {
  
   
   public static class DoubleScalar extends NumericValue{
+    private MajorType type = MajorType.newBuilder().setMinorType(MinorType.FLOAT8).setMode(DataMode.OPTIONAL).build();
     private double d;
+    
     public DoubleScalar(double d){
       this.d = d;
     }
 
     @Override
-    public DataType getDataType() {
-      return DataType.FLOAT64;
+    public MajorType getDataType() {
+      return type;
     }
 
     @Override
@@ -427,6 +441,7 @@ public final class ScalarValues {
   }
   
   public static class BytesScalar extends BaseDataValue implements BytesValue{
+    private MajorType type = MajorType.newBuilder().setMinorType(MinorType.VARBINARY4).setMode(DataMode.OPTIONAL).build();
     private BytesWritable.Comparator comparator = new BytesWritable.Comparator();
     private final static HashFunction HASH = Hashing.murmur3_32();
 
@@ -442,7 +457,7 @@ public final class ScalarValues {
 
     @Override
     public boolean supportsCompare(DataValue dv2) {
-      return dv2.getDataType() == DataType.BYTES;
+      return Types.isBytesScalarType(dv2.getDataType());
     }
 
 
@@ -454,8 +469,8 @@ public final class ScalarValues {
     }
 
     @Override
-    public DataType getDataType() {
-      return DataType.BYTES;
+    public MajorType getDataType() {
+      return type;
     }
 
     @Override
@@ -480,7 +495,7 @@ public final class ScalarValues {
 
     @Override
     public boolean equals(DataValue v) {
-      if(v.getDataType() != this.getDataType()) return false;
+      if(!v.getDataType().equals(this.getDataType())) return false;
       BytesValue other = v.getAsBytesValue();
       if(this.getLength() != other.getLength()) return false;
       for(int i =0; i < this.getLength(); i++){
@@ -505,15 +520,18 @@ public final class ScalarValues {
   
   
   static class NullValue extends BaseDataValue{
-
+    
+    // not sure what to do here... 
+    MajorType type = MajorType.newBuilder().setMode(DataMode.OPTIONAL).setMinorType(MinorType.LATE).build();
+    
     @Override
     public void write(DataWriter writer) throws IOException {
       writer.writeNullValue();
     }
 
     @Override
-    public DataType getDataType() {
-      return DataType.NULL;
+    public MajorType getDataType() {
+      return type;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/SimpleArrayValue.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/SimpleArrayValue.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/SimpleArrayValue.java
index a8c11de..b87a4db 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/SimpleArrayValue.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/SimpleArrayValue.java
@@ -21,7 +21,7 @@ import java.io.IOException;
 import java.util.Arrays;
 import java.util.Objects;
 
-import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.types.TypeProtos.MinorType;
 import org.apache.drill.exec.ref.rops.DataWriter;
 
 
@@ -119,7 +119,7 @@ public class SimpleArrayValue extends BaseArrayValue{
 
   @Override
   public boolean equals(DataValue v) {
-    if(v.getDataType() != DataType.MAP) return false;
+    if(v.getDataType().getMinorType() == MinorType.REPEATMAP) return false;
     BaseArrayValue other = v.getAsContainer().getAsArray();
     if(this.size() != other.size()) return false;
     for(int i =0; i < this.size(); i++){

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/SimpleMapValue.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/SimpleMapValue.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/SimpleMapValue.java
index 1c170f2..ab231ff 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/SimpleMapValue.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/SimpleMapValue.java
@@ -24,9 +24,10 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
 
-import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.types.TypeProtos.DataMode;
 import org.apache.drill.exec.ref.exceptions.RecordException;
 import org.apache.drill.exec.ref.rops.DataWriter;
+import org.apache.tools.ant.types.DataType;
 
 public class SimpleMapValue extends BaseMapValue{
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SimpleMapValue.class);
@@ -86,7 +87,7 @@ public class SimpleMapValue extends BaseMapValue{
   @Override
   public boolean equals(DataValue v) {
     if(v == null) return false;
-    if(v.getDataType() != DataType.MAP) return false;
+    if(v.getDataType().getMode() != DataMode.REPEATED) return false;
     BaseMapValue other = v.getAsContainer().getAsMap();
     for(Entry<CharSequence, DataValue> e : this){
       DataValue v2 = other.getByName(e.getKey());

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ValueReader.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ValueReader.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ValueReader.java
index 9adcca0..3a6be51 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ValueReader.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ValueReader.java
@@ -18,35 +18,37 @@
 package org.apache.drill.exec.ref.values;
 
 import org.apache.drill.common.exceptions.DrillRuntimeException;
-import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.types.TypeProtos.DataMode;
+import org.apache.drill.common.types.TypeProtos.MinorType;
+import org.apache.drill.common.types.Types;
 
 public class ValueReader {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ValueReader.class);
   
   public static boolean getBoolean(DataValue v){
-    if(v.getDataType() == DataType.BOOLEAN){
+    if(v.getDataType().getMinorType() == MinorType.BOOLEAN && v.getDataType().getMode() != DataMode.REPEATED){
       return v.getAsBooleanValue().getBoolean();
     }else{
-      throw new DrillRuntimeException(String.format("Unable to get boolean.  Type os a %s", v.getClass().getCanonicalName()));
+      throw new DrillRuntimeException(String.format("Unable to get boolean.  Type was a %s", v.getClass().getCanonicalName()));
     }
   }
   
   public static long getLong(DataValue v){
-    if(v.getDataType().isNumericType()){
+    if(Types.isNumericType(v.getDataType())){
       return v.getAsNumeric().getAsLong();
     }else{
       throw new DrillRuntimeException(String.format("Unable to get value.  %s is not a numeric type.", v.getClass().getCanonicalName()));
     }
   }
   public static double getDouble(DataValue v){
-    if(v.getDataType().isNumericType()){
+    if(Types.isNumericType(v.getDataType())){
       return v.getAsNumeric().getAsDouble();
     }else{
       throw new DrillRuntimeException(String.format("Unable to get value.  %s is not a numeric type.", v.getClass().getCanonicalName()));
     }
   }
   public static CharSequence getChars(DataValue v){
-    if(v.getDataType() == DataType.NVARCHAR){
+    if(Types.isStringScalarType(v.getDataType())){
       return v.getAsStringValue().getString();
     }else{
       throw new DrillRuntimeException(String.format("Unable to get value.  %s is not a StringValue type.", v.getClass().getCanonicalName()));

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ValueUtils.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ValueUtils.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ValueUtils.java
index ac51d3b..dff8b11 100644
--- a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ValueUtils.java
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/values/ValueUtils.java
@@ -19,8 +19,11 @@ package org.apache.drill.exec.ref.values;
 
 import org.apache.drill.common.expression.PathSegment;
 import org.apache.drill.common.expression.ValueExpressions.CollisionBehavior;
-import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.types.TypeProtos.DataMode;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.TypeProtos.MinorType;
 import org.apache.drill.exec.ref.exceptions.RecordException;
+import org.apache.tools.ant.types.DataType;
 
 public class ValueUtils {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ValueUtils.class);
@@ -47,17 +50,17 @@ public class ValueUtils {
       a.addToArray(1, newValue);
       return a;
     case MERGE_OVERRIDE:
-      DataType oldT = oldValue.getDataType();
-      DataType newT = oldValue.getDataType();
-      if(oldT == DataType.MAP && newT == DataType.MAP){
+      MajorType oldT = oldValue.getDataType();
+      MajorType newT = newValue.getDataType();
+      if(oldT.getMinorType() == MinorType.REPEATMAP && newT.getMinorType() == MinorType.REPEATMAP){
         oldValue.getAsContainer().getAsMap().merge(newValue.getAsContainer().getAsMap());
         return oldValue;
-      }else if(oldT == DataType.ARRAY && newT == DataType.ARRAY){
+      }else if(oldT.getMode() == DataMode.REPEATED && newT.getMode() == DataMode.REPEATED){
         logger.debug("Merging two arrays. {} and {}", oldValue, newValue);
         oldValue.getAsContainer().getAsArray().append(newValue.getAsContainer().getAsArray());
         return oldValue;
-      }else if(oldT == DataType.ARRAY || newT == DataType.ARRAY || oldT == DataType.MAP || newT == DataType.MAP){
-        throw new RecordException(String.format("Failure while doing query.  You requested a merge of values that were incompatibile.  Examples include merging an array and a map or merging a map/array with a scalar.  Merge Types were %s and %s.", oldT.getName(), newT.getName()), null);
+      }else if(oldT.getMode() == DataMode.REPEATED || newT.getMode() == DataMode.REPEATED || oldT.getMinorType() == MinorType.REPEATMAP || newT.getMinorType() == MinorType.REPEATMAP){
+        throw new RecordException(String.format("Failure while doing query.  You requested a merge of values that were incompatibile.  Examples include merging an array and a map or merging a map/array with a scalar.  Merge Types were %s and %s.", oldT, newT), null);
       }else{
         // scalar type, just override the value.
         return newValue;

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/RunSimplePlan.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/RunSimplePlan.java b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/RunSimplePlan.java
index 110e655..5b1841b 100644
--- a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/RunSimplePlan.java
+++ b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/RunSimplePlan.java
@@ -24,6 +24,7 @@ import java.util.Collection;
 import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.common.logical.LogicalPlan;
 import org.apache.drill.common.util.FileUtils;
+import org.apache.drill.exec.ref.RunOutcome.OutcomeType;
 import org.apache.drill.exec.ref.eval.BasicEvaluatorFactory;
 import org.apache.drill.exec.ref.rse.RSERegistry;
 import org.junit.Test;
@@ -36,7 +37,7 @@ public class RunSimplePlan{
   
   
   @Test
-  public void parseSimplePlan() throws Exception{
+  public void parseSimplePlan() throws Throwable{
     DrillConfig config = DrillConfig.create();
     LogicalPlan plan = LogicalPlan.parse(config, Files.toString(FileUtils.getResourceAsFile("/simple_plan.json"), Charsets.UTF_8));
     IteratorRegistry ir = new IteratorRegistry();
@@ -48,7 +49,7 @@ public class RunSimplePlan{
   }
   
   @Test
-  public void joinPlan() throws Exception{
+  public void joinPlan() throws Throwable{
     DrillConfig config = DrillConfig.create();
     LogicalPlan plan = LogicalPlan.parse(config, Files.toString(FileUtils.getResourceAsFile("/simple_join.json"), Charsets.UTF_8));
     IteratorRegistry ir = new IteratorRegistry();
@@ -56,11 +57,12 @@ public class RunSimplePlan{
     i.setup();
     Collection<RunOutcome> outcomes = i.run();
     assertEquals(outcomes.size(), 1);
-    assertEquals(outcomes.iterator().next().outcome, RunOutcome.OutcomeType.SUCCESS);
+    RunOutcome out = outcomes.iterator().next();
+    if(out.outcome != OutcomeType.FAILED && out.exception != null) logger.error("Failure while running {}", out.exception);
   }
   
   @Test
-  public void flattenPlan() throws Exception{
+  public void flattenPlan() throws Throwable{
     DrillConfig config = DrillConfig.create();
     LogicalPlan plan = LogicalPlan.parse(config, Files.toString(FileUtils.getResourceAsFile("/simple_plan_flattened.json"), Charsets.UTF_8));
     IteratorRegistry ir = new IteratorRegistry();
@@ -68,6 +70,8 @@ public class RunSimplePlan{
     i.setup();
     Collection<RunOutcome> outcomes = i.run();
     assertEquals(outcomes.size(), 1);
-    assertEquals(outcomes.iterator().next().outcome, RunOutcome.OutcomeType.SUCCESS);
+    RunOutcome out = outcomes.iterator().next();
+    if(out.outcome != OutcomeType.FAILED && out.exception != null) logger.error("Failure while running {}", out.exception);
+    assertEquals(out.outcome, RunOutcome.OutcomeType.SUCCESS);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/TestUtils.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/TestUtils.java b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/TestUtils.java
index d7cc690..c340e7e 100644
--- a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/TestUtils.java
+++ b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/TestUtils.java
@@ -12,6 +12,7 @@ import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 
 import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.expression.ExpressionPosition;
 import org.apache.drill.common.expression.SchemaPath;
 import org.apache.drill.common.logical.LogicalPlan;
 import org.apache.drill.common.util.FileUtils;
@@ -27,7 +28,7 @@ import com.google.common.io.Files;
 public class TestUtils {
   public static RecordIterator jsonToRecordIterator(String schemaPath, String j) throws IOException {
     InputStream is = new ByteArrayInputStream(j.getBytes());
-    JSONRecordReader reader = new JSONRecordReader(new SchemaPath(schemaPath), DrillConfig.create(), is, null);
+    JSONRecordReader reader = new JSONRecordReader(new SchemaPath(schemaPath, ExpressionPosition.UNKNOWN), DrillConfig.create(), is, null);
     return reader.getIterator();
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/CollapsingAggregateTest.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/CollapsingAggregateTest.java b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/CollapsingAggregateTest.java
index edc92a4..34a500c 100644
--- a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/CollapsingAggregateTest.java
+++ b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/CollapsingAggregateTest.java
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
 
 import java.util.List;
 
+import org.apache.drill.common.expression.ExpressionPosition;
 import org.apache.drill.common.expression.SchemaPath;
 import org.apache.drill.exec.ref.TestUtils;
 import org.apache.drill.exec.ref.UnbackedRecord;
@@ -38,8 +39,8 @@ public class CollapsingAggregateTest {
 
     DataValue[] depts = {DataValue.NULL_VALUE, new LongScalar(31), new LongScalar(33), new LongScalar(34)};
     DataValue[] cnts = {new LongScalar(1), new LongScalar(1), new LongScalar(2), new LongScalar(2)};
-    SchemaPath typeCount = new SchemaPath("typeCount");
-    SchemaPath dept = new SchemaPath("deptId");
+    SchemaPath typeCount = new SchemaPath("typeCount", ExpressionPosition.UNKNOWN);
+    SchemaPath dept = new SchemaPath("deptId", ExpressionPosition.UNKNOWN);
     for(int i =0; i < depts.length; i++){
       UnbackedRecord r = records.get(i);
       assertEquals(String.format("Invalid dept value for record %d.", i), depts[i], r.getField(dept));

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/ConstantROPTest.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/ConstantROPTest.java b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/ConstantROPTest.java
index 499b335..9aea930 100644
--- a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/ConstantROPTest.java
+++ b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/ConstantROPTest.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.common.base.Charsets;
 import com.google.common.io.Files;
 import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.expression.ExpressionPosition;
 import org.apache.drill.common.expression.SchemaPath;
 import org.apache.drill.common.logical.LogicalPlan;
 import org.apache.drill.common.logical.data.Constant;
@@ -50,9 +51,9 @@ public class ConstantROPTest {
             while (iter.next() != RecordIterator.NextOutcome.NONE_LEFT){
                 System.out.println(ptr);
                 org.junit.Assert.assertEquals("Integer value in record " + i + " is incorrect.",
-                        ptr.getField(new SchemaPath("c1")), new ScalarValues.IntegerScalar(i));
+                        ptr.getField(new SchemaPath("c1", ExpressionPosition.UNKNOWN)), new ScalarValues.IntegerScalar(i));
                 org.junit.Assert.assertEquals("String value in record " + i + " is incorrect.",
-                        ptr.getField(new SchemaPath("c2")), new ScalarValues.StringScalar("string " + i));
+                        ptr.getField(new SchemaPath("c2", ExpressionPosition.UNKNOWN)), new ScalarValues.StringScalar("string " + i));
                 i++;
             }
             org.junit.Assert.assertEquals("Incorrect number of records returned by 'constant' record iterator.", 3, i - 1);

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/OrderROPTest.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/OrderROPTest.java b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/OrderROPTest.java
index 23d0fe6..8a49040 100644
--- a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/OrderROPTest.java
+++ b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/OrderROPTest.java
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
 
 import java.util.List;
 
+import org.apache.drill.common.expression.ExpressionPosition;
 import org.apache.drill.common.expression.SchemaPath;
 import org.apache.drill.exec.ref.TestUtils;
 import org.apache.drill.exec.ref.UnbackedRecord;
@@ -37,7 +38,7 @@ public class OrderROPTest {
     List<UnbackedRecord> records = TestUtils.getResultAsUnbackedRecords("/order/nulls-first.json");
 
     DataValue[] depts = {DataValue.NULL_VALUE, new LongScalar(31), new LongScalar(33), new LongScalar(34)};
-    SchemaPath dept = new SchemaPath("deptId");
+    SchemaPath dept = new SchemaPath("deptId", ExpressionPosition.UNKNOWN);
     for(int i =0; i < depts.length; i++){
       UnbackedRecord r = records.get(i);
       assertEquals(String.format("Invalid dept value for record %d.", i), depts[i], r.getField(dept));
@@ -50,7 +51,7 @@ public class OrderROPTest {
     List<UnbackedRecord> records = TestUtils.getResultAsUnbackedRecords("/order/nulls-last.json");
 
     DataValue[] depts = {new LongScalar(31), new LongScalar(33), new LongScalar(34), DataValue.NULL_VALUE};
-    SchemaPath dept = new SchemaPath("deptId");
+    SchemaPath dept = new SchemaPath("deptId", ExpressionPosition.UNKNOWN);
     for(int i =0; i < depts.length; i++){
       UnbackedRecord r = records.get(i);
       assertEquals(String.format("Invalid dept value for record %d.", i), depts[i], r.getField(dept));

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/ce0da88d/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/WindowFrameROPTest.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/WindowFrameROPTest.java b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/WindowFrameROPTest.java
index b0aeb99..38f97b1 100644
--- a/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/WindowFrameROPTest.java
+++ b/sandbox/prototype/exec/ref/src/test/java/org/apache/drill/exec/ref/rops/WindowFrameROPTest.java
@@ -1,6 +1,8 @@
 package org.apache.drill.exec.ref.rops;
 
 import com.google.common.collect.Lists;
+
+import org.apache.drill.common.expression.ExpressionPosition;
 import org.apache.drill.common.expression.FieldReference;
 import org.apache.drill.common.expression.SchemaPath;
 import org.apache.drill.common.logical.data.WindowFrame;
@@ -112,7 +114,7 @@ public class WindowFrameROPTest {
                 "{id: 2, v: 2}" +
                 "{id: 3, v: 3}" +
                 "{id: 4, v: 4}";
-        WindowFrameROP rop = new WindowFrameROP(new WindowFrame(new FieldReference("test.v"), null, -2L, 2L));
+        WindowFrameROP rop = new WindowFrameROP(new WindowFrame(new FieldReference("test.v", ExpressionPosition.UNKNOWN), null, -2L, 2L));
         RecordIterator incoming = TestUtils.jsonToRecordIterator("test", withinInput);
         rop.setInput(incoming);
         RecordIterator out = rop.getOutput();
@@ -136,7 +138,7 @@ public class WindowFrameROPTest {
                 "{id: 2, v: 1}" +
                 "{id: 3, v: 1}" +
                 "{id: 4, v: 2}";
-        WindowFrameROP rop = new WindowFrameROP(new WindowFrame(new FieldReference("test.v"), null, -1L, 2L));
+        WindowFrameROP rop = new WindowFrameROP(new WindowFrame(new FieldReference("test.v", ExpressionPosition.UNKNOWN), null, -1L, 2L));
         RecordIterator incoming = TestUtils.jsonToRecordIterator("test", withinInput);
         rop.setInput(incoming);
         RecordIterator out = rop.getOutput();
@@ -166,7 +168,7 @@ public class WindowFrameROPTest {
                 "{id: 4, v: 1}" +
                 "{id: 5, v: 1}" +
                 "{id: 6, v: 2}";
-        WindowFrameROP rop = new WindowFrameROP(new WindowFrame(new FieldReference("test.v"), null, -1L, 3L));
+        WindowFrameROP rop = new WindowFrameROP(new WindowFrame(new FieldReference("test.v", ExpressionPosition.UNKNOWN), null, -1L, 3L));
         RecordIterator incoming = TestUtils.jsonToRecordIterator("test", withinInput);
         rop.setInput(incoming);
         RecordIterator out = rop.getOutput();
@@ -196,14 +198,14 @@ public class WindowFrameROPTest {
     }
 
     private void verifyWindowOrder(List<WindowObj> expectedIds, RecordIterator out) {
-        verifyWindowOrder(expectedIds, out, new SchemaPath("ref.segment"), new SchemaPath("ref.position"));
+        verifyWindowOrder(expectedIds, out, new SchemaPath("ref.segment", ExpressionPosition.UNKNOWN), new SchemaPath("ref.position", ExpressionPosition.UNKNOWN));
     }
 
     private void verifyWindowOrder(List<WindowObj> expectedIds, RecordIterator out, SchemaPath segment, SchemaPath position) {
         RecordIterator.NextOutcome outcome = out.next();
         RecordPointer pointer = out.getRecordPointer();
         int count = 0;
-        SchemaPath id = new SchemaPath("test.id");
+        SchemaPath id = new SchemaPath("test.id", ExpressionPosition.UNKNOWN);
         int expectedSize = expectedIds.size();
         while (outcome != RecordIterator.NextOutcome.NONE_LEFT) {
             count += 1;