You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2015/03/28 01:04:56 UTC

[19/50] incubator-kylin git commit: KYLIN-625, consider null & code system in GTRecord comparison

KYLIN-625, consider null & code system in GTRecord comparison


Project: http://git-wip-us.apache.org/repos/asf/incubator-kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kylin/commit/959d031c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kylin/tree/959d031c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kylin/diff/959d031c

Branch: refs/heads/streaming-localdict
Commit: 959d031ce310921b0c77f173f3a55b449df54c60
Parents: 5dda35f
Author: Li, Yang <ya...@ebay.com>
Authored: Fri Mar 27 10:35:19 2015 +0800
Committer: Li, Yang <ya...@ebay.com>
Committed: Fri Mar 27 10:35:19 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kylin/common/util/ByteArray.java | 25 ++++++++++++++++----
 .../kylin/storage/gridtable/GTRecord.java       |  5 +++-
 2 files changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/959d031c/common/src/main/java/org/apache/kylin/common/util/ByteArray.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/kylin/common/util/ByteArray.java b/common/src/main/java/org/apache/kylin/common/util/ByteArray.java
index df107a5..8856fe8 100644
--- a/common/src/main/java/org/apache/kylin/common/util/ByteArray.java
+++ b/common/src/main/java/org/apache/kylin/common/util/ByteArray.java
@@ -30,7 +30,7 @@ public class ByteArray implements Comparable<ByteArray> {
     public static ByteArray allocate(int length) {
         return new ByteArray(new byte[length]);
     }
-    
+
     public static ByteArray copyOf(byte[] array, int offset, int length) {
         byte[] space = new byte[length];
         System.arraycopy(array, offset, space, 0, length);
@@ -88,7 +88,7 @@ public class ByteArray implements Comparable<ByteArray> {
     public void setLength(int length) {
         this.length = length;
     }
-    
+
     public ByteArray copy() {
         ByteArray copy = new ByteArray(length);
         copy.copyFrom(this);
@@ -111,7 +111,10 @@ public class ByteArray implements Comparable<ByteArray> {
 
     @Override
     public int hashCode() {
-        return Bytes.hashCode(data, offset, length);
+        if (data == null)
+            return 0;
+        else
+            return Bytes.hashCode(data, offset, length);
     }
 
     @Override
@@ -123,12 +126,24 @@ public class ByteArray implements Comparable<ByteArray> {
         if (getClass() != obj.getClass())
             return false;
         ByteArray o = (ByteArray) obj;
-        return Bytes.equals(this.data, this.offset, this.length, o.data, o.offset, o.length);
+        if (this.data == null && o.data == null)
+            return true;
+        else if (this.data == null || o.data == null)
+            return false;
+        else
+            return Bytes.equals(this.data, this.offset, this.length, o.data, o.offset, o.length);
     }
 
     @Override
     public int compareTo(ByteArray o) {
-        return Bytes.compareTo(this.data, this.offset, this.length, o.data, o.offset, o.length);
+        if (this.data == null && o.data == null)
+            return 0;
+        else if (this.data == null)
+            return -1;
+        else if (o.data == null)
+            return 1;
+        else
+            return Bytes.compareTo(this.data, this.offset, this.length, o.data, o.offset, o.length);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/959d031c/storage/src/main/java/org/apache/kylin/storage/gridtable/GTRecord.java
----------------------------------------------------------------------
diff --git a/storage/src/main/java/org/apache/kylin/storage/gridtable/GTRecord.java b/storage/src/main/java/org/apache/kylin/storage/gridtable/GTRecord.java
index 6eb38a9..605a469 100644
--- a/storage/src/main/java/org/apache/kylin/storage/gridtable/GTRecord.java
+++ b/storage/src/main/java/org/apache/kylin/storage/gridtable/GTRecord.java
@@ -5,6 +5,7 @@ import java.util.Arrays;
 import java.util.BitSet;
 
 import org.apache.kylin.common.util.ByteArray;
+import org.apache.kylin.metadata.filter.IFilterCodeSystem;
 
 public class GTRecord implements Comparable<GTRecord> {
 
@@ -128,11 +129,13 @@ public class GTRecord implements Comparable<GTRecord> {
 
     @Override
     public int compareTo(GTRecord o) {
+        assert this.info == o.info;
         assert this.maskForEqualHashComp == o.maskForEqualHashComp; // reference equal for performance
+        IFilterCodeSystem<ByteArray> cs = info.codeSystem.getFilterCodeSystem();
         
         int comp = 0;
         for (int i = maskForEqualHashComp.nextSetBit(0); i >= 0; i = maskForEqualHashComp.nextSetBit(i + 1)) {
-            comp = this.cols[i].compareTo(o.cols[i]);
+            comp = cs.compare(cols[i], o.cols[i]);
             if (comp != 0)
                 return comp;
         }