kylin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liy...@apache.org
Subject [16/50] [abbrv] incubator-kylin git commit: KYLIN-625, formalize ICodeSystem
Date Sat, 14 Mar 2015 00:00:51 GMT
KYLIN-625, formalize ICodeSystem


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

Branch: refs/heads/streaming-localdict
Commit: 6ecd73ea2f55b4cb39ed6ac9c9a1c33a40a19579
Parents: 2be4e32
Author: Li, Yang <yangli9@ebay.com>
Authored: Wed Mar 11 10:40:51 2015 +0800
Committer: Li, Yang <yangli9@ebay.com>
Committed: Wed Mar 11 10:40:51 2015 +0800

----------------------------------------------------------------------
 .../kylin/metadata/filter/CaseTupleFilter.java  |  9 ++++--
 .../metadata/filter/ColumnTupleFilter.java      |  8 ++++--
 .../metadata/filter/CompareTupleFilter.java     |  6 +++-
 .../metadata/filter/ConstantTupleFilter.java    |  7 +++--
 .../metadata/filter/DynamicTupleFilter.java     |  8 ++++--
 .../metadata/filter/ExtractTupleFilter.java     |  9 ++++--
 .../kylin/metadata/filter/ICodeSystem.java      | 23 ---------------
 .../metadata/filter/IEvaluatableTuple.java      |  9 ------
 .../metadata/filter/LogicalTupleFilter.java     | 15 ++++++----
 .../kylin/metadata/filter/StringCodeSystem.java | 25 +++++++++++-----
 .../kylin/metadata/filter/TupleFilter.java      |  8 ++++--
 .../metadata/filter/TupleFilterSerializer.java  | 11 +++----
 .../kylin/metadata/tuple/ICodeSystem.java       | 30 ++++++++++++++++++++
 .../kylin/metadata/tuple/IEvaluatableTuple.java |  9 ++++++
 .../org/apache/kylin/metadata/tuple/ITuple.java |  3 +-
 .../storage/hbase/DerivedFilterTranslator.java  |  2 +-
 .../hbase/coprocessor/CoprocessorFilter.java    |  2 +-
 .../hbase/coprocessor/DictCodeSystem.java       | 22 ++++++++++----
 .../coprocessor/observer/ObserverTuple.java     |  2 +-
 .../kylin/storage/filter/FilterBaseTest.java    |  1 +
 20 files changed, 130 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/filter/CaseTupleFilter.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/CaseTupleFilter.java
