You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ma...@apache.org on 2015/04/14 04:29:03 UTC

phoenix git commit: file rename

Repository: phoenix
Updated Branches:
  refs/heads/calcite 8cde1c54e -> 6a8c37629


file rename


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

Branch: refs/heads/calcite
Commit: 6a8c37629d4b5bb0c8dad7ed85fda3a99a61a3ae
Parents: 8cde1c5
Author: maryannxue <we...@intel.com>
Authored: Mon Apr 13 22:28:43 2015 -0400
Committer: maryannxue <we...@intel.com>
Committed: Mon Apr 13 22:28:43 2015 -0400

----------------------------------------------------------------------
 .../org/apache/phoenix/calcite/CalciteTest.java |   2 +-
 .../apache/phoenix/calcite/PhoenixFilter.java   |   2 +-
 .../calcite/PhoenixFilterScanMergeRule.java     |  36 --
 .../apache/phoenix/calcite/PhoenixRules.java    | 354 ------------------
 .../phoenix/calcite/PhoenixTableScan.java       |   6 +-
 .../calcite/PhoenixToEnumerableConverter.java   |   2 +-
 .../apache/phoenix/calcite/PhoenixUnion.java    |   2 +-
 .../calcite/rules/PhoenixConverterRules.java    | 365 +++++++++++++++++++
 .../rules/PhoenixFilterScanMergeRule.java       |  38 ++
 9 files changed, 411 insertions(+), 396 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/6a8c3762/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
