Repository: phoenix
Updated Branches:
  refs/heads/calcite 76e92a961 -> b13e9f22e


PHOENIX-2133 Implement PhoenixValues rel in Phoenix - Calcite Integration


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

Branch: refs/heads/calcite
Commit: b13e9f22e3aec4c530ba7cdf6d52bfe6ab23ddaf
Parents: 76e92a9
Author: maryannxue <[email protected]>
Authored: Mon Jul 20 20:35:17 2015 -0400
Committer: maryannxue <[email protected]>
Committed: Mon Jul 20 20:35:17 2015 -0400

----------------------------------------------------------------------
 .../apache/phoenix/calcite/CalciteUtils.java    |  10 +-
 .../apache/phoenix/compile/QueryCompiler.java   |   4 +-
 .../apache/phoenix/execute/BaseQueryPlan.java   |   8 +-
 .../phoenix/execute/EmptyTableQueryPlan.java    |  96 -----------------
 .../LiteralResultIterationQueryPlan.java        | 105 +++++++++++++++++++
 5 files changed, 119 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b13e9f22/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
index 6e1f07d..99b8ba9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
@@ -462,14 +462,20 @@ public class CalciteUtils {
         });
                EXPRESSION_MAP.put(SqlKind.LITERAL, new ExpressionFactory() {
 
-                       @Override
+                       @SuppressWarnings("rawtypes")
+            @Override
                        public Expression newExpression(RexNode node, 
Implementor implementor) {
                                RexLiteral lit = (RexLiteral) node;
+                PDataType targetType = 
sqlTypeNameToPDataType(node.getType().getSqlTypeName());
                                Object o = lit.getValue();
                                if (o instanceof NlsString) {
                                    o = ((NlsString) o).getValue();
                                }
-                               return LiteralExpression.newConstant(o);
+                               try {
+                    return LiteralExpression.newConstant(o, targetType);
+                } catch (SQLException e) {
+                    throw new RuntimeException(e);
+                }
                        }
                        
                });

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b13e9f22/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
index ce3343e..a516bf2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java
@@ -35,7 +35,7 @@ import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
 import org.apache.phoenix.execute.AggregatePlan;
 import org.apache.phoenix.execute.ClientAggregatePlan;
 import org.apache.phoenix.execute.ClientScanPlan;
-import org.apache.phoenix.execute.EmptyTableQueryPlan;
+import org.apache.phoenix.execute.LiteralResultIterationQueryPlan;
 import org.apache.phoenix.execute.HashJoinPlan;
 import org.apache.phoenix.execute.HashJoinPlan.HashSubPlan;
 import org.apache.phoenix.execute.HashJoinPlan.WhereClauseSubPlan;
