tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject [14/15] tajo git commit: TAJO-1659: Simplify scan iteration in SeqScan.
Date Thu, 25 Jun 2015 08:09:06 GMT
TAJO-1659: Simplify scan iteration in SeqScan.


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

Branch: refs/heads/index_support
Commit: 2ec307d621828cc18627ef7bd98e9c3c6774c5af
Parents: 03bf843
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Wed Jun 24 20:51:07 2015 -0700
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Wed Jun 24 20:51:07 2015 -0700

----------------------------------------------------------------------
 CHANGES                                         |  2 +
 .../planner/physical/FilterScanIterator.java    | 56 ++++++++++++++++++++
 .../planner/physical/FullScanIterator.java      | 47 ++++++++++++++++
 .../engine/planner/physical/ScanIterator.java   | 33 ++++++++++++
 .../engine/planner/physical/SeqScanExec.java    | 34 ++++++------
 5 files changed, 153 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/2ec307d6/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 75ffd39..425ac5d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -27,6 +27,8 @@ Release 0.11.0 - unreleased
 
   IMPROVEMENT
 
+    TAJO-1659: Simplify scan iteration in SeqScan. (hyunsik)
+
     TAJO-751: JDBC driver should support cancel() method.
     (Contributed by navis, Committed by jihoon)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/2ec307d6/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/FilterScanIterator.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/FilterScanIterator.java
b/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/FilterScanIterator.java
new file mode 100644
index 0000000..fd440d7
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/FilterScanIterator.java
@@ -0,0 +1,56 @@
+/*
+ * 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.tajo.engine.planner.physical;
+
+import org.apache.tajo.plan.expr.EvalNode;
+import org.apache.tajo.storage.Scanner;
+import org.apache.tajo.storage.Tuple;
+
+import java.io.IOException;
+
+/**
+ * This iterator involves filter operation.
+ */
+public class FilterScanIterator implements ScanIterator {
+  private final Scanner scanner;
+  private final EvalNode filter;
+  private Tuple currentTuple;
+
+  public FilterScanIterator(Scanner scanner, EvalNode filter) {
+    this.scanner = scanner;
+    this.filter = filter;
+  }
+
+  @Override
+  public boolean hasNext() throws IOException {
+    while((currentTuple = scanner.next()) != null) {
+      if (filter.eval(currentTuple).isTrue()) {
+        return true;
+      }
+    }
+
+    return false;
+  }
+
+  @Override
+  public Tuple next() {
+    return currentTuple;
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/tajo/blob/2ec307d6/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/FullScanIterator.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/FullScanIterator.java
b/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/FullScanIterator.java
new file mode 100644
index 0000000..a32f33d
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/FullScanIterator.java
@@ -0,0 +1,47 @@
+/*
+ * 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.tajo.engine.planner.physical;
+
+import org.apache.tajo.storage.Scanner;
+import org.apache.tajo.storage.Tuple;
+
+import java.io.IOException;
+
+/**
+ * This scan iterator performs full scan.
+ */
+public class FullScanIterator implements ScanIterator {
+  private final Scanner scanner;
+  private Tuple currentTuple;
+
+  public FullScanIterator(Scanner scanner) {
+    this.scanner = scanner;
+  }
+
+  @Override
+  public boolean hasNext() throws IOException {
+    return (currentTuple = scanner.next()) != null;
+  }
+
+  @Override
+  public Tuple next() {
+    return currentTuple;
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/tajo/blob/2ec307d6/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/ScanIterator.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/ScanIterator.java
b/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/ScanIterator.java
new file mode 100644
index 0000000..813d8d0
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/ScanIterator.java
@@ -0,0 +1,33 @@
+/*
+ * 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.tajo.engine.planner.physical;
+
+import org.apache.tajo.storage.Tuple;
+
+import java.io.IOException;
+
+/**
+ * This is a scan iterator implementation for various scan types.
+ * It has the same semantic to java.util.Iterator except throwing IOException.
+ */
+public interface ScanIterator {
+  boolean hasNext() throws IOException;
+
+  Tuple next() throws IOException;
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/2ec307d6/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/SeqScanExec.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/SeqScanExec.java
b/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/SeqScanExec.java
index 599f160..79e0a5d 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/SeqScanExec.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/physical/SeqScanExec.java
@@ -62,6 +62,9 @@ public class SeqScanExec extends ScanExec {
 
   private TableStats inputStats;
 
+  // scanner iterator with filter or without filter
+  private ScanIterator scanIt;
+
   public SeqScanExec(TaskAttemptContext context, ScanNode plan,
                      CatalogProtos.FragmentProto [] fragments) throws IOException {
     super(context, plan.getInSchema(), plan.getOutSchema());
@@ -173,6 +176,10 @@ public class SeqScanExec extends ScanExec {
       } else {
         qual.bind(context.getEvalContext(), inSchema);
       }
+
+      scanIt = new FilterScanIterator(scanner, qual);
+    } else {
+      scanIt = new FullScanIterator(scanner);
     }
   }
 
@@ -226,26 +233,15 @@ public class SeqScanExec extends ScanExec {
       return null;
     }
 
-    Tuple tuple;
-    Tuple outTuple = new VTuple(outColumnNum);
-
-    if (!plan.hasQual()) {
-      if ((tuple = scanner.next()) != null) {
-        projector.eval(tuple, outTuple);
-        outTuple.setOffset(tuple.getOffset());
-        return outTuple;
-      } else {
-        return null;
-      }
-    } else {
-      while ((tuple = scanner.next()) != null) {
-        if (qual.eval(tuple).isTrue()) {
-          projector.eval(tuple, outTuple);
-          return outTuple;
-        }
-      }
-      return null;
+    while(scanIt.hasNext()) {
+      Tuple outTuple = new VTuple(outColumnNum);
+      Tuple t = scanIt.next();
+      projector.eval(t, outTuple);
+      outTuple.setOffset(t.getOffset());
+      return outTuple;
     }
+
+    return null;
   }
 
   @Override


Mime
View raw message