index 59858e3..df870e1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
@@ -260,7 +260,7 @@ public class CalciteTest extends BaseClientManagedTimeIT {
         start().sql("select t1.entity_id, t2.a_string, t3.organization_id from aTable t1 join aTable t2 on t1.entity_id = t2.entity_id and t1.organization_id = t2.organization_id join atable t3 on t1.entity_id = t3.entity_id and t1.organization_id = t3.organization_id where t1.a_string = 'a'") 
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerProject(ENTITY_ID=[$19], A_STRING=[$38], ORGANIZATION_ID=[$0])\n" +
-                           "    PhoenixServerJoin(condition=[AND(=($19, $1), =($18, $0))], joinType=[inner])\n" +
+                           "    PhoenixServerJoin(condition=[AND(=($1, $19), =($0, $18))], joinType=[inner])\n" +
                            "      PhoenixTableScan(table=[[phoenix, ATABLE]])\n" +
                            "      PhoenixServerProject(ORGANIZATION_ID=[$18], ENTITY_ID=[$19], A_STRING=[$20], B_STRING=[$21], A_INTEGER=[$22], A_DATE=[$23], A_TIME=[$24], A_TIMESTAMP=[$25], X_DECIMAL=[$26], X_LONG=[$27], X_INTEGER=[$28], Y_INTEGER=[$29], A_BYTE=[$30], A_SHORT=[$31], A_FLOAT=[$32], A_DOUBLE=[$33], A_UNSIGNED_FLOAT=[$34], A_UNSIGNED_DOUBLE=[$35], ORGANIZATION_ID0=[$0], ENTITY_ID0=[$1], A_STRING0=[$2], B_STRING0=[$3], A_INTEGER0=[$4], A_DATE0=[$5], A_TIME0=[$6], A_TIMESTAMP0=[$7], X_DECIMAL0=[$8], X_LONG0=[$9], X_INTEGER0=[$10], Y_INTEGER0=[$11], A_BYTE0=[$12], A_SHORT0=[$13], A_FLOAT0=[$14], A_DOUBLE0=[$15], A_UNSIGNED_FLOAT0=[$16], A_UNSIGNED_DOUBLE0=[$17])\n" +
                            "        PhoenixServerJoin(condition=[AND(=($1, $19), =($0, $18))], joinType=[inner])\n" +

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6a8c3762/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixFilter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixFilter.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixFilter.java
index f569605..baeefaa 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixFilter.java
@@ -17,7 +17,7 @@ import org.apache.phoenix.expression.Expression;
  * relational expression in Phoenix.
  */
 public class PhoenixFilter extends Filter implements PhoenixRel {
-    protected PhoenixFilter(RelOptCluster cluster, RelTraitSet traits, RelNode input, RexNode condition) {
+    public PhoenixFilter(RelOptCluster cluster, RelTraitSet traits, RelNode input, RexNode condition) {
         super(cluster, traits, input, condition);
         assert getConvention() == PhoenixRel.CONVENTION;
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6a8c3762/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixFilterScanMergeRule.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixFilterScanMergeRule.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixFilterScanMergeRule.java
deleted file mode 100644
index 808fa99..0000000
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixFilterScanMergeRule.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.apache.phoenix.calcite;
-
-import com.google.common.base.Predicate;
-import org.apache.calcite.plan.RelOptRule;
-import org.apache.calcite.plan.RelOptRuleCall;
-import org.apache.calcite.rel.core.Filter;
-
-public class PhoenixFilterScanMergeRule extends RelOptRule {
-
-    /** Predicate that returns true if a table scan has no filter. */
-    private static final Predicate<PhoenixTableScan> NO_FILTER =
-        new Predicate<PhoenixTableScan>() {
-            @Override
-            public boolean apply(PhoenixTableScan phoenixTableScan) {
-                return phoenixTableScan.filter == null;
-            }
-        };
-
-    public static final PhoenixFilterScanMergeRule INSTANCE = new PhoenixFilterScanMergeRule();
-
-    private PhoenixFilterScanMergeRule() {
-        super(
-            operand(Filter.class,
-                operand(PhoenixTableScan.class, null, NO_FILTER, any())));
-    }
-
-    @Override
-    public void onMatch(RelOptRuleCall call) {
-        Filter filter = call.rel(0);
-        PhoenixTableScan scan = call.rel(1);
-        assert scan.filter == null : "predicate should have ensured no filter";
-        call.transformTo(new PhoenixTableScan(scan.getCluster(),
-                scan.getTraitSet(), scan.getTable(),
-                filter.getCondition()));
-    }
-}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6a8c3762/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixRules.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixRules.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixRules.java
deleted file mode 100644
index 9130f77..0000000
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixRules.java
+++ /dev/null
@@ -1,354 +0,0 @@
-package org.apache.phoenix.calcite;
-
-import org.apache.calcite.adapter.enumerable.EnumerableConvention;
-import org.apache.calcite.plan.*;
-import org.apache.calcite.rel.RelNode;
-import org.apache.calcite.rel.convert.ConverterRule;
-import org.apache.calcite.rel.logical.LogicalAggregate;
-import org.apache.calcite.rel.logical.LogicalFilter;
-import org.apache.calcite.rel.logical.LogicalJoin;
-import org.apache.calcite.rel.logical.LogicalProject;
-import org.apache.calcite.rel.logical.LogicalSort;
-import org.apache.calcite.rel.logical.LogicalUnion;
-import org.apache.calcite.util.trace.CalciteTrace;
-
-import java.util.logging.Logger;
-
-/**
- * Rules and relational operators for
- * {@link PhoenixRel#CONVENTION PHOENIX}
- * calling convention.
- */
-public class PhoenixRules {
-    private PhoenixRules() {}
-
-    protected static final Logger LOGGER = CalciteTrace.getPlannerTracer();
-
-    public static final RelOptRule[] RULES = {
-        PhoenixToEnumerableConverterRule.INSTANCE,
-        PhoenixSortRule.INSTANCE,
-        PhoenixFilterRule.INSTANCE,
-        PhoenixProjectRule.INSTANCE,
-        PhoenixAggregateRule.INSTANCE,
-        PhoenixUnionRule.INSTANCE,
-        PhoenixJoinRule.INSTANCE,
-    };
-
-    /** Base class for planner rules that convert a relational expression to
-     * Phoenix calling convention. */
-    abstract static class PhoenixConverterRule extends ConverterRule {
-        protected final Convention out;
-        public PhoenixConverterRule(
-            Class<? extends RelNode> clazz,
-            RelTrait in,
-            Convention out,
-            String description) {
-            super(clazz, in, out, description);
-            this.out = out;
-        }
-    }
-
-    /**
-     * Rule to convert a {@link org.apache.calcite.rel.core.Sort} to a
-     * {@link PhoenixSort}.
-     */
-    private static class PhoenixSortRule extends PhoenixConverterRule {
-        public static final PhoenixSortRule INSTANCE = new PhoenixSortRule();
-
-        private PhoenixSortRule() {
-            super(LogicalSort.class, Convention.NONE, PhoenixRel.CONVENTION,
-                "PhoenixSortRule");
-        }
-
-        public RelNode convert(RelNode rel) {
-            final LogicalSort sort = (LogicalSort) rel;
-            final RelTraitSet traitSet =
-                sort.getTraitSet().replace(out)
-                    .replace(sort.getCollation());
-            return new PhoenixClientSort(rel.getCluster(), traitSet,
-                convert(sort.getInput(), sort.getInput().getTraitSet().replace(out)),
-                sort.getCollation(), sort.offset, sort.fetch);
-        }
-    }
-
-    /**
-     * Rule to convert a {@link org.apache.calcite.rel.logical.LogicalFilter} to a
-     * {@link PhoenixFilter}.
-     */
-    private static class PhoenixFilterRule extends PhoenixConverterRule {
-        private static final PhoenixFilterRule INSTANCE = new PhoenixFilterRule();
-
-        private PhoenixFilterRule() {
-            super(LogicalFilter.class, Convention.NONE, PhoenixRel.CONVENTION,
-                "PhoenixFilterRule");
-        }
-
-        public RelNode convert(RelNode rel) {
-            final LogicalFilter filter = (LogicalFilter) rel;
-            final RelTraitSet traitSet = filter.getTraitSet().replace(out);
-            return new PhoenixFilter(
-                rel.getCluster(),
-                traitSet,
-                convert(filter.getInput(), filter.getInput().getTraitSet().replace(out)),
-                filter.getCondition());
-        }
-    }
-
-    /**
-     * Rule to convert a {@link org.apache.calcite.rel.logical.LogicalProject}
-     * to a {@link PhoenixProject}.
-     */
-    private static class PhoenixProjectRule extends PhoenixConverterRule {
-        private static final PhoenixProjectRule INSTANCE = new PhoenixProjectRule();
-
-        private PhoenixProjectRule() {
-            super(LogicalProject.class, Convention.NONE, PhoenixRel.CONVENTION,
-                "PhoenixProjectRule");
-        }
-
-        public RelNode convert(RelNode rel) {
-            final LogicalProject project = (LogicalProject) rel;
-            final RelTraitSet traitSet = project.getTraitSet().replace(out);
-            return new PhoenixClientProject(project.getCluster(), traitSet,
-                convert(project.getInput(), project.getInput().getTraitSet().replace(out)), project.getProjects(),
-                project.getRowType());
-        }
-    }
-
-    /**
-     * Rule to convert a {@link org.apache.calcite.rel.logical.LogicalAggregate}
-     * to an {@link PhoenixAggregate}.
-     */
-    private static class PhoenixAggregateRule extends PhoenixConverterRule {
-        public static final RelOptRule INSTANCE = new PhoenixAggregateRule();
-
-        private PhoenixAggregateRule() {
-            super(LogicalAggregate.class, Convention.NONE, PhoenixRel.CONVENTION,
-                "PhoenixAggregateRule");
-        }
-
-        public RelNode convert(RelNode rel) {
-            final LogicalAggregate agg = (LogicalAggregate) rel;
-            final RelTraitSet traitSet =
-                agg.getTraitSet().replace(out);
-            return new PhoenixClientAggregate(
-                    rel.getCluster(),
-                    traitSet,
-                    convert(agg.getInput(), agg.getInput().getTraitSet().replace(out)),
-                    agg.indicator,
-                    agg.getGroupSet(),
-                    agg.getGroupSets(),
-                    agg.getAggCallList());
-        }
-    }
-
-    /**
-     * Rule to convert a {@link org.apache.calcite.rel.core.Union} to a
-     * {@link PhoenixUnion}.
-     */
-    private static class PhoenixUnionRule extends PhoenixConverterRule {
-        public static final PhoenixUnionRule INSTANCE = new PhoenixUnionRule();
-
-        private PhoenixUnionRule() {
-            super(LogicalUnion.class, Convention.NONE, PhoenixRel.CONVENTION,
-                "PhoenixUnionRule");
-        }
-
-        public RelNode convert(RelNode rel) {
-            final LogicalUnion union = (LogicalUnion) rel;
-            final RelTraitSet traitSet = union.getTraitSet().replace(out);
-            return new PhoenixUnion(rel.getCluster(), traitSet, convertList(union.getInputs(), out),
-                union.all);
-        }
-    }
-
-    /**
-     * Rule to convert a {@link org.apache.calcite.rel.core.Sort} to a
-     * {@link PhoenixSort}.
-     */
-    private static class PhoenixJoinRule extends PhoenixConverterRule {
-        public static final PhoenixJoinRule INSTANCE = new PhoenixJoinRule();
-
-        private PhoenixJoinRule() {
-            super(LogicalJoin.class, Convention.NONE, PhoenixRel.CONVENTION,
-                "PhoenixJoinRule");
-        }
-
-        public RelNode convert(RelNode rel) {
-            final LogicalJoin join = (LogicalJoin) rel;
-            final RelTraitSet traitSet =
-                join.getTraitSet().replace(out);
-            return new PhoenixClientJoin(rel.getCluster(), traitSet,
-                convert(join.getLeft(), join.getLeft().getTraitSet().replace(out)),
-                convert(join.getRight(), join.getRight().getTraitSet().replace(out)),
-                join.getCondition(),
-                join.getJoinType(),
-                join.getVariablesStopped());
-        }
-    }
-
-    /**
-     * Rule to convert an {@link org.apache.calcite.rel.logical.LogicalIntersect}
-     * to an {@link PhoenixIntersectRel}.
-     o/
-     private static class PhoenixIntersectRule
-     extends PhoenixConverterRule {
-     private PhoenixIntersectRule(PhoenixConvention out) {
-     super(
-     LogicalIntersect.class,
-     Convention.NONE,
-     out,
-     "PhoenixIntersectRule");
-     }
-
-     public RelNode convert(RelNode rel) {
-     final LogicalIntersect intersect = (LogicalIntersect) rel;
-     if (intersect.all) {
-     return null; // INTERSECT ALL not implemented
-     }
-     final RelTraitSet traitSet =
-     intersect.getTraitSet().replace(out);
-     return new PhoenixIntersectRel(
-     rel.getCluster(),
-     traitSet,
-     convertList(intersect.getInputs(), traitSet),
-     intersect.all);
-     }
-     }
-
-     public static class PhoenixIntersectRel
-     extends Intersect
-     implements PhoenixRel {
-     public PhoenixIntersectRel(
-     RelOptCluster cluster,
-     RelTraitSet traitSet,
-     List<RelNode> inputs,
-     boolean all) {
-     super(cluster, traitSet, inputs, all);
-     assert !all;
-     }
-
-     public PhoenixIntersectRel copy(
-     RelTraitSet traitSet, List<RelNode> inputs, boolean all) {
-     return new PhoenixIntersectRel(getCluster(), traitSet, inputs, all);
-     }
-
-     public SqlString implement(PhoenixImplementor implementor) {
-     return setOpSql(this, implementor, " intersect ");
-     }
-     }
-
-     /**
-     * Rule to convert an {@link org.apache.calcite.rel.logical.LogicalMinus}
-     * to an {@link PhoenixMinusRel}.
-     o/
-     private static class PhoenixMinusRule
-     extends PhoenixConverterRule {
-     private PhoenixMinusRule(PhoenixConvention out) {
-     super(
-     LogicalMinus.class,
-     Convention.NONE,
-     out,
-     "PhoenixMinusRule");
-     }
-
-     public RelNode convert(RelNode rel) {
-     final LogicalMinus minus = (LogicalMinus) rel;
-     if (minus.all) {
-     return null; // EXCEPT ALL not implemented
-     }
-     final RelTraitSet traitSet =
-     rel.getTraitSet().replace(out);
-     return new PhoenixMinusRel(
-     rel.getCluster(),
-     traitSet,
-     convertList(minus.getInputs(), traitSet),
-     minus.all);
-     }
-     }
-
-     public static class PhoenixMinusRel
-     extends Minus
-     implements PhoenixRel {
-     public PhoenixMinusRel(
-     RelOptCluster cluster,
-     RelTraitSet traitSet,
-     List<RelNode> inputs,
-     boolean all) {
-     super(cluster, traitSet, inputs, all);
-     assert !all;
-     }
-
-     public PhoenixMinusRel copy(
-     RelTraitSet traitSet, List<RelNode> inputs, boolean all) {
-     return new PhoenixMinusRel(getCluster(), traitSet, inputs, all);
-     }
-
-     public SqlString implement(PhoenixImplementor implementor) {
-     return setOpSql(this, implementor, " minus ");
-     }
-     }
-     */
-
-  /*
-  public static class PhoenixValuesRule extends PhoenixConverterRule {
-    private PhoenixValuesRule() {
-      super(Values.class, Convention.NONE, PhoenixRel.CONVENTION, "PhoenixValuesRule");
-    }
-
-    @Override public RelNode convert(RelNode rel) {
-      Values valuesRel = (Values) rel;
-      return new PhoenixValuesRel(
-          valuesRel.getCluster(),
-          valuesRel.getRowType(),
-          valuesRel.getTuples(),
-          valuesRel.getTraitSet().plus(out));
-    }
-  }
-
-  public static class PhoenixValuesRel
-      extends Values
-      implements PhoenixRel {
-    PhoenixValuesRel(
-        RelOptCluster cluster,
-        RelDataType rowType,
-        List<List<RexLiteral>> tuples,
-        RelTraitSet traitSet) {
-      super(cluster, rowType, tuples, traitSet);
-    }
-
-    @Override public RelNode copy(
-        RelTraitSet traitSet, List<RelNode> inputs) {
-      assert inputs.isEmpty();
-      return new PhoenixValuesRel(
-          getCluster(), rowType, tuples, traitSet);
-    }
-
-    public SqlString implement(PhoenixImplementor implementor) {
-      throw new AssertionError(); // TODO:
-    }
-  }
-*/
-
-    /**
-     * Rule to convert a relational expression from
-     * {@link org.apache.phoenix.calcite.PhoenixRel#CONVENTION} to
-     * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention}.
-     */
-    public static class PhoenixToEnumerableConverterRule extends ConverterRule {
-        public static final ConverterRule INSTANCE =
-            new PhoenixToEnumerableConverterRule();
-
-        private PhoenixToEnumerableConverterRule() {
-            super(RelNode.class, PhoenixRel.CONVENTION, EnumerableConvention.INSTANCE,
-                "PhoenixToEnumerableConverterRule");
-        }
-
-        @Override public RelNode convert(RelNode rel) {
-            RelTraitSet newTraitSet = rel.getTraitSet().replace(getOutConvention());
-            return new PhoenixToEnumerableConverter(rel.getCluster(), newTraitSet, rel);
-        }
-    }
-}
-
-// End PhoenixRules.java

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6a8c3762/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTableScan.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTableScan.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTableScan.java
index e86045a..c5db7f1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTableScan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTableScan.java
@@ -17,6 +17,8 @@ import org.apache.calcite.rex.RexNode;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.phoenix.calcite.rules.PhoenixCompactClientSortRule;
+import org.apache.phoenix.calcite.rules.PhoenixFilterScanMergeRule;
+import org.apache.phoenix.calcite.rules.PhoenixConverterRules;
 import org.apache.phoenix.calcite.rules.PhoenixServerAggregateRule;
 import org.apache.phoenix.calcite.rules.PhoenixServerJoinRule;
 import org.apache.phoenix.calcite.rules.PhoenixServerProjectRule;
@@ -51,7 +53,7 @@ import com.google.common.collect.Lists;
 public class PhoenixTableScan extends TableScan implements PhoenixRel {
     public final RexNode filter;
 
-    protected PhoenixTableScan(RelOptCluster cluster, RelTraitSet traits, RelOptTable table, RexNode filter) {
+    public PhoenixTableScan(RelOptCluster cluster, RelTraitSet traits, RelOptTable table, RexNode filter) {
         super(cluster, traits, table);
         this.filter = filter;
     }
@@ -64,7 +66,7 @@ public class PhoenixTableScan extends TableScan implements PhoenixRel {
 
     @Override
     public void register(RelOptPlanner planner) {
-        RelOptRule[] rules = PhoenixRules.RULES;
+        RelOptRule[] rules = PhoenixConverterRules.RULES;
         for (RelOptRule rule : rules) {
             planner.addRule(rule);
         }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6a8c3762/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixToEnumerableConverter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixToEnumerableConverter.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixToEnumerableConverter.java
index 537e748..9c124d4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixToEnumerableConverter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixToEnumerableConverter.java
@@ -31,7 +31,7 @@ import org.apache.phoenix.iterate.ResultIterator;
  * Scan of a Phoenix table.
  */
 public class PhoenixToEnumerableConverter extends ConverterImpl implements EnumerableRel {
-    protected PhoenixToEnumerableConverter(
+    public PhoenixToEnumerableConverter(
         RelOptCluster cluster,
         RelTraitSet traits,
         RelNode input) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6a8c3762/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixUnion.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixUnion.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixUnion.java
index cc76334..bc855fb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixUnion.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixUnion.java
@@ -14,7 +14,7 @@ import org.apache.phoenix.compile.QueryPlan;
  * relational expression in Phoenix.
  */
 public class PhoenixUnion extends Union implements PhoenixRel {
-    protected PhoenixUnion(RelOptCluster cluster, RelTraitSet traits, List<RelNode> inputs, boolean all) {
+    public PhoenixUnion(RelOptCluster cluster, RelTraitSet traits, List<RelNode> inputs, boolean all) {
         super(cluster, traits, inputs, all);
         assert getConvention() == PhoenixRel.CONVENTION;
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6a8c3762/phoenix-core/src/main/java/org/apache/phoenix/calcite/rules/PhoenixConverterRules.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rules/PhoenixConverterRules.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rules/PhoenixConverterRules.java
new file mode 100644
index 0000000..e426637
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rules/PhoenixConverterRules.java
@@ -0,0 +1,365 @@
+package org.apache.phoenix.calcite.rules;
+
+import org.apache.calcite.adapter.enumerable.EnumerableConvention;
+import org.apache.calcite.plan.*;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.convert.ConverterRule;
+import org.apache.calcite.rel.logical.LogicalAggregate;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalJoin;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.logical.LogicalSort;
+import org.apache.calcite.rel.logical.LogicalUnion;
+import org.apache.calcite.util.trace.CalciteTrace;
+import org.apache.phoenix.calcite.PhoenixAggregate;
+import org.apache.phoenix.calcite.PhoenixClientAggregate;
+import org.apache.phoenix.calcite.PhoenixClientJoin;
+import org.apache.phoenix.calcite.PhoenixClientProject;
+import org.apache.phoenix.calcite.PhoenixClientSort;
+import org.apache.phoenix.calcite.PhoenixFilter;
+import org.apache.phoenix.calcite.PhoenixProject;
+import org.apache.phoenix.calcite.PhoenixRel;
+import org.apache.phoenix.calcite.PhoenixSort;
+import org.apache.phoenix.calcite.PhoenixToEnumerableConverter;
+import org.apache.phoenix.calcite.PhoenixUnion;
+
+import java.util.logging.Logger;
+
+/**
+ * Rules and relational operators for
+ * {@link PhoenixRel#CONVENTION PHOENIX}
+ * calling convention.
+ */
+public class PhoenixConverterRules {
+    private PhoenixConverterRules() {}
+
+    protected static final Logger LOGGER = CalciteTrace.getPlannerTracer();
+
+    public static final RelOptRule[] RULES = {
+        PhoenixToEnumerableConverterRule.INSTANCE,
+        PhoenixSortRule.INSTANCE,
+        PhoenixFilterRule.INSTANCE,
+        PhoenixProjectRule.INSTANCE,
+        PhoenixAggregateRule.INSTANCE,
+        PhoenixUnionRule.INSTANCE,
+        PhoenixJoinRule.INSTANCE,
+    };
+
+    /** Base class for planner rules that convert a relational expression to
+     * Phoenix calling convention. */
+    abstract static class PhoenixConverterRule extends ConverterRule {
+        protected final Convention out;
+        public PhoenixConverterRule(
+            Class<? extends RelNode> clazz,
+            RelTrait in,
+            Convention out,
+            String description) {
+            super(clazz, in, out, description);
+            this.out = out;
+        }
+    }
+
+    /**
+     * Rule to convert a {@link org.apache.calcite.rel.core.Sort} to a
+     * {@link PhoenixSort}.
+     */
+    private static class PhoenixSortRule extends PhoenixConverterRule {
+        public static final PhoenixSortRule INSTANCE = new PhoenixSortRule();
+
+        private PhoenixSortRule() {
+            super(LogicalSort.class, Convention.NONE, PhoenixRel.CONVENTION,
+                "PhoenixSortRule");
+        }
+
+        public RelNode convert(RelNode rel) {
+            final LogicalSort sort = (LogicalSort) rel;
+            final RelTraitSet traitSet =
+                sort.getTraitSet().replace(out)
+                    .replace(sort.getCollation());
+            return new PhoenixClientSort(rel.getCluster(), traitSet,
+                convert(sort.getInput(), sort.getInput().getTraitSet().replace(out)),
+                sort.getCollation(), sort.offset, sort.fetch);
+        }
+    }
+
+    /**
+     * Rule to convert a {@link org.apache.calcite.rel.logical.LogicalFilter} to a
+     * {@link PhoenixFilter}.
+     */
+    private static class PhoenixFilterRule extends PhoenixConverterRule {
+        private static final PhoenixFilterRule INSTANCE = new PhoenixFilterRule();
+
+        private PhoenixFilterRule() {
+            super(LogicalFilter.class, Convention.NONE, PhoenixRel.CONVENTION,
+                "PhoenixFilterRule");
+        }
+
+        public RelNode convert(RelNode rel) {
+            final LogicalFilter filter = (LogicalFilter) rel;
+            final RelTraitSet traitSet = filter.getTraitSet().replace(out);
+            return new PhoenixFilter(
+                rel.getCluster(),
+                traitSet,
+                convert(filter.getInput(), filter.getInput().getTraitSet().replace(out)),
+                filter.getCondition());
+        }
+    }
+
+    /**
+     * Rule to convert a {@link org.apache.calcite.rel.logical.LogicalProject}
+     * to a {@link PhoenixProject}.
+     */
+    private static class PhoenixProjectRule extends PhoenixConverterRule {
+        private static final PhoenixProjectRule INSTANCE = new PhoenixProjectRule();
+
+        private PhoenixProjectRule() {
+            super(LogicalProject.class, Convention.NONE, PhoenixRel.CONVENTION,
+                "PhoenixProjectRule");
+        }
+
+        public RelNode convert(RelNode rel) {
+            final LogicalProject project = (LogicalProject) rel;
+            final RelTraitSet traitSet = project.getTraitSet().replace(out);
+            return new PhoenixClientProject(project.getCluster(), traitSet,
+                convert(project.getInput(), project.getInput().getTraitSet().replace(out)), project.getProjects(),
+                project.getRowType());
+        }
+    }
+
+    /**
+     * Rule to convert a {@link org.apache.calcite.rel.logical.LogicalAggregate}
+     * to an {@link PhoenixAggregate}.
+     */
+    private static class PhoenixAggregateRule extends PhoenixConverterRule {
+        public static final RelOptRule INSTANCE = new PhoenixAggregateRule();
+
+        private PhoenixAggregateRule() {
+            super(LogicalAggregate.class, Convention.NONE, PhoenixRel.CONVENTION,
+                "PhoenixAggregateRule");
+        }
+
+        public RelNode convert(RelNode rel) {
+            final LogicalAggregate agg = (LogicalAggregate) rel;
+            final RelTraitSet traitSet =
+                agg.getTraitSet().replace(out);
+            return new PhoenixClientAggregate(
+                    rel.getCluster(),
+                    traitSet,
+                    convert(agg.getInput(), agg.getInput().getTraitSet().replace(out)),
+                    agg.indicator,
+                    agg.getGroupSet(),
+                    agg.getGroupSets(),
+                    agg.getAggCallList());
+        }
+    }
+
+    /**
+     * Rule to convert a {@link org.apache.calcite.rel.core.Union} to a
+     * {@link PhoenixUnion}.
+     */
+    private static class PhoenixUnionRule extends PhoenixConverterRule {
+        public static final PhoenixUnionRule INSTANCE = new PhoenixUnionRule();
+
+        private PhoenixUnionRule() {
+            super(LogicalUnion.class, Convention.NONE, PhoenixRel.CONVENTION,
+                "PhoenixUnionRule");
+        }
+
+        public RelNode convert(RelNode rel) {
+            final LogicalUnion union = (LogicalUnion) rel;
+            final RelTraitSet traitSet = union.getTraitSet().replace(out);
+            return new PhoenixUnion(rel.getCluster(), traitSet, convertList(union.getInputs(), out),
+                union.all);
+        }
+    }
+
+    /**
+     * Rule to convert a {@link org.apache.calcite.rel.core.Sort} to a
+     * {@link PhoenixSort}.
+     */
+    private static class PhoenixJoinRule extends PhoenixConverterRule {
+        public static final PhoenixJoinRule INSTANCE = new PhoenixJoinRule();
+
+        private PhoenixJoinRule() {
+            super(LogicalJoin.class, Convention.NONE, PhoenixRel.CONVENTION,
+                "PhoenixJoinRule");
+        }
+
+        public RelNode convert(RelNode rel) {
+            final LogicalJoin join = (LogicalJoin) rel;
+            final RelTraitSet traitSet =
+                join.getTraitSet().replace(out);
+            return new PhoenixClientJoin(rel.getCluster(), traitSet,
+                convert(join.getLeft(), join.getLeft().getTraitSet().replace(out)),
+                convert(join.getRight(), join.getRight().getTraitSet().replace(out)),
+                join.getCondition(),
+                join.getJoinType(),
+                join.getVariablesStopped());
+        }
+    }
+
+    /**
+     * Rule to convert an {@link org.apache.calcite.rel.logical.LogicalIntersect}
+     * to an {@link PhoenixIntersectRel}.
+     o/
+     private static class PhoenixIntersectRule
+     extends PhoenixConverterRule {
+     private PhoenixIntersectRule(PhoenixConvention out) {
+     super(
+     LogicalIntersect.class,
+     Convention.NONE,
+     out,
+     "PhoenixIntersectRule");
+     }
+
+     public RelNode convert(RelNode rel) {
+     final LogicalIntersect intersect = (LogicalIntersect) rel;
+     if (intersect.all) {
+     return null; // INTERSECT ALL not implemented
+     }
+     final RelTraitSet traitSet =
+     intersect.getTraitSet().replace(out);
+     return new PhoenixIntersectRel(
+     rel.getCluster(),
+     traitSet,
+     convertList(intersect.getInputs(), traitSet),
+     intersect.all);
+     }
+     }
+
+     public static class PhoenixIntersectRel
+     extends Intersect
+     implements PhoenixRel {
+     public PhoenixIntersectRel(
+     RelOptCluster cluster,
+     RelTraitSet traitSet,
+     List<RelNode> inputs,
+     boolean all) {
+     super(cluster, traitSet, inputs, all);
+     assert !all;
+     }
+
+     public PhoenixIntersectRel copy(
+     RelTraitSet traitSet, List<RelNode> inputs, boolean all) {
+     return new PhoenixIntersectRel(getCluster(), traitSet, inputs, all);
+     }
+
+     public SqlString implement(PhoenixImplementor implementor) {
+     return setOpSql(this, implementor, " intersect ");
+     }
+     }
+
+     /**
+     * Rule to convert an {@link org.apache.calcite.rel.logical.LogicalMinus}
+     * to an {@link PhoenixMinusRel}.
+     o/
+     private static class PhoenixMinusRule
+     extends PhoenixConverterRule {
+     private PhoenixMinusRule(PhoenixConvention out) {
+     super(
+     LogicalMinus.class,
+     Convention.NONE,
+     out,
+     "PhoenixMinusRule");
+     }
+
+     public RelNode convert(RelNode rel) {
+     final LogicalMinus minus = (LogicalMinus) rel;
+     if (minus.all) {
+     return null; // EXCEPT ALL not implemented
+     }
+     final RelTraitSet traitSet =
+     rel.getTraitSet().replace(out);
+     return new PhoenixMinusRel(
+     rel.getCluster(),
+     traitSet,
+     convertList(minus.getInputs(), traitSet),
+     minus.all);
+     }
+     }
+
+     public static class PhoenixMinusRel
+     extends Minus
+     implements PhoenixRel {
+     public PhoenixMinusRel(
+     RelOptCluster cluster,
+     RelTraitSet traitSet,
+     List<RelNode> inputs,
+     boolean all) {
+     super(cluster, traitSet, inputs, all);
+     assert !all;
+     }
+
+     public PhoenixMinusRel copy(
+     RelTraitSet traitSet, List<RelNode> inputs, boolean all) {
+     return new PhoenixMinusRel(getCluster(), traitSet, inputs, all);
+     }
+
+     public SqlString implement(PhoenixImplementor implementor) {
+     return setOpSql(this, implementor, " minus ");
+     }
+     }
+     */
+
+  /*
+  public static class PhoenixValuesRule extends PhoenixConverterRule {
+    private PhoenixValuesRule() {
+      super(Values.class, Convention.NONE, PhoenixRel.CONVENTION, "PhoenixValuesRule");
+    }
+
+    @Override public RelNode convert(RelNode rel) {
+      Values valuesRel = (Values) rel;
+      return new PhoenixValuesRel(
+          valuesRel.getCluster(),
+          valuesRel.getRowType(),
+          valuesRel.getTuples(),
+          valuesRel.getTraitSet().plus(out));
+    }
+  }
+
+  public static class PhoenixValuesRel
+      extends Values
+      implements PhoenixRel {
+    PhoenixValuesRel(
+        RelOptCluster cluster,
+        RelDataType rowType,
+        List<List<RexLiteral>> tuples,
+        RelTraitSet traitSet) {
+      super(cluster, rowType, tuples, traitSet);
+    }
+
+    @Override public RelNode copy(
+        RelTraitSet traitSet, List<RelNode> inputs) {
+      assert inputs.isEmpty();
+      return new PhoenixValuesRel(
+          getCluster(), rowType, tuples, traitSet);
+    }
+
+    public SqlString implement(PhoenixImplementor implementor) {
+      throw new AssertionError(); // TODO:
+    }
+  }
+*/
+
+    /**
+     * Rule to convert a relational expression from
+     * {@link org.apache.phoenix.calcite.PhoenixRel#CONVENTION} to
+     * {@link org.apache.calcite.adapter.enumerable.EnumerableConvention}.
+     */
+    public static class PhoenixToEnumerableConverterRule extends ConverterRule {
+        public static final ConverterRule INSTANCE =
+            new PhoenixToEnumerableConverterRule();
+
+        private PhoenixToEnumerableConverterRule() {
+            super(RelNode.class, PhoenixRel.CONVENTION, EnumerableConvention.INSTANCE,
+                "PhoenixToEnumerableConverterRule");
+        }
+
+        @Override public RelNode convert(RelNode rel) {
+            RelTraitSet newTraitSet = rel.getTraitSet().replace(getOutConvention());
+            return new PhoenixToEnumerableConverter(rel.getCluster(), newTraitSet, rel);
+        }
+    }
+}
+
+// End PhoenixRules.java

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6a8c3762/phoenix-core/src/main/java/org/apache/phoenix/calcite/rules/PhoenixFilterScanMergeRule.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rules/PhoenixFilterScanMergeRule.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rules/PhoenixFilterScanMergeRule.java
new file mode 100644
index 0000000..a456c7a
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rules/PhoenixFilterScanMergeRule.java
@@ -0,0 +1,38 @@
+package org.apache.phoenix.calcite.rules;
+
+import com.google.common.base.Predicate;
+
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.phoenix.calcite.PhoenixTableScan;
+
+public class PhoenixFilterScanMergeRule extends RelOptRule {
+
+    /** Predicate that returns true if a table scan has no filter. */
+    private static final Predicate<PhoenixTableScan> NO_FILTER =
+        new Predicate<PhoenixTableScan>() {
+            @Override
+            public boolean apply(PhoenixTableScan phoenixTableScan) {
+                return phoenixTableScan.filter == null;
+            }
+        };
+
+    public static final PhoenixFilterScanMergeRule INSTANCE = new PhoenixFilterScanMergeRule();
+
+    private PhoenixFilterScanMergeRule() {
+        super(
+            operand(Filter.class,
+                operand(PhoenixTableScan.class, null, NO_FILTER, any())));
+    }
+
+    @Override
+    public void onMatch(RelOptRuleCall call) {
+        Filter filter = call.rel(0);
+        PhoenixTableScan scan = call.rel(1);
+        assert scan.filter == null : "predicate should have ensured no filter";
+        call.transformTo(new PhoenixTableScan(scan.getCluster(),
+                scan.getTraitSet(), scan.getTable(),
+                filter.getCondition()));
+    }
+}