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 2016/01/04 10:20:06 UTC
kylin git commit: KYLIN-1282 Comparison filter on Date/Time column
not work for query
Repository: kylin
Updated Branches:
refs/heads/2.0-rc 47ff40e20 -> 47f20ed53
KYLIN-1282 Comparison filter on Date/Time column not work for query
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/47f20ed5
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/47f20ed5
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/47f20ed5
Branch: refs/heads/2.0-rc
Commit: 47f20ed5355144a9b5df7225ea1a4e1f1f6053f4
Parents: 47ff40e
Author: lidongsjtu <do...@ebay.com>
Authored: Mon Jan 4 16:46:06 2016 +0800
Committer: lidongsjtu <do...@ebay.com>
Committed: Mon Jan 4 17:19:51 2016 +0800
----------------------------------------------------------------------
.../apache/kylin/common/util/DateFormat.java | 14 +++++++
.../kylin/common/util/DateFormatTest.java | 44 ++++++++++++++++++++
.../filter/TimeConditionLiteralsReplacer.java | 9 +++-
query/src/test/resources/query/sql/query10.sql | 2 +-
4 files changed, 66 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/47f20ed5/core-common/src/main/java/org/apache/kylin/common/util/DateFormat.java
----------------------------------------------------------------------
diff --git a/core-common/src/main/java/org/apache/kylin/common/util/DateFormat.java b/core-common/src/main/java/org/apache/kylin/common/util/DateFormat.java
index 9fc3122..e2777e5 100644
--- a/core-common/src/main/java/org/apache/kylin/common/util/DateFormat.java
+++ b/core-common/src/main/java/org/apache/kylin/common/util/DateFormat.java
@@ -29,6 +29,7 @@ public class DateFormat {
public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd";
public static final String DEFAULT_DATETIME_PATTERN_WITHOUT_MILLISECONDS = "yyyy-MM-dd HH:mm:ss";
public static final String DEFAULT_DATETIME_PATTERN_WITH_MILLISECONDS = "yyyy-MM-dd HH:mm:ss.SSS";
+ public static final String[] SUPPORTED_DATETIME_PATTERN = { DEFAULT_DATE_PATTERN, DEFAULT_DATETIME_PATTERN_WITHOUT_MILLISECONDS, DEFAULT_DATETIME_PATTERN_WITH_MILLISECONDS, "yyyyMMdd" };
static final private Map<String, ThreadLocal<SimpleDateFormat>> threadLocalMap = new ConcurrentHashMap<String, ThreadLocal<SimpleDateFormat>>();
@@ -112,4 +113,17 @@ public class DateFormat {
return true;
}
+ public static boolean isSupportedDateFormat(String dateStr) {
+ assert dateStr != null;
+ for (String formatStr : SUPPORTED_DATETIME_PATTERN) {
+ try {
+ if (dateStr.equals(dateToString(stringToDate(dateStr, formatStr), formatStr))) {
+ return true;
+ }
+ } catch (Exception ex) {
+ continue;
+ }
+ }
+ return false;
+ }
}
http://git-wip-us.apache.org/repos/asf/kylin/blob/47f20ed5/core-common/src/test/java/org/apache/kylin/common/util/DateFormatTest.java
----------------------------------------------------------------------
diff --git a/core-common/src/test/java/org/apache/kylin/common/util/DateFormatTest.java b/core-common/src/test/java/org/apache/kylin/common/util/DateFormatTest.java
new file mode 100644
index 0000000..52888a3
--- /dev/null
+++ b/core-common/src/test/java/org/apache/kylin/common/util/DateFormatTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kylin.common.util;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Created by dongli on 1/4/16.
+ */
+public class DateFormatTest {
+
+ @Test
+ public void testIsSupportedDateFormat() {
+ assertTrue(DateFormat.isSupportedDateFormat("2010-01-01"));
+ assertTrue(DateFormat.isSupportedDateFormat("20100101"));
+ assertTrue(DateFormat.isSupportedDateFormat("2010-01-01 01:01:01"));
+ assertTrue(DateFormat.isSupportedDateFormat("2010-01-01 01:00:00.000"));
+
+ assertFalse(DateFormat.isSupportedDateFormat("2010-01"));
+ assertFalse(DateFormat.isSupportedDateFormat("2010/01/01"));
+ assertFalse(DateFormat.isSupportedDateFormat("2010-1-1"));
+ assertFalse(DateFormat.isSupportedDateFormat("abc"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/kylin/blob/47f20ed5/core-metadata/src/main/java/org/apache/kylin/metadata/filter/TimeConditionLiteralsReplacer.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/filter/TimeConditionLiteralsReplacer.java b/core-metadata/src/main/java/org/apache/kylin/metadata/filter/TimeConditionLiteralsReplacer.java
index e4bdf3d..20fbe7a 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/filter/TimeConditionLiteralsReplacer.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/filter/TimeConditionLiteralsReplacer.java
@@ -47,18 +47,23 @@ public class TimeConditionLiteralsReplacer implements TupleFilterSerializer.Deco
DataType columnType = dateCompareTupleChildren.get(filter);
for (String value : (Collection<String>) constantTupleFilter.getValues()) {
- newValues.add(formatTime(Long.valueOf(value), columnType));
+ newValues.add(formatTime(value, columnType));
}
return new ConstantTupleFilter(newValues);
}
return filter;
}
- private String formatTime(long millis, DataType dataType) {
+ private String formatTime(String dateStr, DataType dataType) {
if (dataType.isDatetime() || dataType.isTime()) {
throw new RuntimeException("Datetime and time type are not supported yet");
}
+ if (DateFormat.isSupportedDateFormat(dateStr)) {
+ return dateStr;
+ }
+
+ long millis = Long.valueOf(dateStr);
if (dataType.isTimestamp()) {
return DateFormat.formatToTimeStr(millis);
} else if (dataType.isDate()) {
http://git-wip-us.apache.org/repos/asf/kylin/blob/47f20ed5/query/src/test/resources/query/sql/query10.sql
----------------------------------------------------------------------
diff --git a/query/src/test/resources/query/sql/query10.sql b/query/src/test/resources/query/sql/query10.sql
index d67d3a4..ad86086 100644
--- a/query/src/test/resources/query/sql/query10.sql
+++ b/query/src/test/resources/query/sql/query10.sql
@@ -26,5 +26,5 @@ inner JOIN edw.test_cal_dt as test_cal_dt
inner JOIN edw.test_sites as test_sites
ON test_kylin_fact.lstg_site_id = test_sites.site_id
where test_kylin_fact.lstg_format_name='FP-GTC'
- and test_cal_dt.week_beg_dt between DATE '2013-05-01' and DATE '2013-08-01'
+ and test_cal_dt.week_beg_dt between '2013-05-01' and DATE '2013-08-01'
group by test_cal_dt.week_beg_dt