kylin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lid...@apache.org
Subject [21/50] [abbrv] kylin git commit: KYLIN-2349 Serialize BitmapCounter with peekLength
Date Thu, 12 Jan 2017 04:09:53 GMT
KYLIN-2349 Serialize BitmapCounter with peekLength

Signed-off-by: Yang Li <liyang@apache.org>


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

Branch: refs/heads/master-cdh5.7
Commit: aa574462aad0620fe10343613dc4c8d761c0d6a0
Parents: 746e380
Author: kangkaisen <kangkaisen@live.com>
Authored: Sat Dec 31 15:41:07 2016 +0800
Committer: Yang Li <liyang@apache.org>
Committed: Sat Jan 7 19:08:15 2017 +0800

----------------------------------------------------------------------
 .../kylin/measure/bitmap/BitmapCounter.java     | 53 ++++++++++++++------
 1 file changed, 37 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/aa574462/core-metadata/src/main/java/org/apache/kylin/measure/bitmap/BitmapCounter.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/measure/bitmap/BitmapCounter.java
b/core-metadata/src/main/java/org/apache/kylin/measure/bitmap/BitmapCounter.java
index a7f277e..aeb14ba 100644
--- a/core-metadata/src/main/java/org/apache/kylin/measure/bitmap/BitmapCounter.java
+++ b/core-metadata/src/main/java/org/apache/kylin/measure/bitmap/BitmapCounter.java
@@ -34,6 +34,7 @@ import org.roaringbitmap.buffer.MutableRoaringBitmap;
 public class BitmapCounter implements Comparable<BitmapCounter> {
 
     private MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
+    private final int VERSION = 2;
 
     public BitmapCounter() {
     }
@@ -102,15 +103,51 @@ public class BitmapCounter implements Comparable<BitmapCounter>
{
         bitmap.serialize(dos);
         dos.close();
         ByteBuffer bb = ByteBuffer.wrap(bos.toByteArray());
+        out.putInt(VERSION);
+        out.putInt(bos.size() + 4 + 4);
         out.put(bb);
     }
 
     public void readRegisters(ByteBuffer in) throws IOException {
+        int mark = in.position();
+        int version = in.getInt();
+
+        // keep forward compatibility
+        if (version == VERSION) {
+            @SuppressWarnings("unused")
+            int size = in.getInt();
+        } else {
+            in.position(mark);
+        }
+
         try (DataInputStream is = new DataInputStream(new ByteBufferBackedInputStream(in)))
{
             bitmap.deserialize(is);
         }
     }
 
+    public int peekLength(ByteBuffer in) {
+        int mark = in.position();
+        int len;
+        int version = in.getInt();
+
+        // keep forward compatibility
+        if (version == VERSION) {
+            len = in.getInt() ;
+        } else {
+            in.position(mark);
+            try (DataInputStream is = new DataInputStream(new ByteBufferBackedInputStream(in)))
{
+                MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
+                bitmap.deserialize(is);
+                len = in.position() - mark;
+            } catch (IOException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+
+        in.position(mark);
+        return len;
+    }
+
     @Override
     public String toString() {
         long count = getCount();
@@ -169,22 +206,6 @@ public class BitmapCounter implements Comparable<BitmapCounter>
{
             return -1;
     }
 
-    public int peekLength(ByteBuffer in) {
-        int mark = in.position();
-        int len;
-
-        MutableRoaringBitmap bitmap = new MutableRoaringBitmap();
-        try (DataInputStream is = new DataInputStream(new ByteBufferBackedInputStream(in)))
{
-            bitmap.deserialize(is);
-        } catch (IOException e) {
-            throw new IllegalStateException(e);
-        }
-
-        len = in.position() - mark;
-        in.position(mark);
-        return len;
-    }
-
     private class ByteBufferBackedInputStream extends InputStream {
         private final ByteBuffer buffer;
 


Mime
View raw message