phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sama...@apache.org
Subject phoenix git commit: Fix test failures due to use of priority queue for merge sort (Ankit Singhal/Samarth Jain)
Date Fri, 13 Nov 2015 18:11:21 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.0 f930e56a8 -> a185340a7


Fix test failures due to use of priority queue for merge sort (Ankit Singhal/Samarth Jain)


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

Branch: refs/heads/4.x-HBase-1.0
Commit: a185340a726551f5ec9f31aa4ad006327bfe668b
Parents: f930e56
Author: Samarth <samarth@apache.org>
Authored: Fri Nov 13 10:11:07 2015 -0800
Committer: Samarth <samarth@apache.org>
Committed: Fri Nov 13 10:11:07 2015 -0800

----------------------------------------------------------------------
 .../iterate/MergeSortResultIterator.java        | 80 +++++++++-----------
 1 file changed, 34 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/a185340a/phoenix-core/src/main/java/org/apache/phoenix/iterate/MergeSortResultIterator.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/iterate/MergeSortResultIterator.java
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/MergeSortResultIterator.java
index 75843eb..e076a40 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/MergeSortResultIterator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/MergeSortResultIterator.java
@@ -34,7 +34,6 @@ import org.apache.phoenix.util.ServerUtil;
 public abstract class MergeSortResultIterator implements PeekingResultIterator {
     protected final ResultIterators resultIterators;
     protected final ImmutableBytesWritable tempPtr = new ImmutableBytesWritable();
-    private List<PeekingResultIterator> iterators;
     private PriorityQueue<MaterializedComparableResultIterator> minHeap;
     private final IteratorComparator itrComparator = new IteratorComparator();
 
@@ -42,34 +41,6 @@ public abstract class MergeSortResultIterator implements PeekingResultIterator
{
         this.resultIterators = iterators;
     }
 
-    private List<PeekingResultIterator> getIterators() throws SQLException {
-        if (iterators == null) {
-            iterators = resultIterators.getIterators();
-        }
-        return iterators;
-    }
-
-    private PriorityQueue<MaterializedComparableResultIterator> getMinHeap() throws
SQLException {
-        if (minHeap == null) {
-            List<PeekingResultIterator> iterators = getIterators();
-            minHeap = new PriorityQueue<MaterializedComparableResultIterator>(iterators.size());
-            for (PeekingResultIterator itr : iterators) {
-                if (itr.peek() == null) {
-                    itr.close();
-                    continue;
-                }
-                minHeap.add(new MaterializedComparableResultIterator(itr, itrComparator));
-            }
-        }
-        return minHeap;
-    }
-
-    private class IteratorComparator implements Comparator<Tuple> {
-        public int compare(Tuple c1, Tuple c2) {
-            return MergeSortResultIterator.this.compare(c1, c2);
-        }
-    }
-
     @Override
     public void close() throws SQLException {
         SQLException toThrow = null;
@@ -81,8 +52,8 @@ public abstract class MergeSortResultIterator implements PeekingResultIterator
{
             toThrow = ServerUtil.parseServerException(e);
         } finally {
             try {
-                if (iterators != null) {
-                    SQLCloseables.closeAll(iterators);
+                if (minHeap != null) {
+                    SQLCloseables.closeAllQuietly(minHeap);
                 }
             } catch (Exception e) {
                 if (toThrow == null) {
@@ -91,36 +62,24 @@ public abstract class MergeSortResultIterator implements PeekingResultIterator
{
                     toThrow.setNextException(ServerUtil.parseServerException(e));
                 }
             } finally {
-                if (toThrow != null) {
-                    throw toThrow;
-                }
+                if (toThrow != null) { throw toThrow; }
             }
         }
     }
 
     abstract protected int compare(Tuple t1, Tuple t2);
 
-    private MaterializedComparableResultIterator minIterator() throws SQLException {
-        PriorityQueue<MaterializedComparableResultIterator> minHeap = getMinHeap();
-        MaterializedComparableResultIterator minIterator = minHeap.peek();
-        return minIterator;
-    }
-
     @Override
     public Tuple peek() throws SQLException {
         MaterializedComparableResultIterator iterator = minIterator();
-        if (iterator == null) {
-            return null;
-        }
+        if (iterator == null) { return null; }
         return iterator.peek();
     }
 
     @Override
     public Tuple next() throws SQLException {
         MaterializedComparableResultIterator iterator = minIterator();
-        if (iterator == null) {
-            return null;
-        }
+        if (iterator == null) { return null; }
         Tuple next = iterator.next();
         minHeap.poll();
         if (iterator.peek() != null) {
@@ -130,4 +89,33 @@ public abstract class MergeSortResultIterator implements PeekingResultIterator
{
         }
         return next;
     }
+
+    private PriorityQueue<MaterializedComparableResultIterator> getMinHeap() throws
SQLException {
+        if (minHeap == null) {
+            List<PeekingResultIterator> iterators = resultIterators.getIterators();
+            minHeap = new PriorityQueue<MaterializedComparableResultIterator>(iterators.size());
+            for (PeekingResultIterator itr : iterators) {
+                if (itr.peek() == null) {
+                    itr.close();
+                    continue;
+                }
+                minHeap.add(new MaterializedComparableResultIterator(itr, itrComparator));
+            }
+        }
+        return minHeap;
+    }
+
+    private class IteratorComparator implements Comparator<Tuple> {
+        @Override
+        public int compare(Tuple c1, Tuple c2) {
+            return MergeSortResultIterator.this.compare(c1, c2);
+        }
+    }
+
+    private MaterializedComparableResultIterator minIterator() throws SQLException {
+        PriorityQueue<MaterializedComparableResultIterator> minHeap = getMinHeap();
+        MaterializedComparableResultIterator minIterator = minHeap.peek();
+        return minIterator;
+    }
+
 }


Mime
View raw message