[ 
https://issues.apache.org/jira/browse/KYLIN-3403?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16536054#comment-16536054
 ] 

ASF GitHub Bot commented on KYLIN-3403:
---------------------------------------

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:
[email protected]


> Querying sample cube with filter "KYLIN_CAL_DT.WEEK_BEG_DT >= 
> CAST('2001-09-09' AS DATE)" returns unexpected empty result set 
> ------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: KYLIN-3403
>                 URL: https://issues.apache.org/jira/browse/KYLIN-3403
>             Project: Kylin
>          Issue Type: Bug
>          Components: Query Engine
>            Reporter: Yifan Zhang
>            Assignee: Yifan Zhang
>            Priority: Major
>             Fix For: v2.4.1, v2.5.0
>
>
> 2018-05-16 13:30:17,824 DEBUG [Query 
> aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] cachesync.CachedCrudAssist : Loaded 
> 3 ColumnACL(s) out of 3 resource
> 2018-05-16 13:30:17,840 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> routing.QueryRouter : Find candidates by table DEFAULT.KYLIN_SALES and 
> project=learn_kylin : 
> INVERTED_INDEX[name=kylin_sales_cube],CUBE[name=kylin_sales_cube]
> 2018-05-16 13:30:17,841 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> routing.QueryRouter : Applying rule: class 
> org.apache.kylin.query.routing.rules.RemoveBlackoutRealizationsRule, 
> realizations before: 
> [INVERTED_INDEX[name=kylin_sales_cube],CUBE[name=kylin_sales_cube]], 
> realizations after: 
> [INVERTED_INDEX[name=kylin_sales_cube],CUBE[name=kylin_sales_cube]]
> 2018-05-16 13:30:17,843 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> routing.QueryRouter : Applying rule: class 
> org.apache.kylin.query.routing.rules.RemoveUncapableRealizationsRule, 
> realizations before: 
> [INVERTED_INDEX[name=kylin_sales_cube],CUBE[name=kylin_sales_cube]], 
> realizations after: 
> [INVERTED_INDEX[name=kylin_sales_cube],CUBE[name=kylin_sales_cube]]
> 2018-05-16 13:30:17,844 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> rules.RealizationSortRule : INVERTED_INDEX[name=kylin_sales_cube] priority 1 
> cost 8360. CUBE[name=kylin_sales_cube] priority 1 cost 836.
> 2018-05-16 13:30:17,844 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> routing.QueryRouter : Applying rule: class 
> org.apache.kylin.query.routing.rules.RealizationSortRule, realizations 
> before: [INVERTED_INDEX[name=kylin_sales_cube],CUBE[name=kylin_sales_cube]], 
> realizations after: 
> [CUBE[name=kylin_sales_cube],INVERTED_INDEX[name=kylin_sales_cube]]
> 2018-05-16 13:30:17,844 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> routing.QueryRouter : The realizations remaining: 
> [CUBE[name=kylin_sales_cube],INVERTED_INDEX[name=kylin_sales_cube]],and the 
> final chosen one for current olap context 0 is CUBE[name=kylin_sales_cube]
> 2018-05-16 13:30:18,042 DEBUG [Query 
> aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] enumerator.OLAPEnumerator : query 
> storage...
> 2018-05-16 13:30:18,082 DEBUG [Query 
> aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] gtrecord.GTCubeStorageQueryBase : 
> Need storage aggregation
> 2018-05-16 13:30:18,083 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> gtrecord.GTCubeStorageQueryBase : exactAggregation is false because need 
> storage aggregation
> 2018-05-16 13:30:18,091 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> lookup.SnapshotManager : Loading snapshotTable from 
> /table_snapshot/DEFAULT.KYLIN_CAL_DT/2d3d125a-30f7-438f-bede-7212c5666f4a.snapshot,
>  with loadData: true
> 2018-05-16 13:30:18,197 DEBUG [Query 
> aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] lookup.SnapshotManager : Loaded 
> snapshot at 
> /table_snapshot/DEFAULT.KYLIN_CAL_DT/2d3d125a-30f7-438f-bede-7212c5666f4a.snapshot
> 2018-05-16 13:30:18,426 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> gtrecord.GTCubeStorageQueryBase : Filter column set for query: []
> 2018-05-16 13:30:18,426 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> gtrecord.GTCubeStorageQueryBase : Filter mask is: 0
> 2018-05-16 13:30:18,426 DEBUG [Query 
> aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] gtrecord.GTCubeStorageQueryBase : 
> storageLimitLevel set to NO_LIMIT because derived column require post 
> aggregation: [DEFAULT.KYLIN_SALES.PART_DT]
> 2018-05-16 13:30:18,426 DEBUG [Query 
> aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] gtrecord.GTCubeStorageQueryBase : 
> storageLimitLevel set to NO_LIMIT because the query has order by
> 2018-05-16 13:30:18,427 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> gtrecord.GTCubeStorageQueryBase : Cuboid identified: cube=kylin_sales_cube, 
> cuboidId=16384, groupsD=[], filterD=[], limitPushdown=2147483647, 
> limitLevel=NO_LIMIT, storageAggr=true
> 2018-05-16 13:30:18,429 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> gtrecord.CubeSegmentScanner : Init CubeSegmentScanner for segment 
> 20120101000000_20180403152544
> 2018-05-16 13:30:18,476 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> gtrecord.ScannerWorker : Segment 
> kylin_sales_cube[20120101000000_20180403152544] will be skipped
> 2018-05-16 13:30:18,477 DEBUG [Query 
> aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] enumerator.OLAPEnumerator : return 
> TupleIterator...
> 2018-05-16 13:30:18,481 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> service.QueryService : Processed rows for each storageContext: 0
> 2018-05-16 13:30:18,481 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> service.QueryService : Stats of SQL response: isException: false, duration: 
> 2711, total scan count 0
> 2018-05-16 13:30:18,512 INFO [Query aa20e5fd-8b86-4359-a87a-2a2e7b8c100a-162] 
> service.QueryService :
> ==========================[QUERY]===============================
> Query Id: aa20e5fd-8b86-4359-a87a-2a2e7b8c100a
> SQL: SELECT COUNT(1) AS "TRANS_CNT"
> FROM "DEFAULT"."KYLIN_SALES" AS "KYLIN_SALES"
> JOIN "DEFAULT"."KYLIN_CAL_DT" AS "KYLIN_CAL_DT" ON KYLIN_SALES.PART_DT = 
> KYLIN_CAL_DT.CAL_DT
> JOIN "DEFAULT"."KYLIN_CATEGORY_GROUPINGS" AS "KYLIN_CATEGORY_GROUPINGS" ON 
> KYLIN_SALES.LEAF_CATEG_ID = KYLIN_CATEGORY_GROUPINGS.LEAF_CATEG_ID
> AND KYLIN_SALES.LSTG_SITE_ID = KYLIN_CATEGORY_GROUPINGS.SITE_ID
> JOIN "DEFAULT"."KYLIN_ACCOUNT" AS "BUYER_ACCOUNT" ON KYLIN_SALES.BUYER_ID = 
> BUYER_ACCOUNT.ACCOUNT_ID
> JOIN "DEFAULT"."KYLIN_ACCOUNT" AS "SELLER_ACCOUNT" ON KYLIN_SALES.SELLER_ID = 
> SELLER_ACCOUNT.ACCOUNT_ID
> JOIN "DEFAULT"."KYLIN_COUNTRY" AS "BUYER_COUNTRY" ON 
> BUYER_ACCOUNT.ACCOUNT_COUNTRY = BUYER_COUNTRY.COUNTRY
> JOIN "DEFAULT"."KYLIN_COUNTRY" AS "SELLER_COUNTRY" ON 
> SELLER_ACCOUNT.ACCOUNT_COUNTRY = SELLER_COUNTRY.COUNTRY
> WHERE KYLIN_CAL_DT.WEEK_BEG_DT >= date'2001-09-05'
> ORDER BY "TRANS_CNT" ASC
> LIMIT 10000
> User: ADMIN
> Success: true
> Duration: 2.742
> Project: learn_kylin
> Realization Names: [CUBE[name=kylin_sales_cube]]
> Cuboid Ids: [16384]
> Total scan count: 0
> Total scan bytes: 0
> Result row count: 1
> Accept Partial: true
> Is Partial Result: false
> Hit Exception Cache: false
> Storage cache used: false
> Is Query Push-Down: false
> Is Prepare: false
> Trace URL: null
> Message: null
> ==========================[QUERY]===============================



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to