You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2014/08/08 21:31:18 UTC

git commit: PHOENIX-1152 Prepend seek next hint of skip scan with region start key for local indexing

Repository: phoenix
Updated Branches:
  refs/heads/4.0 48e0827d6 -> df0122c7e


PHOENIX-1152 Prepend seek next hint of skip scan with region start key for local indexing


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

Branch: refs/heads/4.0
Commit: df0122c7ebabbfa7d1e07ab024a03d86ae1a3259
Parents: 48e0827
Author: James Taylor <jt...@salesforce.com>
Authored: Fri Aug 8 12:34:51 2014 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Fri Aug 8 12:34:51 2014 -0700

----------------------------------------------------------------------
 .../apache/phoenix/filter/SkipScanFilter.java   | 24 ++++++++++++++++----
 .../org/apache/phoenix/schema/ValueSchema.java  | 14 ++++++++++++
 2 files changed, 34 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/df0122c7/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 5cee0d7..b9b091d 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
@@ -75,6 +75,7 @@ public class SkipScanFilter extends FilterBase implements Writable {
     private int endKeyLength;
     private boolean isDone;
     private int offset;
+    private Cell nextCellHint;
 
     private final ImmutableBytesWritable ptr = new ImmutableBytesWritable();
 
@@ -121,14 +122,29 @@ public class SkipScanFilter extends FilterBase implements Writable {
 
     @Override
     public ReturnCode filterKeyValue(Cell kv) {
-        return navigate(kv.getRowArray(), kv.getRowOffset() + offset,kv.getRowLength()- offset,Terminate.AFTER);
+        ReturnCode code = navigate(kv.getRowArray(), kv.getRowOffset() + offset,kv.getRowLength()- offset,Terminate.AFTER);
+        if (code == ReturnCode.SEEK_NEXT_USING_HINT) {
+            setNextCellHint(kv);
+        }
+        return code;
     }
 
+    private void setNextCellHint(Cell kv) {
+        if (offset == 0) {
+            nextCellHint = new KeyValue(startKey, 0, startKeyLength,
+                    null, 0, 0, null, 0, 0, HConstants.LATEST_TIMESTAMP, Type.Maximum, null, 0, 0);
+        } else { // Prepend key of NextCellHint with bytes before offset
+            byte[] nextKey = new byte[offset + startKeyLength];
+            System.arraycopy(kv.getRowArray(), kv.getRowOffset(), nextKey, 0, offset);
+            System.arraycopy(startKey, 0, nextKey, offset, startKeyLength);
+            nextCellHint = new KeyValue(nextKey, 0, nextKey.length,
+                    null, 0, 0, null, 0, 0, HConstants.LATEST_TIMESTAMP, Type.Maximum, null, 0, 0);
+        }
+    }
+    
     @Override
     public Cell getNextCellHint(Cell kv) {
-        // TODO: don't allocate new key value every time here if possible
-        return isDone ? null : new KeyValue(startKey, 0, startKeyLength,
-                null, 0, 0, null, 0, 0, HConstants.LATEST_TIMESTAMP, Type.Maximum, null, 0, 0);
+        return isDone ? null : nextCellHint;
     }
 
     public boolean hasIntersect(byte[] lowerInclusiveKey, byte[] upperExclusiveKey) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/df0122c7/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
index b7af8a4..12e30ab 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/ValueSchema.java
@@ -56,6 +56,11 @@ public abstract class ValueSchema implements Writable {
         init(minNullable, fields);
     }
     
+    @Override
+    public String toString() {
+        return fields.toString();
+    }
+    
     public int getEstimatedSize() { // Memory size of ValueSchema
         int count = fieldIndexByPosition.length;
         return SizedUtil.OBJECT_SIZE + SizedUtil.POINTER_SIZE + SizedUtil.INT_SIZE * (4 + count) + 
@@ -187,6 +192,15 @@ public abstract class ValueSchema implements Writable {
             }
         }
         
+        @Override
+        public String toString() {
+            return (count == 1 ? "" : count + " * ") 
+                    + type.toString() 
+                    + (byteSize == 0 ? "" : "(" + byteSize + ")") 
+                    + (isNullable ? "" : " NOT NULL") 
+                    + (sortOrder == SortOrder.ASC ? "" : " " + sortOrder);
+        }
+        
         private Field(Field field, int count) {
             this.type = field.getDataType();
             this.byteSize = field.byteSize;