You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by ts...@apache.org on 2013/01/26 04:00:18 UTC
git commit: reference implementation of limit operator
Updated Branches:
refs/heads/master ce3f1c603 -> f6fcc4c73
reference implementation of limit operator
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/f6fcc4c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/f6fcc4c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/f6fcc4c7
Branch: refs/heads/master
Commit: f6fcc4c7303703ef84256f3a278dbed3e2d91f86
Parents: ce3f1c6
Author: Chris Merrick <ch...@gmail.com>
Authored: Fri Jan 25 18:59:23 2013 -0800
Committer: Jacques Nadeau <ja...@gmail.com>
Committed: Fri Jan 25 18:59:23 2013 -0800
----------------------------------------------------------------------
.../drill/common/logical/data/LogicalOperator.java | 2 +-
.../org/apache/drill/exec/ref/rops/LimitROP.java | 87 +++++++++++++++
.../exec/ref/src/test/resources/simple_plan.json | 5 +
3 files changed, 93 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/f6fcc4c7/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/data/LogicalOperator.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/data/LogicalOperator.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/data/LogicalOperator.java
index 1a7d9c6..3a890ce 100644
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/data/LogicalOperator.java
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/data/LogicalOperator.java
@@ -33,7 +33,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property="op")
public interface LogicalOperator extends Iterable<LogicalOperator>{
- public static final Class<?>[] SUB_TYPES = {Write.class, Aggregate.class, Group.class, Filter.class, Flatten.class, Join.class, Order.class, Project.class, Scan.class, Sequence.class, Transform.class, Union.class, WindowFrame.class};
+ public static final Class<?>[] SUB_TYPES = {Write.class, Aggregate.class, Group.class, Filter.class, Flatten.class, Join.class, Order.class, Limit.class, Project.class, Scan.class, Sequence.class, Transform.class, Union.class, WindowFrame.class};
public void accept(OpVisitor visitor);
public void registerAsSubscriber(LogicalOperator operator);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/f6fcc4c7/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/LimitROP.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/LimitROP.java b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/LimitROP.java
new file mode 100644
index 0000000..4a29f94
--- /dev/null
+++ b/sandbox/prototype/exec/ref/src/main/java/org/apache/drill/exec/ref/rops/LimitROP.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.drill.exec.ref.rops;
+
+import org.apache.drill.common.logical.data.Limit;
+import org.apache.drill.exec.ref.RecordIterator;
+import org.apache.drill.exec.ref.RecordPointer;
+import org.apache.drill.exec.ref.eval.EvaluatorFactory;
+
+public class LimitROP extends SingleInputROPBase<Limit>{
+
+ private LimitIterator iter;
+ private int first;
+ private int last;
+
+ public LimitROP(Limit config) {
+ super(config);
+ }
+
+ @Override
+ protected void setupEvals(EvaluatorFactory builder) {
+ first = config.getFirst();
+ last = config.getLast();
+ }
+
+ @Override
+ public void setInput(RecordIterator incoming) {
+ iter = new LimitIterator(incoming);
+ }
+
+ @Override
+ public RecordIterator getIteratorInternal() {
+ return iter;
+ }
+
+ private class LimitIterator implements RecordIterator{
+ RecordIterator incoming;
+ int currentIndex = 0;
+
+ public LimitIterator(RecordIterator incoming) {
+ this.incoming = incoming;
+ }
+
+ @Override
+ public NextOutcome next() {
+ NextOutcome r;
+ while(true){
+ r = incoming.next();
+ currentIndex++;
+ if (currentIndex > first && currentIndex <= last)
+ return r;
+
+ if (currentIndex > last)
+ return NextOutcome.NONE_LEFT;
+ }
+ }
+
+ @Override
+ public ROP getParent() {
+ return LimitROP.this;
+ }
+
+ @Override
+ public RecordPointer getRecordPointer() {
+ return record;
+ }
+
+
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/f6fcc4c7/sandbox/prototype/exec/ref/src/test/resources/simple_plan.json
----------------------------------------------------------------------
diff --git a/sandbox/prototype/exec/ref/src/test/resources/simple_plan.json b/sandbox/prototype/exec/ref/src/test/resources/simple_plan.json
index f1cea95..936c094 100644
--- a/sandbox/prototype/exec/ref/src/test/resources/simple_plan.json
+++ b/sandbox/prototype/exec/ref/src/test/resources/simple_plan.json
@@ -65,6 +65,11 @@
{ ref: "output", expr: "donuts" }
]
},
+ {
+ op: "limit",
+ first: 0,
+ last: 2
+ },
{
op: "write",
memo: "output sink",