b/metadata/src/main/java/org/apache/kylin/metadata/filter/CaseTupleFilter.java
index d3ec3e3..4b85172 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/CaseTupleFilter.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/CaseTupleFilter.java
@@ -23,6 +23,9 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.kylin.metadata.tuple.ICodeSystem;
+import org.apache.kylin.metadata.tuple.IEvaluatableTuple;
+
 
 /**
  * @author xjiang
@@ -62,7 +65,7 @@ public class CaseTupleFilter extends TupleFilter {
     }
 
     @Override
-    public boolean evaluate(IEvaluatableTuple tuple, ICodeSystem cs) {
+    public boolean evaluate(IEvaluatableTuple tuple, ICodeSystem<?> cs) {
         if (whenFilters.size() != thenFilters.size()) {
             elseFilter = whenFilters.remove(whenFilters.size() - 1);
         }
@@ -100,12 +103,12 @@ public class CaseTupleFilter extends TupleFilter {
     }
 
     @Override
-    public byte[] serialize(ICodeSystem cs) {
+    public byte[] serialize(ICodeSystem<?> cs) {
         return new byte[0];
     }
 
     @Override
-    public void deserialize(byte[] bytes, ICodeSystem cs) {
+    public void deserialize(byte[] bytes, ICodeSystem<?> cs) {
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/filter/ColumnTupleFilter.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/ColumnTupleFilter.java
b/metadata/src/main/java/org/apache/kylin/metadata/filter/ColumnTupleFilter.java
index a294112..75f534d 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/ColumnTupleFilter.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/ColumnTupleFilter.java
@@ -28,6 +28,8 @@ import org.apache.kylin.common.util.BytesUtil;
 import org.apache.kylin.metadata.model.ColumnDesc;
 import org.apache.kylin.metadata.model.TableDesc;
 import org.apache.kylin.metadata.model.TblColRef;
+import org.apache.kylin.metadata.tuple.ICodeSystem;
+import org.apache.kylin.metadata.tuple.IEvaluatableTuple;
 
 /**
  * 
@@ -66,7 +68,7 @@ public class ColumnTupleFilter extends TupleFilter {
     }
 
     @Override
-    public boolean evaluate(IEvaluatableTuple tuple, ICodeSystem cs) {
+    public boolean evaluate(IEvaluatableTuple tuple, ICodeSystem<?> cs) {
         this.tupleValue = tuple.getValue(columnRef);
         return true;
     }
@@ -83,7 +85,7 @@ public class ColumnTupleFilter extends TupleFilter {
     }
 
     @Override
-    public byte[] serialize(ICodeSystem cs) {
+    public byte[] serialize(ICodeSystem<?> cs) {
         ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
         String table = columnRef.getTable();
         BytesUtil.writeUTFString(table, buffer);
@@ -103,7 +105,7 @@ public class ColumnTupleFilter extends TupleFilter {
     }
 
     @Override
-    public void deserialize(byte[] bytes, ICodeSystem cs) {
+    public void deserialize(byte[] bytes, ICodeSystem<?> cs) {
         TableDesc table = null;
         ColumnDesc column = new ColumnDesc();
         ByteBuffer buffer = ByteBuffer.wrap(bytes);

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java
b/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java
index 48b31ea..71950ff 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java
@@ -27,6 +27,8 @@ import java.util.Map;
 
 import org.apache.kylin.common.util.BytesUtil;
 import org.apache.kylin.metadata.model.TblColRef;
+import org.apache.kylin.metadata.tuple.ICodeSystem;
+import org.apache.kylin.metadata.tuple.IEvaluatableTuple;
 
 /**
  * @author xjiang
@@ -128,6 +130,7 @@ public class CompareTupleFilter extends TupleFilter {
 
     // TODO requires generalize, currently only evaluates COLUMN {op} CONST
     @Override
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     public boolean evaluate(IEvaluatableTuple tuple, ICodeSystem cs) {
         // extract tuple value
         Object tupleValue = null;
@@ -194,6 +197,7 @@ public class CompareTupleFilter extends TupleFilter {
         return column != null && !conditionValues.isEmpty();
     }
 
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
     public byte[] serialize(ICodeSystem cs) {
         ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
@@ -209,7 +213,7 @@ public class CompareTupleFilter extends TupleFilter {
     }
 
     @Override
-    public void deserialize(byte[] bytes, ICodeSystem cs) {
+    public void deserialize(byte[] bytes, ICodeSystem<?> cs) {
         this.dynamicVariables.clear();
         ByteBuffer buffer = ByteBuffer.wrap(bytes);
         int size = BytesUtil.readVInt(buffer);

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/filter/ConstantTupleFilter.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/ConstantTupleFilter.java
b/metadata/src/main/java/org/apache/kylin/metadata/filter/ConstantTupleFilter.java
index 2280c6a..c92b743 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/ConstantTupleFilter.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/ConstantTupleFilter.java
@@ -24,6 +24,8 @@ import java.util.Collections;
 import java.util.HashSet;
 
 import org.apache.kylin.common.util.BytesUtil;
+import org.apache.kylin.metadata.tuple.ICodeSystem;
+import org.apache.kylin.metadata.tuple.IEvaluatableTuple;
 
 /**
  * 
@@ -63,7 +65,7 @@ public class ConstantTupleFilter extends TupleFilter {
     }
 
     @Override
-    public boolean evaluate(IEvaluatableTuple tuple, ICodeSystem cs) {
+    public boolean evaluate(IEvaluatableTuple tuple, ICodeSystem<?> cs) {
         return constantValues.size() > 0;
     }
 
@@ -77,6 +79,7 @@ public class ConstantTupleFilter extends TupleFilter {
         return this.constantValues;
     }
 
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
     public byte[] serialize(ICodeSystem cs) {
         ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
@@ -91,7 +94,7 @@ public class ConstantTupleFilter extends TupleFilter {
     }
 
     @Override
-    public void deserialize(byte[] bytes, ICodeSystem cs) {
+    public void deserialize(byte[] bytes, ICodeSystem<?> cs) {
         this.constantValues.clear();
         ByteBuffer buffer = ByteBuffer.wrap(bytes);
         int size = BytesUtil.readVInt(buffer);

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/filter/DynamicTupleFilter.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/DynamicTupleFilter.java
b/metadata/src/main/java/org/apache/kylin/metadata/filter/DynamicTupleFilter.java
index 64f12b8..3d7f65f 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/DynamicTupleFilter.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/DynamicTupleFilter.java
@@ -23,6 +23,8 @@ import java.util.Collection;
 import java.util.Collections;
 
 import org.apache.kylin.common.util.BytesUtil;
+import org.apache.kylin.metadata.tuple.ICodeSystem;
+import org.apache.kylin.metadata.tuple.IEvaluatableTuple;
 
 /**
  * 
@@ -53,7 +55,7 @@ public class DynamicTupleFilter extends TupleFilter {
     }
 
     @Override
-    public boolean evaluate(IEvaluatableTuple tuple, ICodeSystem cs) {
+    public boolean evaluate(IEvaluatableTuple tuple, ICodeSystem<?> cs) {
         return true;
     }
 
@@ -68,7 +70,7 @@ public class DynamicTupleFilter extends TupleFilter {
     }
 
     @Override
-    public byte[] serialize(ICodeSystem cs) {
+    public byte[] serialize(ICodeSystem<?> cs) {
         ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
         BytesUtil.writeUTFString(variableName, buffer);
         byte[] result = new byte[buffer.position()];
@@ -77,7 +79,7 @@ public class DynamicTupleFilter extends TupleFilter {
     }
 
     @Override
-    public void deserialize(byte[] bytes, ICodeSystem cs) {
+    public void deserialize(byte[] bytes, ICodeSystem<?> cs) {
         ByteBuffer buffer = ByteBuffer.wrap(bytes);
         this.variableName = BytesUtil.readUTFString(buffer);
     }

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/filter/ExtractTupleFilter.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/ExtractTupleFilter.java
b/metadata/src/main/java/org/apache/kylin/metadata/filter/ExtractTupleFilter.java
index 929ab0f..ad1395c 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/ExtractTupleFilter.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/ExtractTupleFilter.java
@@ -22,6 +22,9 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.kylin.metadata.tuple.ICodeSystem;
+import org.apache.kylin.metadata.tuple.IEvaluatableTuple;
+
 
 /**
  * 
@@ -52,7 +55,7 @@ public class ExtractTupleFilter extends TupleFilter {
     }
 
     @Override
-    public boolean evaluate(IEvaluatableTuple tuple, ICodeSystem cs) {
+    public boolean evaluate(IEvaluatableTuple tuple, ICodeSystem<?> cs) {
         // extract tuple value
         String extractType = null;
         String tupleValue = null;
@@ -112,12 +115,12 @@ public class ExtractTupleFilter extends TupleFilter {
     }
 
     @Override
-    public byte[] serialize(ICodeSystem cs) {
+    public byte[] serialize(ICodeSystem<?> cs) {
         return new byte[0];
     }
 
     @Override
-    public void deserialize(byte[] bytes, ICodeSystem cs) {
+    public void deserialize(byte[] bytes, ICodeSystem<?> cs) {
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/filter/ICodeSystem.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/ICodeSystem.java b/metadata/src/main/java/org/apache/kylin/metadata/filter/ICodeSystem.java
deleted file mode 100644
index 39dcd16..0000000
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/ICodeSystem.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.apache.kylin.metadata.filter;
-
-import java.nio.ByteBuffer;
-
-/**
- * Decides how constant values in filter are coded and compared.
- * 
- * TupleFilter are involved in both query engine and coprocessor. In query engine, the values
are strings.
- * In coprocessor, the values are dictionary IDs.
- * 
- * @author yangli9
- */
-public interface ICodeSystem {
-
-    boolean isNull(Object value);
-
-    int compare(Object tupleValue, Object constValue);
-
-    void serialize(Object value, ByteBuffer buffer);
-
-    Object deserialize(ByteBuffer buffer);
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/filter/IEvaluatableTuple.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/IEvaluatableTuple.java
b/metadata/src/main/java/org/apache/kylin/metadata/filter/IEvaluatableTuple.java
deleted file mode 100644
index 92f83f1..0000000
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/IEvaluatableTuple.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.apache.kylin.metadata.filter;
-
-import org.apache.kylin.metadata.model.TblColRef;
-
-public interface IEvaluatableTuple {
-
-    public Object getValue(TblColRef col);
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/filter/LogicalTupleFilter.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/LogicalTupleFilter.java
b/metadata/src/main/java/org/apache/kylin/metadata/filter/LogicalTupleFilter.java
index 6b77cb5..0c8f96b 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/LogicalTupleFilter.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/LogicalTupleFilter.java
@@ -24,6 +24,9 @@ import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.kylin.metadata.tuple.ICodeSystem;
+import org.apache.kylin.metadata.tuple.IEvaluatableTuple;
+
 
 public class LogicalTupleFilter extends TupleFilter {
 
@@ -69,7 +72,7 @@ public class LogicalTupleFilter extends TupleFilter {
     }
 
     @Override
-    public boolean evaluate(IEvaluatableTuple tuple, ICodeSystem cs) {
+    public boolean evaluate(IEvaluatableTuple tuple, ICodeSystem<?> cs) {
         switch (this.operator) {
         case AND:
             return evalAnd(tuple, cs);
@@ -82,7 +85,7 @@ public class LogicalTupleFilter extends TupleFilter {
         }
     }
 
-    private boolean evalAnd(IEvaluatableTuple tuple, ICodeSystem cs) {
+    private boolean evalAnd(IEvaluatableTuple tuple, ICodeSystem<?> cs) {
         for (TupleFilter filter : this.children) {
             if (!filter.evaluate(tuple, cs)) {
                 return false;
@@ -91,7 +94,7 @@ public class LogicalTupleFilter extends TupleFilter {
         return true;
     }
 
-    private boolean evalOr(IEvaluatableTuple tuple, ICodeSystem cs) {
+    private boolean evalOr(IEvaluatableTuple tuple, ICodeSystem<?> cs) {
         for (TupleFilter filter : this.children) {
             if (filter.evaluate(tuple, cs)) {
                 return true;
@@ -100,7 +103,7 @@ public class LogicalTupleFilter extends TupleFilter {
         return false;
     }
 
-    private boolean evalNot(IEvaluatableTuple tuple, ICodeSystem cs) {
+    private boolean evalNot(IEvaluatableTuple tuple, ICodeSystem<?> cs) {
         return !this.children.get(0).evaluate(tuple, cs);
     }
 
@@ -115,12 +118,12 @@ public class LogicalTupleFilter extends TupleFilter {
     }
 
     @Override
-    public byte[] serialize(ICodeSystem cs) {
+    public byte[] serialize(ICodeSystem<?> cs) {
         return new byte[0];
     }
 
     @Override
-    public void deserialize(byte[] bytes, ICodeSystem cs) {
+    public void deserialize(byte[] bytes, ICodeSystem<?> cs) {
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/filter/StringCodeSystem.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/StringCodeSystem.java
b/metadata/src/main/java/org/apache/kylin/metadata/filter/StringCodeSystem.java
index b39b398..5240491 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/StringCodeSystem.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/StringCodeSystem.java
@@ -3,13 +3,14 @@ package org.apache.kylin.metadata.filter;
 import java.nio.ByteBuffer;
 
 import org.apache.kylin.common.util.BytesUtil;
+import org.apache.kylin.metadata.tuple.ICodeSystem;
 
 /**
  * A simple code system where all values are strings and conform to string comparison system.
  * 
  * @author yangli9
  */
-public class StringCodeSystem implements ICodeSystem {
+public class StringCodeSystem implements ICodeSystem<String> {
     
     public static final StringCodeSystem INSTANCE = new StringCodeSystem();
     
@@ -18,22 +19,32 @@ public class StringCodeSystem implements ICodeSystem {
     }
 
     @Override
-    public boolean isNull(Object value) {
+    public String encode(Object value) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Object decode(String code) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean isNull(String value) {
         return value == null;
     }
 
     @Override
-    public int compare(Object tupleValue, Object constValue) {
-        return ((String) tupleValue).compareTo((String) constValue);
+    public int compare(String tupleValue, String constValue) {
+        return tupleValue.compareTo(constValue);
     }
 
     @Override
-    public void serialize(Object value, ByteBuffer buffer) {
-        BytesUtil.writeUTFString((String) value, buffer);
+    public void serialize(String value, ByteBuffer buffer) {
+        BytesUtil.writeUTFString( value, buffer);
     }
 
     @Override
-    public Object deserialize(ByteBuffer buffer) {
+    public String deserialize(ByteBuffer buffer) {
         return BytesUtil.readUTFString(buffer);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilter.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilter.java b/metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilter.java
index 5293d42..75d55c3 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilter.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilter.java
@@ -25,6 +25,8 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.kylin.metadata.model.TblColRef;
+import org.apache.kylin.metadata.tuple.ICodeSystem;
+import org.apache.kylin.metadata.tuple.IEvaluatableTuple;
 
 import com.google.common.collect.Maps;
 
@@ -188,13 +190,13 @@ public abstract class TupleFilter {
 
     public abstract boolean isEvaluable();
 
-    public abstract boolean evaluate(IEvaluatableTuple tuple, ICodeSystem cs);
+    public abstract boolean evaluate(IEvaluatableTuple tuple, ICodeSystem<?> cs);
 
     public abstract Collection<?> getValues();
 
-    abstract byte[] serialize(ICodeSystem cs);
+    abstract byte[] serialize(ICodeSystem<?> cs);
 
-    abstract void deserialize(byte[] bytes, ICodeSystem cs);
+    abstract void deserialize(byte[] bytes, ICodeSystem<?> cs);
 
     public static boolean isEvaluableRecursively(TupleFilter filter) {
         if (filter == null)

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilterSerializer.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilterSerializer.java
b/metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilterSerializer.java
index ba4b5e6..5164c5b 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilterSerializer.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/TupleFilterSerializer.java
@@ -24,6 +24,7 @@ import java.util.Map;
 import java.util.Stack;
 
 import org.apache.kylin.common.util.BytesUtil;
+import org.apache.kylin.metadata.tuple.ICodeSystem;
 
 /**
  * http://eli.thegreenplace.net/2011/09/29/an-interesting-tree-serialization-algorithm-from-dwarf
@@ -46,11 +47,11 @@ public class TupleFilterSerializer {
         }
     }
 
-    public static byte[] serialize(TupleFilter rootFilter, ICodeSystem cs) {
+    public static byte[] serialize(TupleFilter rootFilter, ICodeSystem<?> cs) {
         return serialize(rootFilter, null, cs);
     }
 
-    public static byte[] serialize(TupleFilter rootFilter, Decorator decorator, ICodeSystem
cs) {
+    public static byte[] serialize(TupleFilter rootFilter, Decorator decorator, ICodeSystem<?>
cs) {
         ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
         internalSerialize(rootFilter, decorator, buffer, cs);
         byte[] result = new byte[buffer.position()];
@@ -58,7 +59,7 @@ public class TupleFilterSerializer {
         return result;
     }
 
-    private static void internalSerialize(TupleFilter filter, Decorator decorator, ByteBuffer
buffer, ICodeSystem cs) {
+    private static void internalSerialize(TupleFilter filter, Decorator decorator, ByteBuffer
buffer, ICodeSystem<?> cs) {
         if (decorator != null) { // give decorator a chance to manipulate the
                                  // output filter
             filter = decorator.onSerialize(filter);
@@ -83,7 +84,7 @@ public class TupleFilterSerializer {
         }
     }
 
-    private static void serializeFilter(int flag, TupleFilter filter, Decorator decorator,
ByteBuffer buffer, ICodeSystem cs) {
+    private static void serializeFilter(int flag, TupleFilter filter, Decorator decorator,
ByteBuffer buffer, ICodeSystem<?> cs) {
         if (flag < 0) {
             BytesUtil.writeVInt(-1, buffer);
         } else {
@@ -95,7 +96,7 @@ public class TupleFilterSerializer {
         }
     }
 
-    public static TupleFilter deserialize(byte[] bytes, ICodeSystem cs) {
+    public static TupleFilter deserialize(byte[] bytes, ICodeSystem<?> cs) {
         ByteBuffer buffer = ByteBuffer.wrap(bytes);
         TupleFilter rootFilter = null;
         Stack<TupleFilter> parentStack = new Stack<TupleFilter>();

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/tuple/ICodeSystem.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/tuple/ICodeSystem.java b/metadata/src/main/java/org/apache/kylin/metadata/tuple/ICodeSystem.java
new file mode 100644
index 0000000..b5bc025
--- /dev/null
+++ b/metadata/src/main/java/org/apache/kylin/metadata/tuple/ICodeSystem.java
@@ -0,0 +1,30 @@
+package org.apache.kylin.metadata.tuple;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Decides how constant values are coded and compared.
+ * 
+ * TupleFilter are involved in both query engine and coprocessor. In query engine, the values
are strings.
+ * In coprocessor, the values are dictionary IDs.
+ * 
+ * The type parameter is java type of code, which should be bytes. However some legacy implementation
+ * stores code as String.
+ * 
+ * @author yangli9
+ */
+public interface ICodeSystem<T> {
+    
+    T encode(Object value);
+    
+    Object decode(T code);
+
+    boolean isNull(T code);
+
+    int compare(T code1, T code2);
+
+    void serialize(T code, ByteBuffer buffer);
+
+    T deserialize(ByteBuffer code);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/tuple/IEvaluatableTuple.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/tuple/IEvaluatableTuple.java
b/metadata/src/main/java/org/apache/kylin/metadata/tuple/IEvaluatableTuple.java
new file mode 100644
index 0000000..ce957b7
--- /dev/null
+++ b/metadata/src/main/java/org/apache/kylin/metadata/tuple/IEvaluatableTuple.java
@@ -0,0 +1,9 @@
+package org.apache.kylin.metadata.tuple;
+
+import org.apache.kylin.metadata.model.TblColRef;
+
+public interface IEvaluatableTuple {
+
+    public Object getValue(TblColRef col);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/metadata/src/main/java/org/apache/kylin/metadata/tuple/ITuple.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/tuple/ITuple.java b/metadata/src/main/java/org/apache/kylin/metadata/tuple/ITuple.java
index e5dbf08..05fe563 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/tuple/ITuple.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/tuple/ITuple.java
@@ -20,7 +20,6 @@ package org.apache.kylin.metadata.tuple;
 
 import java.util.List;
 
-import org.apache.kylin.metadata.filter.IEvaluatableTuple;
 import org.apache.kylin.metadata.model.TblColRef;
 
 /**
@@ -37,7 +36,7 @@ public interface ITuple extends IEvaluatableTuple {
 
     public Object[] getAllValues();
 
-    // declared in IEvaluatableTuple:  public Object getValue(TblColRef col);
+    // declared from IEvaluatableTuple:  public Object getValue(TblColRef col);
 
     public Object getValue(String field);
 

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/storage/src/main/java/org/apache/kylin/storage/hbase/DerivedFilterTranslator.java
----------------------------------------------------------------------
diff --git a/storage/src/main/java/org/apache/kylin/storage/hbase/DerivedFilterTranslator.java
b/storage/src/main/java/org/apache/kylin/storage/hbase/DerivedFilterTranslator.java
index 7fc0429..36a281f 100644
--- a/storage/src/main/java/org/apache/kylin/storage/hbase/DerivedFilterTranslator.java
+++ b/storage/src/main/java/org/apache/kylin/storage/hbase/DerivedFilterTranslator.java
@@ -30,12 +30,12 @@ import org.apache.kylin.dict.lookup.LookupStringTable;
 import org.apache.kylin.metadata.filter.ColumnTupleFilter;
 import org.apache.kylin.metadata.filter.CompareTupleFilter;
 import org.apache.kylin.metadata.filter.ConstantTupleFilter;
-import org.apache.kylin.metadata.filter.IEvaluatableTuple;
 import org.apache.kylin.metadata.filter.LogicalTupleFilter;
 import org.apache.kylin.metadata.filter.StringCodeSystem;
 import org.apache.kylin.metadata.filter.TupleFilter;
 import org.apache.kylin.metadata.filter.TupleFilter.FilterOperatorEnum;
 import org.apache.kylin.metadata.model.TblColRef;
+import org.apache.kylin.metadata.tuple.IEvaluatableTuple;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/CoprocessorFilter.java
----------------------------------------------------------------------
diff --git a/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/CoprocessorFilter.java
b/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/CoprocessorFilter.java
index ea4b2e1..a91999f 100644
--- a/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/CoprocessorFilter.java
+++ b/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/CoprocessorFilter.java
@@ -22,10 +22,10 @@ import java.util.Set;
 
 import org.apache.kylin.common.util.BytesUtil;
 import org.apache.kylin.dict.IDictionaryAware;
-import org.apache.kylin.metadata.filter.IEvaluatableTuple;
 import org.apache.kylin.metadata.filter.TupleFilter;
 import org.apache.kylin.metadata.filter.TupleFilterSerializer;
 import org.apache.kylin.metadata.model.TblColRef;
+import org.apache.kylin.metadata.tuple.IEvaluatableTuple;
 
 /**
  * @author yangli9

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/DictCodeSystem.java
----------------------------------------------------------------------
diff --git a/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/DictCodeSystem.java
b/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/DictCodeSystem.java
index 14497f4..cada02b 100644
--- a/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/DictCodeSystem.java
+++ b/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/DictCodeSystem.java
@@ -4,9 +4,9 @@ import java.nio.ByteBuffer;
 
 import org.apache.kylin.common.util.BytesUtil;
 import org.apache.kylin.dict.Dictionary;
-import org.apache.kylin.metadata.filter.ICodeSystem;
+import org.apache.kylin.metadata.tuple.ICodeSystem;
 
-public class DictCodeSystem implements ICodeSystem {
+public class DictCodeSystem implements ICodeSystem<String> {
 
     public static final DictCodeSystem INSTANCE = new DictCodeSystem();
     
@@ -15,7 +15,17 @@ public class DictCodeSystem implements ICodeSystem {
     }
 
     @Override
-    public boolean isNull(Object value) {
+    public String encode(Object value) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Object decode(String code) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean isNull(String value) {
         if (value == null)
             return true;
         
@@ -28,17 +38,17 @@ public class DictCodeSystem implements ICodeSystem {
     }
 
     @Override
-    public int compare(Object tupleValue, Object constValue) {
+    public int compare(String tupleValue, String constValue) {
         return ((String) tupleValue).compareTo((String) constValue);
     }
 
     @Override
-    public void serialize(Object value, ByteBuffer buffer) {
+    public void serialize(String value, ByteBuffer buffer) {
         BytesUtil.writeUTFString((String) value, buffer);
     }
 
     @Override
-    public Object deserialize(ByteBuffer buffer) {
+    public String deserialize(ByteBuffer buffer) {
         return BytesUtil.readUTFString(buffer);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/observer/ObserverTuple.java
----------------------------------------------------------------------
diff --git a/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/observer/ObserverTuple.java
b/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/observer/ObserverTuple.java
index 288afa9..cdbe392 100644
--- a/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/observer/ObserverTuple.java
+++ b/storage/src/main/java/org/apache/kylin/storage/hbase/coprocessor/observer/ObserverTuple.java
@@ -20,8 +20,8 @@ package org.apache.kylin.storage.hbase.coprocessor.observer;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.kylin.dict.Dictionary;
-import org.apache.kylin.metadata.filter.IEvaluatableTuple;
 import org.apache.kylin.metadata.model.TblColRef;
+import org.apache.kylin.metadata.tuple.IEvaluatableTuple;
 import org.apache.kylin.storage.hbase.coprocessor.CoprocessorRowType;
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6ecd73ea/storage/src/test/java/org/apache/kylin/storage/filter/FilterBaseTest.java
----------------------------------------------------------------------
diff --git a/storage/src/test/java/org/apache/kylin/storage/filter/FilterBaseTest.java b/storage/src/test/java/org/apache/kylin/storage/filter/FilterBaseTest.java
index 97e0e33..fe9d336 100644
--- a/storage/src/test/java/org/apache/kylin/storage/filter/FilterBaseTest.java
+++ b/storage/src/test/java/org/apache/kylin/storage/filter/FilterBaseTest.java
@@ -27,6 +27,7 @@ import org.apache.kylin.metadata.filter.*;
 import org.apache.kylin.metadata.model.ColumnDesc;
 import org.apache.kylin.metadata.model.TableDesc;
 import org.apache.kylin.metadata.model.TblColRef;
+import org.apache.kylin.metadata.tuple.ICodeSystem;
 import org.apache.kylin.metadata.filter.TupleFilter.FilterOperatorEnum;
 import org.apache.kylin.storage.tuple.Tuple;
 import org.apache.kylin.storage.tuple.TupleInfo;


Mime
View raw message