phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [3/3] phoenix git commit: PHOENIX-1690 IndexOutOfBoundsException during SkipScanFilter interesect
Date Wed, 04 Mar 2015 02:45:22 GMT
PHOENIX-1690 IndexOutOfBoundsException during SkipScanFilter interesect

Conflicts:
	phoenix-core/src/test/java/org/apache/phoenix/filter/SkipScanFilterIntersectTest.java


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

Branch: refs/heads/3.0
Commit: dd22ccd94a33fe987661c6953bbe61a6cf6f9e71
Parents: b467af4
Author: James Taylor <jtaylor@salesforce.com>
Authored: Tue Mar 3 12:07:56 2015 -0800
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Tue Mar 3 18:45:13 2015 -0800

----------------------------------------------------------------------
 .../apache/phoenix/filter/SkipScanFilter.java   |  31 +-
 .../org/apache/phoenix/schema/PTableImpl.java   |   9 +
 .../phoenix/filter/SkipScanBigFilterTest.java   | 728 +++++++++++++++++++
 .../filter/SkipScanFilterIntersectTest.java     |  63 +-
 4 files changed, 829 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/dd22ccd9/phoenix-core/src/main/java/org/apache/phoenix/filter/SkipScanFilter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/filter/SkipScanFilter.java b/phoenix-core/src/main/java/org/apache/phoenix/filter/SkipScanFilter.java
index ba2f180..a8c1243 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/filter/SkipScanFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/filter/SkipScanFilter.java
@@ -179,7 +179,7 @@ public class SkipScanFilter extends FilterBase {
         Arrays.fill(position, 0);
     }
     
-    private boolean intersect(byte[] lowerInclusiveKey, byte[] upperExclusiveKey, List<List<KeyRange>>
newSlots) {
+    private boolean intersect(final byte[] lowerInclusiveKey, final byte[] upperExclusiveKey,
List<List<KeyRange>> newSlots) {
         resetState();
         boolean lowerUnbound = (lowerInclusiveKey.length == 0);
         int startPos = 0;
@@ -246,6 +246,9 @@ public class SkipScanFilter extends FilterBase {
         }
         int[] lowerPosition = Arrays.copyOf(position, position.length);
         // Navigate to the upperExclusiveKey, but not past it
+        // TODO: We're including everything between the lowerPosition and end position, which
is
+        // more than we need. We can optimize this by tracking whether each range in each
slot position
+        // intersects.
         ReturnCode endCode = navigate(upperExclusiveKey, 0, upperExclusiveKey.length, Terminate.AT);
         if (endCode == ReturnCode.INCLUDE) {
             setStartKey();
@@ -270,6 +273,11 @@ public class SkipScanFilter extends FilterBase {
                 position[i] = slots.get(i).size() - 1;
             }
         }
+        int prevRowKeyPos = -1;
+        ImmutableBytesWritable lowerPtr = new ImmutableBytesWritable();
+        ImmutableBytesWritable upperPtr = new ImmutableBytesWritable();
+        schema.iterator(lowerInclusiveKey, lowerPtr);
+        schema.iterator(upperExclusiveKey, upperPtr);
         // Copy inclusive all positions 
         for (int i = 0; i <= lastSlot; i++) {
             List<KeyRange> newRanges = slots.get(i).subList(lowerPosition[i], Math.min(position[i]
+ 1, slots.get(i).size()));
@@ -279,12 +287,33 @@ public class SkipScanFilter extends FilterBase {
             if (newSlots != null) {
                 newSlots.add(newRanges);
             }
+            // Must include all "less-significant" slot values if:
+            // 1) a more-significant slot was incremented
             if (position[i] > lowerPosition[i]) {
                 if (newSlots != null) {
                     newSlots.addAll(slots.subList(i+1, slots.size()));
                 }
                 break;
             }
+            // 2) we're at a slot containing a range and the values differ between the lower
and upper range,
+            //    since less-significant slots may be lower after traversal than where they
started.
+            if (!slots.get(i).get(position[i]).isSingleKey()) {
+                int rowKeyPos = ScanUtil.getRowKeyPosition(slotSpan, i);
+                // Position lowerPtr/upperPtr within lowerInclusiveKey/upperExclusiveKey
at value for slot i
+                // The reposition method will do this incrementally, where we we're initially
have prevRowKeyPos = -1. 
+                schema.reposition(lowerPtr, prevRowKeyPos, rowKeyPos, 0, lowerInclusiveKey.length,
slotSpan[i]);
+                schema.reposition(upperPtr, prevRowKeyPos, rowKeyPos, 0, upperExclusiveKey.length,
slotSpan[i]);
+                // If we have a range and the values differ, we must include all slots that
are less significant.
+                // For example: [A-D][1,23], the lower/upper keys could be B5/C2, where the
C is in range and the
+                // next slot value of 2 is less than the next corresponding slot value of
the 5.
+                if (lowerPtr.compareTo(upperPtr) != 0) {
+                    if (newSlots != null) {
+                        newSlots.addAll(slots.subList(i+1, slots.size()));
+                    }
+                    break;
+                }
+                prevRowKeyPos = rowKeyPos;
+            }
         }
         return true;
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/dd22ccd9/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
index 6905b03..4dcc6fe 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
@@ -217,6 +217,15 @@ public class PTableImpl implements PTable {
                 table.isMultiTenant(), table.getViewType(), table.getViewIndexId(), table.getTableStats());
     }
 
+    public static PTableImpl makePTable(PTable table, PTableStats stats) throws SQLException
{
+        return new PTableImpl(
+                table.getTenantId(), table.getSchemaName(), table.getTableName(), table.getType(),
table.getIndexState(), table.getTimeStamp(), 
+                table.getSequenceNumber(), table.getPKName(), table.getBucketNum(), getColumnsToClone(table),

+                table.getParentSchemaName(), table.getParentTableName(), table.getIndexes(),
table.isImmutableRows(),
+                table.getPhysicalNames(), table.getDefaultFamilyName(), table.getViewStatement(),
table.isWALDisabled(),
+                table.isMultiTenant(), table.getViewType(), table.getViewIndexId(), stats);
+    }
+
     public static PTableImpl makePTable(PName tenantId, PName schemaName, PName tableName,
PTableType type, PIndexState state, long timeStamp, long sequenceNumber,
             PName pkName, Integer bucketNum, List<PColumn> columns, PName dataSchemaName,
PName dataTableName, List<PTable> indexes, boolean isImmutableRows,
             List<PName> physicalNames, PName defaultFamilyName, String viewExpression,
boolean disableWAL, boolean multiTenant, ViewType viewType, Short viewIndexId) throws SQLException
{


Mime
View raw message