drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jacq...@apache.org
Subject [06/38] DRILL-257: Move SQL parsing to server side. Switch to Avatica based JDBC driver. Update QuerySubmitter to support SQL queries. Update SqlAccesors to support getObject() Remove ref, clean up SQL packages some. Various performance fixes. Updating
Date Tue, 04 Mar 2014 08:07:33 GMT
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillAggregateRel.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillAggregateRel.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillAggregateRel.java
deleted file mode 100644
index 668ed33..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillAggregateRel.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import java.util.BitSet;
-import java.util.List;
-
-import net.hydromatic.linq4j.Ord;
-
-import org.eigenbase.rel.AggregateCall;
-import org.eigenbase.rel.AggregateRelBase;
-import org.eigenbase.rel.InvalidRelException;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.RelOptCluster;
-import org.eigenbase.relopt.RelTraitSet;
-import org.eigenbase.util.Util;
-
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * Aggregation implemented in Drill.
- */
-public class DrillAggregateRel extends AggregateRelBase implements DrillRel {
-  /** Creates a DrillAggregateRel. */
-  public DrillAggregateRel(RelOptCluster cluster, RelTraitSet traits, RelNode child, BitSet groupSet,
-      List<AggregateCall> aggCalls) throws InvalidRelException {
-    super(cluster, traits, child, groupSet, aggCalls);
-    for (AggregateCall aggCall : aggCalls) {
-      if (aggCall.isDistinct()) {
-        throw new InvalidRelException("DrillAggregateRel does not support DISTINCT aggregates");
-      }
-    }
-  }
-
-  @Override
-  public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
-    try {
-      return new DrillAggregateRel(getCluster(), traitSet, sole(inputs), getGroupSet(), aggCalls);
-    } catch (InvalidRelException e) {
-      throw new AssertionError(e);
-    }
-  }
-
-  @Override
-  public int implement(DrillImplementor implementor) {
-    int inputId = implementor.visitChild(this, 0, getChild());
-    final List<String> childFields = getChild().getRowType().getFieldNames();
-    final List<String> fields = getRowType().getFieldNames();
-    /*
-     * E.g. { op: "segment", ref: "segment", exprs: ["deptId"] }, { op: "collapsingaggregate", within: "segment",
-     * carryovers: ["deptId"], aggregations: [ {ref: "c", expr: "count(1)"} ] }
-     */
-    final ObjectNode segment = implementor.mapper.createObjectNode();
-    segment.put("op", "segment");
-    segment.put("input", inputId);
-    // TODO: choose different name for field if there is already a field
-    // called "segment"
-    segment.put("ref", "segment");
-    final ArrayNode exprs = implementor.mapper.createArrayNode();
-    segment.put("exprs", exprs);
-    for (int group : Util.toIter(groupSet)) {
-      exprs.add(childFields.get(group));
-    }
-
-    final int segmentId = implementor.add(segment);
-
-    final ObjectNode aggregate = implementor.mapper.createObjectNode();
-    aggregate.put("op", "collapsingaggregate");
-    aggregate.put("input", segmentId);
-    aggregate.put("within", "segment");
-    final ArrayNode carryovers = implementor.mapper.createArrayNode();
-    aggregate.put("carryovers", carryovers);
-    for (int group : Util.toIter(groupSet)) {
-      carryovers.add(childFields.get(group));
-    }
-    final ArrayNode aggregations = implementor.mapper.createArrayNode();
-    aggregate.put("aggregations", aggregations);
-    for (Ord<AggregateCall> aggCall : Ord.zip(aggCalls)) {
-      final ObjectNode aggregation = implementor.mapper.createObjectNode();
-      aggregation.put("ref", fields.get(groupSet.cardinality() + aggCall.i));
-      aggregation.put("expr", toDrill(aggCall.e, childFields));
-      aggregations.add(aggregation);
-    }
-
-    return implementor.add(aggregate);
-  }
-
-  private String toDrill(AggregateCall call, List<String> fn) {
-    final StringBuilder buf = new StringBuilder();
-    buf.append(call.getAggregation().getName().toLowerCase()).append("(");
-    for (Ord<Integer> arg : Ord.zip(call.getArgList())) {
-      if (arg.i > 0) {
-        buf.append(", ");
-      }
-      buf.append(fn.get(arg.e));
-    }
-    if (call.getArgList().isEmpty()) {
-      buf.append("1"); // dummy arg to implement COUNT(*)
-    }
-    buf.append(")");
-    return buf.toString();
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillAggregateRule.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillAggregateRule.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillAggregateRule.java
deleted file mode 100644
index 003ff61..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillAggregateRule.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import org.eigenbase.rel.AggregateRel;
-import org.eigenbase.rel.InvalidRelException;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.*;
-import org.eigenbase.trace.EigenbaseTrace;
-
-import java.util.logging.Logger;
-
-/**
- * Rule that converts an {@link AggregateRel} to a {@link DrillAggregateRel}, implemented by a Drill "segment" operation
- * followed by a "collapseaggregate" operation.
- */
-public class DrillAggregateRule extends RelOptRule {
-  public static final RelOptRule INSTANCE = new DrillAggregateRule();
-  protected static final Logger tracer = EigenbaseTrace.getPlannerTracer();
-
-  private DrillAggregateRule() {
-    super(RelOptRule.some(AggregateRel.class, Convention.NONE, RelOptRule.any(RelNode.class)), "DrillAggregateRule");
-  }
-
-  @Override
-  public void onMatch(RelOptRuleCall call) {
-    final AggregateRel aggregate = (AggregateRel) call.rel(0);
-    final RelNode input = call.rel(1);
-    final RelTraitSet traits = aggregate.getTraitSet().plus(DrillRel.CONVENTION);
-    final RelNode convertedInput = convert(input, traits);
-    try {
-      call.transformTo(new DrillAggregateRel(aggregate.getCluster(), traits, convertedInput, aggregate.getGroupSet(),
-          aggregate.getAggCallList()));
-    } catch (InvalidRelException e) {
-      tracer.warning(e.toString());
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillFilterRel.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillFilterRel.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillFilterRel.java
deleted file mode 100644
index e01d645..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillFilterRel.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-import org.eigenbase.rel.FilterRelBase;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.*;
-import org.eigenbase.rex.RexNode;
-
-import java.util.List;
-
-/**
- * Filter implemented in Drill.
- */
-public class DrillFilterRel extends FilterRelBase implements DrillRel {
-  protected DrillFilterRel(RelOptCluster cluster, RelTraitSet traits, RelNode child, RexNode condition) {
-    super(cluster, traits, child, condition);
-    assert getConvention() == CONVENTION;
-  }
-
-  @Override
-  public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
-    return new DrillFilterRel(getCluster(), traitSet, sole(inputs), getCondition());
-  }
-
-  @Override
-  public RelOptCost computeSelfCost(RelOptPlanner planner) {
-    return super.computeSelfCost(planner).multiplyBy(0.1);
-  }
-
-  @Override
-  public int implement(DrillImplementor implementor) {
-    final int inputId = implementor.visitChild(this, 0, getChild());
-    final ObjectNode filter = implementor.mapper.createObjectNode();
-    /*
-     * E.g. { op: "filter", expr: "donuts.ppu < 1.00" }
-     */
-    filter.put("op", "filter");
-    filter.put("input", inputId);
-    filter.put("expr", DrillOptiq.toDrill(getChild(), getCondition()));
-    return implementor.add(filter);
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillFilterRule.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillFilterRule.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillFilterRule.java
deleted file mode 100644
index eff0715..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillFilterRule.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import org.eigenbase.rel.FilterRel;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.*;
-
-/**
- * Rule that converts a {@link org.eigenbase.rel.FilterRel} to a Drill "filter" operation.
- */
-public class DrillFilterRule extends RelOptRule {
-  public static final RelOptRule INSTANCE = new DrillFilterRule();
-
-  private DrillFilterRule() {
-    super(RelOptRule.some(FilterRel.class, Convention.NONE, RelOptRule.any(RelNode.class)), "DrillFilterRule");
-  }
-
-  @Override
-  public void onMatch(RelOptRuleCall call) {
-    final FilterRel filter = (FilterRel) call.getRels()[0];
-    final RelNode input = call.getRels()[1];
-    final RelTraitSet traits = filter.getTraitSet().plus(DrillRel.CONVENTION);
-    final RelNode convertedInput = convert(input, traits);
-    call.transformTo(new DrillFilterRel(filter.getCluster(), traits, convertedInput, filter.getCondition()));
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillImplementor.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillImplementor.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillImplementor.java
deleted file mode 100644
index 715e64f..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillImplementor.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import java.io.IOException;
-import java.util.Set;
-
-import org.apache.drill.common.logical.data.LogicalOperator;
-import org.apache.drill.exec.ref.rse.QueueRSE.QueueOutputInfo;
-import org.apache.drill.jdbc.DrillTable;
-import org.eigenbase.rel.RelNode;
-
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.collect.Sets;
-
-/**
- * Context for converting a tree of {@link DrillRel} nodes into a Drill logical plan.
- */
-public class DrillImplementor {
-  
-  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillImplementor.class);
-  
-  final ObjectMapper mapper = new ObjectMapper();
-  {
-    mapper.enable(SerializationFeature.INDENT_OUTPUT);
-    mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
-    mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
-  }
-  private final ObjectNode rootNode = mapper.createObjectNode();
-  private final ArrayNode operatorsNode;
-  private final ObjectNode sourcesNode;
-  private Set<DrillTable> tables = Sets.newHashSet();
-  private final boolean isRef;
-  
-  public DrillImplementor(boolean isRef) {
-    this.isRef = isRef;
-    final ObjectNode headNode = mapper.createObjectNode();
-    rootNode.put("head", headNode);
-    headNode.put("type", "APACHE_DRILL_LOGICAL");
-    headNode.put("version", "1");
-
-    final ObjectNode generatorNode = mapper.createObjectNode();
-    headNode.put("generator", generatorNode);
-    generatorNode.put("type", "optiq");
-    generatorNode.put("info", "na");
-
-    // TODO: populate sources based on the sources of scans that occur in
-    // the query
-    sourcesNode = mapper.createObjectNode();
-    rootNode.put("storage", sourcesNode);
-
-    if(isRef){
-      {
-        final ObjectNode sourceNode = mapper.createObjectNode();
-        sourceNode.put("type", "classpath");
-        sourcesNode.put("donuts-json", sourceNode);
-      }
-      {
-        final ObjectNode sourceNode = mapper.createObjectNode();
-        sourceNode.put("type", "queue");
-        sourcesNode.put("queue", sourceNode);
-      }
-    }
-
-
-    final ArrayNode queryNode = mapper.createArrayNode();
-    rootNode.put("query", queryNode);
-
-    this.operatorsNode = queryNode;
-  }
-  
-  public void registerSource(DrillTable table){
-    if(!table.isRefEngine() && tables.add(table)){
-      sourcesNode.put(table.getStorageEngineName(), mapper.convertValue(table.getStorageEngineConfig(), JsonNode.class));  
-    }
-  }
-
-  public int go(DrillRel root) {
-    int inputId = root.implement(this);
-
-    // Add a last node, to write to the output queue.
-    final ObjectNode writeOp = mapper.createObjectNode();
-    writeOp.put("op", "store");
-    writeOp.put("input", inputId);
-    writeOp.put("storageengine", "queue");
-    writeOp.put("memo", "output sink");
-    QueueOutputInfo output = new QueueOutputInfo();
-    output.number = 0;
-    writeOp.put("target", mapper.convertValue(output, JsonNode.class));
-    return add(writeOp);
-  }
-
-  public int add(LogicalOperator operator, Integer inputId) {
-    return add(operator.nodeBuilder().convert(mapper, operator, inputId));
-  }
-
-  public int add(ObjectNode operator) {
-    operatorsNode.add(operator);
-    final int id = operatorsNode.size();
-    operator.put("@id", id);
-    return id;
-  }
-
-  /** Returns the generated plan. */
-  public String getJsonString() {
-    String s = rootNode.toString();
-    
-    if(logger.isDebugEnabled()){
-      JsonNode node;
-      try {
-        ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
-        node = mapper.readValue(s, JsonNode.class);
-        logger.debug("Optiq Generated Logical Plan: {}", mapper.writeValueAsString(node));
-      } catch (IOException e) {
-        logger.error("Failure while trying to parse logical plan string of {}", s, e);
-      }
-      
-    }
-    return s;
-  }
-
-  public int visitChild(DrillRel parent, int ordinal, RelNode child) {
-    ((DrillRel) child).implement(this);
-    return operatorsNode.size();
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillJoinRel.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillJoinRel.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillJoinRel.java
deleted file mode 100644
index acdc5c7..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillJoinRel.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-
-import org.eigenbase.rel.InvalidRelException;
-import org.eigenbase.rel.JoinRelBase;
-import org.eigenbase.rel.JoinRelType;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.RelOptCluster;
-import org.eigenbase.relopt.RelOptUtil;
-import org.eigenbase.relopt.RelTraitSet;
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.rex.RexNode;
-import org.eigenbase.util.Pair;
-
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * Join implemented in Drill.
- */
-public class DrillJoinRel extends JoinRelBase implements DrillRel {
-  private final List<Integer> leftKeys = new ArrayList<>();
-  private final List<Integer> rightKeys = new ArrayList<>();
-
-  /** Creates a DrillJoinRel. */
-  public DrillJoinRel(RelOptCluster cluster, RelTraitSet traits, RelNode left, RelNode right, RexNode condition,
-      JoinRelType joinType) throws InvalidRelException {
-    super(cluster, traits, left, right, condition, joinType, Collections.<String> emptySet());
-
-    RexNode remaining = RelOptUtil.splitJoinCondition(left, right, condition, leftKeys, rightKeys);
-    if (!remaining.isAlwaysTrue()) {
-      throw new InvalidRelException("DrillJoinRel only supports equi-join");
-    }
-  }
-
-  @Override
-  public DrillJoinRel copy(RelTraitSet traitSet, RexNode condition, RelNode left, RelNode right) {
-    try {
-      return new DrillJoinRel(getCluster(), traitSet, left, right, condition, joinType);
-    } catch (InvalidRelException e) {
-      throw new AssertionError(e);
-    }
-  }
-
-  @Override
-  public int implement(DrillImplementor implementor) {
-    final List<String> fields = getRowType().getFieldNames();
-    assert isUnique(fields);
-    final int leftCount = left.getRowType().getFieldCount();
-    final List<String> leftFields = fields.subList(0, leftCount);
-    final List<String> rightFields = fields.subList(leftCount, fields.size());
-
-    final int leftId = implementInput(implementor, 0, 0, left);
-    final int rightId = implementInput(implementor, 1, leftCount, right);
-
-    /*
-     * E.g. { op: "join", left: 2, right: 4, conditions: [ {relationship: "==", left: "deptId", right: "deptId"} ] }
-     */
-    final ObjectNode join = implementor.mapper.createObjectNode();
-    join.put("op", "join");
-    join.put("left", leftId);
-    join.put("right", rightId);
-    join.put("type", toDrill(joinType));
-    final ArrayNode conditions = implementor.mapper.createArrayNode();
-    join.put("conditions", conditions);
-    for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
-      final ObjectNode condition = implementor.mapper.createObjectNode();
-      condition.put("relationship", "==");
-      condition.put("left", leftFields.get(pair.left));
-      condition.put("right", rightFields.get(pair.right));
-      conditions.add(condition);
-    }
-    return implementor.add(join);
-  }
-
-  private int implementInput(DrillImplementor implementor, int i, int offset, RelNode input) {
-    final int inputId = implementor.visitChild(this, i, input);
-    assert uniqueFieldNames(input.getRowType());
-    final List<String> fields = getRowType().getFieldNames();
-    final List<String> inputFields = input.getRowType().getFieldNames();
-    final List<String> outputFields = fields.subList(offset, offset + inputFields.size());
-    if (!outputFields.equals(inputFields)) {
-      // Ensure that input field names are the same as output field names.
-      // If there are duplicate field names on left and right, fields will get
-      // lost.
-      return rename(implementor, inputId, inputFields, outputFields);
-    } else {
-      return inputId;
-    }
-  }
-
-  private int rename(DrillImplementor implementor, int inputId, List<String> inputFields, List<String> outputFields) {
-    final ObjectNode project = implementor.mapper.createObjectNode();
-    project.put("op", "project");
-    project.put("input", inputId);
-    final ArrayNode transforms = implementor.mapper.createArrayNode();
-    project.put("projections", transforms);
-    for (Pair<String, String> pair : Pair.zip(inputFields, outputFields)) {
-      final ObjectNode objectNode = implementor.mapper.createObjectNode();
-      transforms.add(objectNode);
-      objectNode.put("expr", pair.left);
-      objectNode.put("ref", "output." + pair.right);
-//      objectNode.put("ref", pair.right);
-    }
-    return implementor.add(project);
-  }
-
-  /**
-   * Returns whether there are any elements in common between left and right.
-   */
-  private static <T> boolean intersects(List<T> left, List<T> right) {
-    return new HashSet<>(left).removeAll(right);
-  }
-
-  private boolean uniqueFieldNames(RelDataType rowType) {
-    return isUnique(rowType.getFieldNames());
-  }
-
-  private static <T> boolean isUnique(List<T> list) {
-    return new HashSet<>(list).size() == list.size();
-  }
-
-  private static String toDrill(JoinRelType joinType) {
-    switch (joinType) {
-    case LEFT:
-      return "left";
-    case RIGHT:
-      return "right";
-    case INNER:
-      return "inner";
-    case FULL:
-      return "outer";
-    default:
-      throw new AssertionError(joinType);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillJoinRule.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillJoinRule.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillJoinRule.java
deleted file mode 100644
index 3c5e072..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillJoinRule.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import org.eigenbase.rel.InvalidRelException;
-import org.eigenbase.rel.JoinRel;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.*;
-import org.eigenbase.trace.EigenbaseTrace;
-
-import java.util.logging.Logger;
-
-/**
- * Rule that converts a {@link JoinRel} to a {@link DrillJoinRel}, which is implemented by Drill "join" operation.
- */
-public class DrillJoinRule extends RelOptRule {
-  public static final RelOptRule INSTANCE = new DrillJoinRule();
-  protected static final Logger tracer = EigenbaseTrace.getPlannerTracer();
-
-  private DrillJoinRule() {
-    super(
-        RelOptRule.some(JoinRel.class, Convention.NONE, RelOptRule.any(RelNode.class), RelOptRule.any(RelNode.class)),
-        "DrillJoinRule");
-  }
-
-  @Override
-  public void onMatch(RelOptRuleCall call) {
-    final JoinRel join = (JoinRel) call.rel(0);
-    final RelNode left = call.rel(1);
-    final RelNode right = call.rel(2);
-    final RelTraitSet traits = join.getTraitSet().plus(DrillRel.CONVENTION);
-
-    final RelNode convertedLeft = convert(left, traits);
-    final RelNode convertedRight = convert(right, traits);
-    try {
-      call.transformTo(new DrillJoinRel(join.getCluster(), traits, convertedLeft, convertedRight, join.getCondition(),
-          join.getJoinType()));
-    } catch (InvalidRelException e) {
-      tracer.warning(e.toString());
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillLimitRel.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillLimitRel.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillLimitRel.java
deleted file mode 100644
index c1bf3d2..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillLimitRel.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.apache.drill.common.logical.data.Limit;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.rel.SingleRel;
-import org.eigenbase.relopt.RelOptCluster;
-import org.eigenbase.relopt.RelTraitSet;
-import org.eigenbase.rex.RexLiteral;
-import org.eigenbase.rex.RexNode;
-
-import java.util.List;
-
-public class DrillLimitRel extends SingleRel implements DrillRel {
-  private RexNode offset;
-  private RexNode fetch;
-
-  public DrillLimitRel(RelOptCluster cluster, RelTraitSet traitSet, RelNode child, RexNode offset, RexNode fetch) {
-    super(cluster, traitSet, child);
-    this.offset = offset;
-    this.fetch = fetch;
-  }
-
-  @Override
-  public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
-    return new DrillLimitRel(getCluster(), traitSet, sole(inputs), offset, fetch);
-  }
-
-  @Override
-  public int implement(DrillImplementor implementor) {
-    int inputId = implementor.visitChild(this, 0, getChild());
-
-
-    // First offset to include into results (inclusive). Null implies it is starting from offset 0
-    int first = offset != null ? Math.max(0, RexLiteral.intValue(offset)) : 0;
-
-    // Last offset to stop including into results (exclusive), translating fetch row counts into an offset.
-    // Null value implies including entire remaining result set from first offset
-    Integer last = fetch != null ? Math.max(0, RexLiteral.intValue(fetch)) + first : null;
-    return implementor.add(new Limit(first, last), inputId);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillLimitRule.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillLimitRule.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillLimitRule.java
deleted file mode 100644
index 0b835c9..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillLimitRule.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.rel.SortRel;
-import org.eigenbase.relopt.Convention;
-import org.eigenbase.relopt.RelOptRule;
-import org.eigenbase.relopt.RelOptRuleCall;
-import org.eigenbase.relopt.RelTraitSet;
-
-/**
- * This rule converts a SortRel that has either a offset and fetch into a Drill Sort and Limit Rel
- */
-public class DrillLimitRule extends RelOptRule {
-  public static DrillLimitRule INSTANCE = new DrillLimitRule();
-
-  private DrillLimitRule() {
-    super(RelOptRule.some(SortRel.class, Convention.NONE, RelOptRule.any(RelNode.class)), "DrillLimitRule");
-  }
-
-  @Override
-  public boolean matches(RelOptRuleCall call) {
-    final SortRel sort = call.rel(0);
-    return sort.offset != null || sort.fetch != null;
-  }
-
-  @Override
-  public void onMatch(RelOptRuleCall call) {
-    final SortRel incomingSort = call.rel(0);
-    final RelTraitSet incomingTraits = incomingSort.getTraitSet();
-    RelNode input = incomingSort.getChild();
-
-    // if the Optiq sort rel includes a collation and a limit, we need to create a copy the sort rel that excludes the
-    // limit information.
-    if (!incomingSort.getCollation().getFieldCollations().isEmpty()) {
-      input = incomingSort.copy(incomingTraits, input, incomingSort.getCollation(), null, null);
-    }
-
-    RelNode convertedInput = convert(input, input.getTraitSet().plus(DrillRel.CONVENTION));
-    call.transformTo(new DrillLimitRel(incomingSort.getCluster(), incomingTraits.plus(DrillRel.CONVENTION), convertedInput, incomingSort.offset, incomingSort.fetch));
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillOptiq.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillOptiq.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillOptiq.java
deleted file mode 100644
index 1897151..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillOptiq.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import net.hydromatic.linq4j.Ord;
-
-import org.apache.drill.exec.client.DrillClient;
-import org.apache.drill.exec.work.fragment.StatusReporter;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.RelOptPlanner;
-import org.eigenbase.reltype.RelDataTypeField;
-import org.eigenbase.rex.RexCall;
-import org.eigenbase.rex.RexCorrelVariable;
-import org.eigenbase.rex.RexDynamicParam;
-import org.eigenbase.rex.RexFieldAccess;
-import org.eigenbase.rex.RexInputRef;
-import org.eigenbase.rex.RexLiteral;
-import org.eigenbase.rex.RexLocalRef;
-import org.eigenbase.rex.RexNode;
-import org.eigenbase.rex.RexOver;
-import org.eigenbase.rex.RexRangeRef;
-import org.eigenbase.rex.RexVisitorImpl;
-import org.eigenbase.sql.SqlSyntax;
-import org.eigenbase.sql.fun.SqlStdOperatorTable;
-
-/**
- * Utilities for Drill's planner.
- */
-public class DrillOptiq {
-  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillOptiq.class);
-  
-  static void registerStandardPlannerRules(RelOptPlanner planner, DrillClient client) {
-    planner.addRule(EnumerableDrillRule.getInstance(client));
-
-    // planner.addRule(DrillTableModificationConverterRule.INSTANCE);
-    // planner.addRule(DrillCalcConverterRule.INSTANCE);
-
-    planner.addRule(DrillFilterRule.INSTANCE);
-    planner.addRule(DrillProjectRule.INSTANCE);
-    planner.addRule(DrillAggregateRule.INSTANCE);
-
-    // Enable when https://issues.apache.org/jira/browse/DRILL-57 fixed
-    if (false) planner.addRule(DrillValuesRule.INSTANCE);
-    planner.addRule(DrillLimitRule.INSTANCE);
-    planner.addRule(DrillSortRule.INSTANCE);
-    planner.addRule(DrillJoinRule.INSTANCE);
-    planner.addRule(DrillUnionRule.INSTANCE);
-    // planner.addRule(AbstractConverter.ExpandConversionRule.instance);
-  }
-
-  /**
-   * Converts a tree of {@link RexNode} operators into a scalar expression in Drill syntax.
-   */
-  static String toDrill(RelNode input, RexNode expr) {
-    final RexToDrill visitor = new RexToDrill(input);
-    expr.accept(visitor);
-    return visitor.buf.toString();
-  }
-
-  private static class RexToDrill extends RexVisitorImpl<StringBuilder> {
-    final StringBuilder buf = new StringBuilder();
-    private final RelNode input;
-
-    RexToDrill(RelNode input) {
-      super(true);
-      this.input = input;
-    }
-
-    @Override
-    public StringBuilder visitCall(RexCall call) {
-      logger.debug("RexCall {}, {}", call);
-      final SqlSyntax syntax = call.getOperator().getSyntax();
-      switch (syntax) {
-      case Binary:
-        logger.debug("Binary");
-        buf.append("(");
-        call.getOperands().get(0).accept(this).append(" ").append(call.getOperator().getName()).append(" ");
-        return call.getOperands().get(1).accept(this).append(")");
-      case Function:
-        logger.debug("Function");
-        buf.append(call.getOperator().getName().toLowerCase()).append("(");
-        for (Ord<RexNode> operand : Ord.zip(call.getOperands())) {
-          buf.append(operand.i > 0 ? ", " : "");
-          operand.e.accept(this);
-        }
-        return buf.append(")");
-      case Special:
-        logger.debug("Special");
-        switch (call.getKind()) {
-        case Cast:
-          logger.debug("Cast {}", buf);
-          // Ignore casts. Drill is type-less.
-          logger.debug("Ignoring cast {}, {}", call.getOperands().get(0), call.getOperands().get(0).getClass());
-          return call.getOperands().get(0).accept(this);
-        }
-        if (call.getOperator() == SqlStdOperatorTable.itemOp) {
-          final RexNode left = call.getOperands().get(0);
-          final RexLiteral literal = (RexLiteral) call.getOperands().get(1);
-          final String field = (String) literal.getValue2();
-//          buf.append('\'');
-          final int length = buf.length();
-          left.accept(this);
-          if (buf.length() > length) {
-            // check before generating empty LHS if inputName is null
-            buf.append('.');
-          }
-          buf.append(field);
-//          buf.append('\'');
-          return buf;
-        }
-        logger.debug("Not cast.");
-        // fall through
-      default:
-        throw new AssertionError("todo: implement syntax " + syntax + "(" + call + ")");
-      }
-    }
-
-    private StringBuilder doUnknown(Object o){
-      logger.warn("Doesn't currently support consumption of {}.", o);
-      return buf;
-    }
-    @Override
-    public StringBuilder visitLocalRef(RexLocalRef localRef) {
-      return doUnknown(localRef);
-    }
-
-    @Override
-    public StringBuilder visitOver(RexOver over) {
-      return doUnknown(over);
-    }
-
-    @Override
-    public StringBuilder visitCorrelVariable(RexCorrelVariable correlVariable) {
-      return doUnknown(correlVariable);
-    }
-
-    @Override
-    public StringBuilder visitDynamicParam(RexDynamicParam dynamicParam) {
-      return doUnknown(dynamicParam);
-    }
-
-    @Override
-    public StringBuilder visitRangeRef(RexRangeRef rangeRef) {
-      return doUnknown(rangeRef);
-    }
-
-    @Override
-    public StringBuilder visitFieldAccess(RexFieldAccess fieldAccess) {
-      return super.visitFieldAccess(fieldAccess);
-    }
-
-    @Override
-    public StringBuilder visitInputRef(RexInputRef inputRef) {
-      final int index = inputRef.getIndex();
-      final RelDataTypeField field = input.getRowType().getFieldList().get(index);
-      buf.append(field.getName());
-      return buf;
-    }
-
-    @Override
-    public StringBuilder visitLiteral(RexLiteral literal) {
-      return buf.append(literal);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillPrepareImpl.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillPrepareImpl.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillPrepareImpl.java
deleted file mode 100644
index af7bbc7..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillPrepareImpl.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import net.hydromatic.optiq.prepare.OptiqPrepareImpl;
-import net.hydromatic.optiq.rules.java.JavaRules;
-
-import org.apache.drill.jdbc.Driver;
-import org.eigenbase.relopt.RelOptPlanner;
-
-/**
- * Implementation of {@link net.hydromatic.optiq.jdbc.OptiqPrepare} for Drill.
- */
-public class DrillPrepareImpl extends OptiqPrepareImpl {
-  final Driver driver;
-  public DrillPrepareImpl(Driver driver) {
-    super();
-    this.driver = driver;
-  }
-
-  @Override
-  protected RelOptPlanner createPlanner() {
-    final RelOptPlanner planner = super.createPlanner();
-    planner.addRule(EnumerableDrillRule.getInstance(driver == null ? null : driver.getClient()));
-    planner.addRule(DrillValuesRule.INSTANCE);
-
-    planner.removeRule(JavaRules.ENUMERABLE_JOIN_RULE);
-    planner.removeRule(JavaRules.ENUMERABLE_CALC_RULE);
-    planner.removeRule(JavaRules.ENUMERABLE_AGGREGATE_RULE);
-    planner.removeRule(JavaRules.ENUMERABLE_SORT_RULE);
-    planner.removeRule(JavaRules.ENUMERABLE_LIMIT_RULE);
-    planner.removeRule(JavaRules.ENUMERABLE_UNION_RULE);
-    planner.removeRule(JavaRules.ENUMERABLE_INTERSECT_RULE);
-    planner.removeRule(JavaRules.ENUMERABLE_MINUS_RULE);
-    planner.removeRule(JavaRules.ENUMERABLE_TABLE_MODIFICATION_RULE);
-    planner.removeRule(JavaRules.ENUMERABLE_VALUES_RULE);
-    planner.removeRule(JavaRules.ENUMERABLE_WINDOW_RULE);
-    planner.removeRule(JavaRules.ENUMERABLE_ONE_ROW_RULE);
-    return planner;
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillProjectRel.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillProjectRel.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillProjectRel.java
deleted file mode 100644
index fabfb77..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillProjectRel.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.rex.RexNode;
-import org.eigenbase.util.Pair;
-
-import java.util.*;
-
-/**
- * Project implemented in Drill.
- */
-public class DrillProjectRel extends ProjectRelBase implements DrillRel {
-  protected DrillProjectRel(RelOptCluster cluster, RelTraitSet traits, RelNode child, List<RexNode> exps,
-      RelDataType rowType) {
-    super(cluster, traits, child, exps, rowType, Flags.Boxed, Collections.<RelCollation> emptyList());
-    assert getConvention() == CONVENTION;
-  }
-
-  public DrillProjectRel(RelOptCluster cluster, RelTraitSet traits, RelNode child, List<RexNode> exps,
-      RelDataType rowType, int flags, List<RelCollation> collationList) {
-    super(cluster, traits, child, exps, rowType, flags, collationList);
-
-  }
-
-  @Override
-  public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
-    return new DrillProjectRel(getCluster(), traitSet, sole(inputs), new ArrayList<RexNode>(exps), rowType);
-  }
-
-  @Override
-  public RelOptCost computeSelfCost(RelOptPlanner planner) {
-    return super.computeSelfCost(planner).multiplyBy(0.1);
-  }
-
-  private List<Pair<RexNode, String>> projects() {
-    return Pair.zip(exps, getRowType().getFieldNames());
-  }
-
-  @Override
-  public int implement(DrillImplementor implementor) {
-    int inputId = implementor.visitChild(this, 0, getChild());
-    final ObjectNode project = implementor.mapper.createObjectNode();
-    /*
-     * E.g. { op: "project", projections: [ { ref: "output.quantity", expr: "donuts.sales"} ]
-     */
-    project.put("op", "project");
-    project.put("input", inputId);
-    final ArrayNode transforms = implementor.mapper.createArrayNode();
-    project.put("projections", transforms);
-    for (Pair<RexNode, String> pair : projects()) {
-      final ObjectNode objectNode = implementor.mapper.createObjectNode();
-      transforms.add(objectNode);
-      String expr = DrillOptiq.toDrill(getChild(), pair.left);
-      objectNode.put("expr", expr);
-      String ref = "output." + pair.right;
-//      String ref = pair.right;
-      objectNode.put("ref", ref);
-    }
-    return implementor.add(project);
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillProjectRule.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillProjectRule.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillProjectRule.java
deleted file mode 100644
index 36b272f..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillProjectRule.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import org.eigenbase.rel.ProjectRel;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.Convention;
-import org.eigenbase.relopt.RelOptRule;
-import org.eigenbase.relopt.RelOptRuleCall;
-import org.eigenbase.relopt.RelTraitSet;
-
-/**
- * Rule that converts a {@link org.eigenbase.rel.ProjectRel} to a Drill "project" operation.
- */
-public class DrillProjectRule extends RelOptRule {
-  public static final RelOptRule INSTANCE = new DrillProjectRule();
-
-  private DrillProjectRule() {
-    super(RelOptRule.some(ProjectRel.class, Convention.NONE, RelOptRule.any(RelNode.class)), "DrillProjectRule");
-  }
-
-  @Override
-  public void onMatch(RelOptRuleCall call) {
-    final ProjectRel project = (ProjectRel) call.rel(0);
-    final RelNode input = call.rel(1);
-    final RelTraitSet traits = project.getTraitSet().plus(DrillRel.CONVENTION);
-    final RelNode convertedInput = convert(input, traits);
-    call.transformTo(new DrillProjectRel(project.getCluster(), traits, convertedInput, project.getProjects(), project
-        .getRowType()));
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillRel.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillRel.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillRel.java
deleted file mode 100644
index 4c9ece9..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillRel.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.Convention;
-
-/**
- * Relational expression that is implemented in Drill.
- */
-public interface DrillRel extends RelNode {
-  /** Calling convention for relational expressions that are "implemented" by
-   * generating Drill logical plans. */
-  Convention CONVENTION = new Convention.Impl("DRILL", DrillRel.class);
-
-  int implement(DrillImplementor implementor);
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillScan.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillScan.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillScan.java
deleted file mode 100644
index a165fea..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillScan.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import org.apache.drill.jdbc.DrillTable;
-import org.eigenbase.rel.TableAccessRelBase;
-import org.eigenbase.relopt.RelOptCluster;
-import org.eigenbase.relopt.RelOptPlanner;
-import org.eigenbase.relopt.RelOptTable;
-import org.eigenbase.relopt.RelTraitSet;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * GroupScan of a Drill table.
- */
-public class DrillScan extends TableAccessRelBase implements DrillRel {
-  private final DrillTable drillTable;
-
-  /** Creates a DrillScan. */
-  public DrillScan(RelOptCluster cluster, RelTraitSet traits, RelOptTable table) {
-    super(cluster, traits, table);
-    assert getConvention() == CONVENTION;
-    this.drillTable = table.unwrap(DrillTable.class);
-    assert drillTable != null;
-  }
-
-  @Override
-  public void register(RelOptPlanner planner) {
-    super.register(planner);
-    DrillOptiq.registerStandardPlannerRules(planner, drillTable.client);
-  }
-
-  public int implement(DrillImplementor implementor) {
-    final ObjectNode node = implementor.mapper.createObjectNode();
-    node.put("op", "scan");
-    node.put("memo", "initial_scan");
-    node.put("ref", "_MAP"); // output is a record with a single field, '_MAP'
-    node.put("storageengine", drillTable.getStorageEngineName());
-    node.put("selection", implementor.mapper.convertValue(drillTable.getSelection(), JsonNode.class));
-    implementor.registerSource(drillTable);
-    return implementor.add(node);
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillSortRel.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillSortRel.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillSortRel.java
deleted file mode 100644
index 929d381..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillSortRel.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import java.util.List;
-
-import net.hydromatic.linq4j.Ord;
-
-import org.eigenbase.rel.RelCollation;
-import org.eigenbase.rel.RelFieldCollation;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.rel.SortRel;
-import org.eigenbase.relopt.RelOptCluster;
-import org.eigenbase.relopt.RelTraitSet;
-
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.eigenbase.rex.RexLiteral;
-import org.eigenbase.rex.RexNode;
-
-/**
- * Sort implemented in Drill.
- */
-public class DrillSortRel extends SortRel implements DrillRel {
-
-  /** Creates a DrillSortRel. */
-  public DrillSortRel(RelOptCluster cluster, RelTraitSet traits, RelNode input, RelCollation collation) {
-    super(cluster, traits, input, collation);
-  }
-
-  /** Creates a DrillSortRel with offset and fetch. */
-  public DrillSortRel(RelOptCluster cluster, RelTraitSet traits, RelNode input, RelCollation collation, RexNode offset, RexNode fetch) {
-    super(cluster, traits, input, collation, offset, fetch);
-  }
-
-  @Override
-  public DrillSortRel copy(RelTraitSet traitSet, RelNode input, RelCollation collation, RexNode offset, RexNode fetch) {
-    return new DrillSortRel(getCluster(), traitSet, input, collation, offset, fetch);
-  }
-
-  @Override
-  public int implement(DrillImplementor implementor) {
-    int inputId = implementor.visitChild(this, 0, getChild());
-    final List<String> childFields = getChild().getRowType().getFieldNames();
-    /*
-     * E.g. { op: "order", input: 4, ordering: [ {order: "asc", expr: "deptId"} ] }
-     */
-    final ObjectNode order = implementor.mapper.createObjectNode();
-    order.put("op", "order");
-    order.put("input", inputId);
-    final ArrayNode orderings = implementor.mapper.createArrayNode();
-    order.put("orderings", orderings);
-    for (Ord<RelFieldCollation> fieldCollation : Ord.zip(this.collation.getFieldCollations())) {
-      final ObjectNode ordering = implementor.mapper.createObjectNode();
-      ordering.put("order", toDrill(fieldCollation.e));
-      ordering.put("expr", childFields.get(fieldCollation.e.getFieldIndex()));
-      switch (fieldCollation.e.nullDirection) {
-      case FIRST:
-        ordering.put("nullCollation", "first");
-        break;
-      default:
-        ordering.put("nullCollation", "last");
-        break;
-      }
-      orderings.add(ordering);
-    }
-
-    return implementor.add(order);
-  }
-
-
-
-  private static String toDrill(RelFieldCollation collation) {
-    switch (collation.getDirection()) {
-    case Ascending:
-      return "asc";
-    case Descending:
-      return "desc";
-    default:
-      throw new AssertionError(collation.getDirection());
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillSortRule.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillSortRule.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillSortRule.java
deleted file mode 100644
index 93ffb62..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillSortRule.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import org.eigenbase.rel.SortRel;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.*;
-
-/**
- * Rule that converts an {@link SortRel} to a {@link DrillSortRel}, implemented by a Drill "order" operation.
- */
-public class DrillSortRule extends RelOptRule {
-  public static final RelOptRule INSTANCE = new DrillSortRule();
-
-  private DrillSortRule() {
-    super(RelOptRule.some(SortRel.class, Convention.NONE, RelOptRule.any(RelNode.class)), "DrillSortRule");
-  }
-
-  @Override
-  public boolean matches(RelOptRuleCall call) {
-    final SortRel sort = call.rel(0);
-    return sort.offset == null && sort.fetch == null;
-  }
-
-  @Override
-  public void onMatch(RelOptRuleCall call) {
-
-    final SortRel sort = call.rel(0);
-
-    final RelNode input = call.rel(1);
-    final RelTraitSet traits = sort.getTraitSet().plus(DrillRel.CONVENTION);
-
-    final RelNode convertedInput = convert(input, input.getTraitSet().plus(DrillRel.CONVENTION));
-    call.transformTo(new DrillSortRel(sort.getCluster(), traits, convertedInput, sort.getCollation()));
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillUnionRel.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillUnionRel.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillUnionRel.java
deleted file mode 100644
index 90cda2e..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillUnionRel.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import net.hydromatic.linq4j.Ord;
-import org.eigenbase.rel.UnionRelBase;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.*;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Union implemented in Drill.
- */
-public class DrillUnionRel extends UnionRelBase implements DrillRel {
-  /** Creates a DrillUnionRel. */
-  public DrillUnionRel(RelOptCluster cluster, RelTraitSet traits,
-      List<RelNode> inputs, boolean all) {
-    super(cluster, traits, inputs, all);
-  }
-
-  @Override
-  public DrillUnionRel copy(RelTraitSet traitSet, List<RelNode> inputs,
-      boolean all) {
-    return new DrillUnionRel(getCluster(), traitSet, inputs, all);
-  }
-
-  @Override
-  public RelOptCost computeSelfCost(RelOptPlanner planner) {
-    // divide cost by two to ensure cheaper than EnumerableDrillRel
-    return super.computeSelfCost(planner).multiplyBy(.5);
-  }
-
-  @Override
-  public int implement(DrillImplementor implementor) {
-    List<Integer> inputIds = new ArrayList<>();
-    for (Ord<RelNode> input : Ord.zip(inputs)) {
-      inputIds.add(implementor.visitChild(this, input.i, input.e));
-    }
-/*
-    E.g. {
-      op: "union",
-      distinct: true,
-	  inputs: [2, 4]
-	}
-*/
-    final ObjectNode union = implementor.mapper.createObjectNode();
-    union.put("op", "union");
-    union.put("distinct", !all);
-    final ArrayNode inputs = implementor.mapper.createArrayNode();
-    union.put("inputs", inputs);
-    for (Integer inputId : inputIds) {
-      inputs.add(inputId);
-    }
-    return implementor.add(union);
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillUnionRule.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillUnionRule.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillUnionRule.java
deleted file mode 100644
index 0d70443..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillUnionRule.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import org.eigenbase.rel.UnionRel;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.*;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Rule that converts a {@link UnionRel} to a {@link DrillUnionRel}, implemented by a "union" operation.
- */
-public class DrillUnionRule extends RelOptRule {
-  public static final RelOptRule INSTANCE = new DrillUnionRule();
-
-  private DrillUnionRule() {
-    super(RelOptRule.any(UnionRel.class, Convention.NONE), "DrillUnionRule");
-  }
-
-  @Override
-  public void onMatch(RelOptRuleCall call) {
-    final UnionRel union = (UnionRel) call.rel(0);
-    final RelTraitSet traits = union.getTraitSet().plus(DrillRel.CONVENTION);
-    final List<RelNode> convertedInputs = new ArrayList<>();
-    for (RelNode input : union.getInputs()) {
-      final RelNode convertedInput = convert(input, traits);
-      convertedInputs.add(convertedInput);
-    }
-    call.transformTo(new DrillUnionRel(union.getCluster(), traits, convertedInputs, union.all));
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRel.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRel.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRel.java
deleted file mode 100644
index 5bab4f8..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRel.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import org.eigenbase.rel.ValuesRelBase;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.rex.RexLiteral;
-
-import java.util.List;
-
-/**
- * Values implemented in Drill.
- */
-public class DrillValuesRel extends ValuesRelBase implements DrillRel {
-  protected DrillValuesRel(RelOptCluster cluster, RelDataType rowType, List<List<RexLiteral>> tuples, RelTraitSet traits) {
-    super(cluster, rowType, tuples, traits);
-    assert getConvention() == CONVENTION;
-  }
-
-  @Override
-  public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
-    assert inputs.isEmpty();
-    return new DrillValuesRel(getCluster(), rowType, tuples, traitSet);
-  }
-
-  @Override
-  public RelOptCost computeSelfCost(RelOptPlanner planner) {
-    return super.computeSelfCost(planner).multiplyBy(0.1);
-  }
-
-  @Override
-  public int implement(DrillImplementor implementor) {
-    // Update when https://issues.apache.org/jira/browse/DRILL-57 fixed
-    throw new UnsupportedOperationException();
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRule.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRule.java b/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRule.java
deleted file mode 100644
index b5e3eb2..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/DrillValuesRule.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import org.eigenbase.rel.ValuesRel;
-import org.eigenbase.relopt.*;
-
-/**
- * Rule that converts a {@link ValuesRel} to a Drill "values" operation.
- */
-public class DrillValuesRule extends RelOptRule {
-  public static final RelOptRule INSTANCE = new DrillValuesRule();
-
-  private DrillValuesRule() {
-    super(RelOptRule.any(ValuesRel.class, Convention.NONE), "DrillValuesRule");
-  }
-
-  @Override
-  public void onMatch(RelOptRuleCall call) {
-    final ValuesRel values = (ValuesRel) call.rel(0);
-    final RelTraitSet traits = values.getTraitSet().plus(DrillRel.CONVENTION);
-    call.transformTo(new DrillValuesRel(values.getCluster(), values.getRowType(), values.getTuples(), traits));
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/EnumerableDrill.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/EnumerableDrill.java b/sqlparser/src/main/java/org/apache/drill/optiq/EnumerableDrill.java
deleted file mode 100644
index 7b0b24d..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/EnumerableDrill.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CompletionService;
-import java.util.concurrent.ExecutorCompletionService;
-import java.util.concurrent.Future;
-import java.util.concurrent.LinkedBlockingDeque;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-import net.hydromatic.linq4j.AbstractEnumerable;
-import net.hydromatic.linq4j.Enumerable;
-import net.hydromatic.linq4j.Enumerator;
-
-import org.apache.drill.common.config.DrillConfig;
-import org.apache.drill.common.logical.LogicalPlan;
-import org.apache.drill.exec.ref.IteratorRegistry;
-import org.apache.drill.exec.ref.ReferenceInterpreter;
-import org.apache.drill.exec.ref.RunOutcome;
-import org.apache.drill.exec.ref.eval.BasicEvaluatorFactory;
-import org.apache.drill.exec.ref.rse.RSERegistry;
-import org.apache.drill.exec.store.json.JSONRecordReader;
-import org.apache.drill.jdbc.DrillHandler;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * Runtime helper that executes a Drill query and converts it into an {@link Enumerable}.
- */
-public class EnumerableDrill<E> extends AbstractEnumerable<E> implements Enumerable<E> {
-  
-  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(EnumerableDrill.class);
-  
-  private final LogicalPlan plan;
-  final BlockingQueue<Object> queue = new ArrayBlockingQueue<>(100);
-  final DrillConfig config;
-  private final String holder;
-  private final List<String> fields;
-
-  private static final ObjectMapper mapper = createMapper();
-
-  /**
-   * Creates a DrillEnumerable.
-   * 
-   * @param plan
-   *          Logical plan
-   * @param clazz
-   *          Type of elements returned from enumerable
-   * @param fields
-   *          Names of fields, or null to return the whole blob
-   */
-  public EnumerableDrill(DrillConfig config, LogicalPlan plan, Class<E> clazz, List<String> fields) {
-    this.plan = plan;
-    this.config = config;
-    this.holder = null;
-    this.fields = fields;
-    config.setSinkQueues(0, queue);
-  }
-
-  /**
-   * Creates a DrillEnumerable from a plan represented as a string. Each record returned is a {@link JsonNode}.
-   */
-  public static <E> EnumerableDrill<E> of(DrillHandler handler, String plan, final List<String> fieldNames, Class<E> clazz) {
-    DrillConfig config = DrillConfig.create();
-    final LogicalPlan parse = LogicalPlan.parse(config, plan);
-    return new EnumerableDrill<>(config, parse, clazz, fieldNames);
-  }
-
-  /** Runs the plan as a background task. */
-  Future<Collection<RunOutcome>> runPlan(CompletionService<Collection<RunOutcome>> service) {
-    IteratorRegistry ir = new IteratorRegistry();
-    DrillConfig config = DrillConfig.create();
-    config.setSinkQueues(0, queue);
-    final ReferenceInterpreter i = new ReferenceInterpreter(plan, ir, new BasicEvaluatorFactory(ir), new RSERegistry(
-        config));
-    try {
-      i.setup();
-    } catch (IOException e) {
-      logger.error("IOException during query", e);
-      throw new RuntimeException(e);
-    }
-    return service.submit(new Callable<Collection<RunOutcome>>() {
-      @Override
-      public Collection<RunOutcome> call() throws Exception {
-        Collection<RunOutcome> outcomes = i.run();
-
-        for (RunOutcome outcome : outcomes) {
-          System.out.println("============");
-          System.out.println(outcome);
-          if (outcome.outcome == RunOutcome.OutcomeType.FAILED && outcome.exception != null) {
-            outcome.exception.printStackTrace();
-          }
-        }
-        return outcomes;
-      }
-    });
-  }
-
-  @Override
-  public Enumerator<E> enumerator() {
-    // TODO: use a completion service from the container
-    final ExecutorCompletionService<Collection<RunOutcome>> service = new ExecutorCompletionService<Collection<RunOutcome>>(
-        new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>(10)));
-
-    // Run the plan using an executor. It runs in a different thread, writing
-    // results to our queue.
-    //
-    // TODO: use the result of task, and check for exceptions
-    final Future<Collection<RunOutcome>> task = runPlan(service);
-
-    return new JsonEnumerator(queue, fields);
-  }
-
-  private static ObjectMapper createMapper() {
-    return new ObjectMapper();
-  }
-
-  /**
-   * Converts a JSON document, represented as an array of bytes, into a Java object (consisting of DistributedMap, List, String,
-   * Integer, Double, Boolean).
-   */
-  static Object parseJson(byte[] bytes) {
-    try {
-      return wrapper(mapper.readTree(bytes));
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
-  }
-
-  /**
-   * Converts a JSON node to Java objects ({@link List}, {@link Map}, {@link String}, {@link Integer}, {@link Double},
-   * {@link Boolean}.
-   */
-  static Object wrapper(JsonNode node) {
-    switch (node.asToken()) {
-    case START_OBJECT:
-      return map((ObjectNode) node);
-    case START_ARRAY:
-      return array((ArrayNode) node);
-    case VALUE_STRING:
-      return node.asText();
-    case VALUE_NUMBER_INT:
-      return node.asInt();
-    case VALUE_NUMBER_FLOAT:
-      return node.asDouble();
-    case VALUE_TRUE:
-      return Boolean.TRUE;
-    case VALUE_FALSE:
-      return Boolean.FALSE;
-    case VALUE_NULL:
-      return null;
-    default:
-      throw new AssertionError("unexpected: " + node + ": " + node.asToken());
-    }
-  }
-
-  private static List<Object> array(ArrayNode node) {
-    final List<Object> list = new ArrayList<>();
-    for (JsonNode jsonNode : node) {
-      list.add(wrapper(jsonNode));
-    }
-    return Collections.unmodifiableList(list);
-  }
-
-  private static SortedMap<String, Object> map(ObjectNode node) {
-    // TreeMap makes the results deterministic.
-    final TreeMap<String, Object> map = new TreeMap<>();
-    final Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
-    while (fields.hasNext()) {
-      Map.Entry<String, JsonNode> next = fields.next();
-      map.put(next.getKey(), wrapper(next.getValue()));
-    }
-    return Collections.unmodifiableSortedMap(map);
-  }
-
-  private static class JsonEnumerator implements Enumerator {
-    private final BlockingQueue<Object> queue;
-    private final String holder;
-    private final List<String> fields;
-    private Object current;
-
-    public JsonEnumerator(BlockingQueue<Object> queue, List<String> fields) {
-      this.queue = queue;
-      this.holder = null;
-      this.fields = fields;
-    }
-
-    public Object current() {
-      return current;
-    }
-
-    public void close() {
-
-    }
-
-    public boolean moveNext() {
-      try {
-        Object o = queue.take();
-        if (o instanceof RunOutcome.OutcomeType) {
-          switch ((RunOutcome.OutcomeType) o) {
-          case SUCCESS:
-            return false; // end of data
-          case CANCELED:
-            throw new RuntimeException("canceled");
-          case FAILED:
-          default:
-            throw new RuntimeException("failed");
-          }
-        } else {
-          Object o1 = parseJson((byte[]) o);
-          if (holder != null) {
-            o1 = ((Map<String, Object>) o1).get(holder);
-          }
-          if (fields == null) {
-            current = o1;
-          } else {
-            final Map<String, Object> map = (Map<String, Object>) o1;
-            if (fields.size() == 1) {
-              current = map.get(fields.get(0));
-            } else {
-              Object[] os = new Object[fields.size()];
-              for (int i = 0; i < os.length; i++) {
-                os[i] = map.get(fields.get(i));
-              }
-              current = os;
-            }
-          }
-          return true;
-        }
-      } catch (InterruptedException e) {
-        Thread.interrupted();
-        throw new RuntimeException(e);
-      }
-    }
-
-    public void reset() {
-      throw new UnsupportedOperationException();
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b3460af8/sqlparser/src/main/java/org/apache/drill/optiq/EnumerableDrillFullEngine.java
----------------------------------------------------------------------
diff --git a/sqlparser/src/main/java/org/apache/drill/optiq/EnumerableDrillFullEngine.java b/sqlparser/src/main/java/org/apache/drill/optiq/EnumerableDrillFullEngine.java
deleted file mode 100644
index 318f982..0000000
--- a/sqlparser/src/main/java/org/apache/drill/optiq/EnumerableDrillFullEngine.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.drill.optiq;
-
-import java.util.List;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-
-import net.hydromatic.linq4j.AbstractEnumerable;
-import net.hydromatic.linq4j.Enumerable;
-import net.hydromatic.linq4j.Enumerator;
-import net.hydromatic.optiq.DataContext;
-
-import org.apache.drill.common.config.DrillConfig;
-import org.apache.drill.exec.client.DrillClient;
-import org.apache.drill.jdbc.DrillHandler.FakeSchema;
-import org.apache.drill.sql.client.full.DrillFullImpl;
-import org.apache.drill.sql.client.ref.DrillRefImpl;
-
-import com.fasterxml.jackson.databind.JsonNode;
-
-/**
- * Runtime helper that executes a Drill query and converts it into an {@link Enumerable}.
- */
-public class EnumerableDrillFullEngine<E> extends AbstractEnumerable<E> implements Enumerable<E> {
-  private final String plan;
-  final BlockingQueue<Object> queue = new ArrayBlockingQueue<>(100);
-  final DrillConfig config;
-  private final List<String> fields;
-  private DrillClient client;
-  
-  /**
-   * Creates a DrillEnumerable.
-   * 
-   * @param plan
-   *          Logical plan
-   * @param clazz
-   *          Type of elements returned from enumerable
-   * @param fields
-   *          Names of fields, or null to return the whole blob
-   */
-  public EnumerableDrillFullEngine(DrillConfig config, String plan, Class<E> clazz, List<String> fields,
-      DrillClient client) {
-    this.plan = plan;
-    this.config = config;
-    this.fields = fields;
-    this.client = client;
-    config.setSinkQueues(0, queue);
-  }
-
-  /**
-   * Creates a DrillEnumerable from a plan represented as a string. Each record returned is a {@link JsonNode}.
-   */
-  public static <E> EnumerableDrillFullEngine<E> of(String plan, final List<String> fieldNames, Class<E> clazz,
-      DataContext context) {
-    DrillConfig config = DrillConfig.create();
-    FakeSchema s = (FakeSchema) context.getSubSchema("--FAKE--");
-    return new EnumerableDrillFullEngine<>(config, plan, clazz, fieldNames, s == null ? null : s.getClient());
-  }
-
-  @Override
-  public Enumerator<E> enumerator() {
-    if (client == null) {
-      DrillRefImpl<E> impl = new DrillRefImpl<E>(plan, config, fields, queue);
-      return impl.enumerator();
-    } else {
-      DrillFullImpl<E> impl = new DrillFullImpl<E>(plan, config, fields);
-      return impl.enumerator(client);
-    }
-  }
-
-}


Mime
View raw message