You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kylin.apache.org by GitBox <gi...@apache.org> on 2018/07/08 09:47:49 UTC

[GitHub] shaofengshi closed pull request #159: KYLIN-3403 filter code system add one type of Date

shaofengshi closed pull request #159: KYLIN-3403 filter code system add one type of Date
URL: https://github.com/apache/kylin/pull/159
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/filter/FilterCodeSystemFactory.java b/core-metadata/src/main/java/org/apache/kylin/metadata/filter/FilterCodeSystemFactory.java
index bae8cf94e2..8ac36b1216 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/filter/FilterCodeSystemFactory.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/filter/FilterCodeSystemFactory.java
@@ -22,18 +22,23 @@
 import java.util.HashMap;
 
 import org.apache.kylin.common.util.BytesUtil;
+import org.apache.kylin.common.util.DateFormat;
 import org.apache.kylin.metadata.datatype.DataType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Created by donald.zheng on 2016/12/19.
  */
 public class FilterCodeSystemFactory {
+    private static final Logger logger = LoggerFactory.getLogger(FilterCodeSystemFactory.class);
     private final static HashMap<String, IFilterCodeSystem> codeSystemMap = new HashMap<>();
 
     static {
         codeSystemMap.put("string", StringCodeSystem.INSTANCE);
         codeSystemMap.put("integer", new IntegerCodeSystem());
         codeSystemMap.put("decimal", new DecimalCodeSystem());
+        codeSystemMap.put("date", new DateTimeCodeSystem());
     }
 
     public static IFilterCodeSystem getFilterCodeSystem(DataType dataType) {
@@ -41,6 +46,8 @@ public static IFilterCodeSystem getFilterCodeSystem(DataType dataType) {
             return codeSystemMap.get("integer");
         } else if (dataType.isNumberFamily()) {
             return codeSystemMap.get("decimal");
+        } else if (dataType.isDateTimeFamily()) {
+            return codeSystemMap.get("date");
         } else {
             return codeSystemMap.get("string");
         }
@@ -95,4 +102,33 @@ public int compare(Object o, Object t1) {
         }
     }
 
+    private static class DateTimeCodeSystem implements IFilterCodeSystem<String> {
+
+        @Override
+        public boolean isNull(String code) {
+            return code == null;
+        }
+
+        @Override
+        public void serialize(String code, ByteBuffer buf) {
+            BytesUtil.writeUTFString(code, buf);
+        }
+
+        @Override
+        public String deserialize(ByteBuffer buf) {
+            return BytesUtil.readUTFString(buf);
+        }
+
+        @Override
+        public int compare(String o1, String o2) {
+            try {
+                long d1 = DateFormat.stringToMillis(o1);
+                long d2 = DateFormat.stringToMillis(o2);
+                return Long.compare(d1, d2);
+            } catch (IllegalArgumentException e) {
+                logger.error("failed to convert string[{},{}] to date, use string to compare.", o1, o2, e);
+                return o1.compareTo(o2);
+            }
+        }
+    }
 }
diff --git a/kylin-it/src/test/resources/query/sql_datetime/query01.sql b/kylin-it/src/test/resources/query/sql_datetime/query01.sql
new file mode 100644
index 0000000000..b2f8b8059d
--- /dev/null
+++ b/kylin-it/src/test/resources/query/sql_datetime/query01.sql
@@ -0,0 +1,9 @@
+SELECT
+
+count(1) as TRANS_CNT
+
+FROM TEST_KYLIN_FACT as TEST_KYLIN_FACT 
+INNER JOIN EDW.TEST_CAL_DT as TEST_CAL_DT
+ON TEST_KYLIN_FACT.CAL_DT = TEST_CAL_DT.CAL_DT
+
+WHERE TEST_CAL_DT.WEEK_BEG_DT > date'2001-09-09'
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services