@@ -557,7 +557,7 @@ public class QueryCompiler {
         if (plan == null) {
             ParallelIteratorFactory parallelIteratorFactory = asSubquery ? 
null : this.parallelIteratorFactory;
             plan = select.getFrom() == null ?
-                      new EmptyTableQueryPlan(context, select, tableRef, 
projector, limit, orderBy, parallelIteratorFactory)
+                      new LiteralResultIterationQueryPlan(context, select, 
tableRef, projector, limit, orderBy, parallelIteratorFactory)
                     : (select.isAggregate() || select.isDistinct() ?
                               new AggregatePlan(context, select, tableRef, 
projector, limit, orderBy, parallelIteratorFactory, groupBy, having)
                             : new ScanPlan(context, select, tableRef, 
projector, limit, orderBy, parallelIteratorFactory, allowPageFilter));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b13e9f22/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
index 11da1c9..ebae0bf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
@@ -162,14 +162,14 @@ public abstract class BaseQueryPlan implements QueryPlan {
     }
 
     public final ResultIterator iterator(final List<? extends SQLCloseable> 
dependencies, ParallelScanGrouper scanGrouper) throws SQLException {
-        if (context.getScanRanges() == ScanRanges.NOTHING) {
-            return ResultIterator.EMPTY_ITERATOR;
-        }
-        
         if (tableRef == TableRef.EMPTY_TABLE_REF) {
             return newIterator(scanGrouper);
         }
         
+        if (context.getScanRanges() == ScanRanges.NOTHING) {
+            return ResultIterator.EMPTY_ITERATOR;
+        }
+        
         // Set miscellaneous scan attributes. This is the last chance to set 
them before we
         // clone the scan for each parallelized chunk.
         Scan scan = context.getScan();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b13e9f22/phoenix-core/src/main/java/org/apache/phoenix/execute/EmptyTableQueryPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/EmptyTableQueryPlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/EmptyTableQueryPlan.java
deleted file mode 100644
index fd55732..0000000
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/EmptyTableQueryPlan.java
+++ /dev/null
@@ -1,96 +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.phoenix.execute;
-
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.client.Scan;
-import org.apache.phoenix.compile.GroupByCompiler.GroupBy;
-import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
-import org.apache.phoenix.compile.RowProjector;
-import org.apache.phoenix.compile.StatementContext;
-import org.apache.phoenix.iterate.ParallelIteratorFactory;
-import org.apache.phoenix.iterate.ParallelScanGrouper;
-import org.apache.phoenix.iterate.ResultIterator;
-import org.apache.phoenix.iterate.SequenceResultIterator;
-import org.apache.phoenix.parse.FilterableStatement;
-import org.apache.phoenix.query.KeyRange;
-import org.apache.phoenix.schema.TableRef;
-import org.apache.phoenix.schema.tuple.SingleKeyValueTuple;
-import org.apache.phoenix.schema.tuple.Tuple;
-
-public class EmptyTableQueryPlan extends BaseQueryPlan {
-
-    public EmptyTableQueryPlan(StatementContext context, FilterableStatement 
statement, 
-            TableRef tableRef, RowProjector projection, Integer limit, OrderBy 
orderBy,
-            ParallelIteratorFactory parallelIteratorFactory) {
-        super(context, statement, tableRef, projection, 
context.getBindManager().getParameterMetaData(), limit, orderBy, 
GroupBy.EMPTY_GROUP_BY, parallelIteratorFactory);
-    }
-
-    @Override
-    public List<KeyRange> getSplits() {
-        return Collections.emptyList();
-    }
-
-    @Override
-    public List<List<Scan>> getScans() {
-        return Collections.emptyList();
-    }
-
-    @Override
-    public boolean useRoundRobinIterator() throws SQLException {
-        return false;
-    }
-
-    @Override
-    protected ResultIterator newIterator(ParallelScanGrouper scanGrouper)
-            throws SQLException {
-        ResultIterator scanner = new ResultIterator() {
-            private boolean hasNext = true;
-
-            @Override
-            public void close() throws SQLException {
-                this.hasNext = false;
-            }
-
-            @Override
-            public Tuple next() throws SQLException {
-                if (hasNext) {
-                    hasNext = false;
-                    return new SingleKeyValueTuple(KeyValue.LOWESTKEY);
-                }
-                return null;
-            }
-
-            @Override
-            public void explain(List<String> planSteps) {
-            }
-            
-        };
-        
-        if (context.getSequenceManager().getSequenceCount() > 0) {
-            scanner = new SequenceResultIterator(scanner, 
context.getSequenceManager());
-        }
-        
-        return scanner;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b13e9f22/phoenix-core/src/main/java/org/apache/phoenix/execute/LiteralResultIterationQueryPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/LiteralResultIterationQueryPlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/LiteralResultIterationQueryPlan.java
new file mode 100644
index 0000000..ab0341b
--- /dev/null
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/LiteralResultIterationQueryPlan.java
@@ -0,0 +1,105 @@
+/*
+ * 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.phoenix.execute;
+
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.phoenix.compile.GroupByCompiler.GroupBy;
+import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
+import org.apache.phoenix.compile.RowProjector;
+import org.apache.phoenix.compile.StatementContext;
+import org.apache.phoenix.iterate.ParallelIteratorFactory;
+import org.apache.phoenix.iterate.ParallelScanGrouper;
+import org.apache.phoenix.iterate.ResultIterator;
+import org.apache.phoenix.iterate.SequenceResultIterator;
+import org.apache.phoenix.parse.FilterableStatement;
+import org.apache.phoenix.query.KeyRange;
+import org.apache.phoenix.schema.TableRef;
+import org.apache.phoenix.schema.tuple.SingleKeyValueTuple;
+import org.apache.phoenix.schema.tuple.Tuple;
+
+public class LiteralResultIterationQueryPlan extends BaseQueryPlan {
+    protected final Iterator<Tuple> tupleIterator;
+
+    public LiteralResultIterationQueryPlan(StatementContext context, 
+            FilterableStatement statement, TableRef tableRef, RowProjector 
projection, 
+            Integer limit, OrderBy orderBy, ParallelIteratorFactory 
parallelIteratorFactory) {
+        this(Collections.<Tuple> singletonList(new 
SingleKeyValueTuple(KeyValue.LOWESTKEY)).iterator(), 
+                context, statement, tableRef, projection, limit, orderBy, 
parallelIteratorFactory);
+    }
+
+    public LiteralResultIterationQueryPlan(Iterator<Tuple> tupleIterator, 
StatementContext context, 
+            FilterableStatement statement, TableRef tableRef, RowProjector 
projection, 
+            Integer limit, OrderBy orderBy, ParallelIteratorFactory 
parallelIteratorFactory) {
+        super(context, statement, tableRef, projection, context == null ? null 
: context.getBindManager().getParameterMetaData(), limit, orderBy, 
GroupBy.EMPTY_GROUP_BY, parallelIteratorFactory);
+        this.tupleIterator = tupleIterator;
+    }
+
+    @Override
+    public List<KeyRange> getSplits() {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public List<List<Scan>> getScans() {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public boolean useRoundRobinIterator() throws SQLException {
+        return false;
+    }
+
+    @Override
+    protected ResultIterator newIterator(ParallelScanGrouper scanGrouper)
+            throws SQLException {
+        ResultIterator scanner = new ResultIterator() {
+            private boolean closed = false;
+
+            @Override
+            public void close() throws SQLException {
+                this.closed = true;;
+            }
+
+            @Override
+            public Tuple next() throws SQLException {
+                if (!this.closed && tupleIterator.hasNext()) {
+                    return tupleIterator.next();
+                }
+                return null;
+            }
+
+            @Override
+            public void explain(List<String> planSteps) {
+            }
+            
+        };
+        
+        if (context != null && context.getSequenceManager().getSequenceCount() 
> 0) {
+            scanner = new SequenceResultIterator(scanner, 
context.getSequenceManager());
+        }
+        
+        return scanner;
+    }
+
+}

Reply via email to