Return-Path: X-Original-To: apmail-tajo-commits-archive@minotaur.apache.org Delivered-To: apmail-tajo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 413BB18582 for ; Thu, 25 Jun 2015 08:08:54 +0000 (UTC) Received: (qmail 35720 invoked by uid 500); 25 Jun 2015 08:08:54 -0000 Delivered-To: apmail-tajo-commits-archive@tajo.apache.org Received: (qmail 35678 invoked by uid 500); 25 Jun 2015 08:08:54 -0000 Mailing-List: contact commits-help@tajo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tajo.apache.org Delivered-To: mailing list commits@tajo.apache.org Received: (qmail 35282 invoked by uid 99); 25 Jun 2015 08:08:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Jun 2015 08:08:54 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EA875E365F; Thu, 25 Jun 2015 08:08:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jihoonson@apache.org To: commits@tajo.apache.org Date: Thu, 25 Jun 2015 08:09:06 -0000 Message-Id: <17c51c6b9a3542fdaf636a2a95724032@git.apache.org> In-Reply-To: <14cfb94ec5294d4aa07f8b91676bb23e@git.apache.org> References: <14cfb94ec5294d4aa07f8b91676bb23e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [14/15] tajo git commit: TAJO-1659: Simplify scan iteration in SeqScan. 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 Authored: Wed Jun 24 20:51:07 2015 -0700 Committer: Hyunsik Choi 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