This is an automated email from the ASF dual-hosted git repository. shaofengshi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kylin.git
commit 7f2aa5ad3cbdac59763b7539f1d31bf099d51cb5 Author: chao long <wayn...@qq.com> AuthorDate: Tue Jul 17 19:11:40 2018 +0800 KYLIN-3186 expand partition-date-column format --- .../org/apache/kylin/common/util/DateFormat.java | 30 +++++++++++++++++++--- .../apache/kylin/metadata/model/PartitionDesc.java | 8 +++--- 2 files changed, 31 insertions(+), 7 deletions(-) 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 29858f1..5035e03 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 @@ -32,6 +32,11 @@ public class DateFormat { public static final String DEFAULT_TIME_PATTERN = "HH:mm:ss"; 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 YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm"; + public static final String YYYY_MM_DD_HH = "yyyy-MM-dd HH"; + public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; + public static final String YYYYMMDDHHMM = "yyyyMMddHHmm"; + public static final String YYYYMMDDHH = "yyyyMMddHH"; public static final String[] SUPPORTED_DATETIME_PATTERN = { // DEFAULT_DATE_PATTERN, // DEFAULT_DATETIME_PATTERN_WITHOUT_MILLISECONDS, // @@ -48,7 +53,7 @@ public class DateFormat { } return r; } - + public static String formatToCompactDateStr(long millis) { return formatToDateStr(millis, COMPACT_DATE_PATTERN); } @@ -94,13 +99,23 @@ public class DateFormat { public static long stringToMillis(String str) { // try to be smart and guess the date format if (isAllDigits(str)) { - if (str.length() == 8) + if (str.length() == 8 && isInputFormatDate(str, COMPACT_DATE_PATTERN)) //TODO: might be prolematic if an actual ts happends to be 8 digits, e.g. 1970-01-01 10:00:01.123 return stringToDate(str, COMPACT_DATE_PATTERN).getTime(); + else if (str.length() == 10 && isInputFormatDate(str, YYYYMMDDHH)) + return stringToDate(str, YYYYMMDDHH).getTime(); + else if (str.length() == 12 && isInputFormatDate(str, YYYYMMDDHHMM)) + return stringToDate(str, YYYYMMDDHHMM).getTime(); + else if (str.length() == 14 && isInputFormatDate(str, YYYYMMDDHHMMSS)) + return stringToDate(str, YYYYMMDDHHMMSS).getTime(); else return Long.parseLong(str); } else if (str.length() == 10) { return stringToDate(str, DEFAULT_DATE_PATTERN).getTime(); + } else if (str.length() == 13) { + return stringToDate(str, YYYY_MM_DD_HH).getTime(); + } else if (str.length() == 16) { + return stringToDate(str, YYYY_MM_DD_HH_MM).getTime(); } else if (str.length() == 19) { return stringToDate(str, DEFAULT_DATETIME_PATTERN_WITHOUT_MILLISECONDS).getTime(); } else if (str.length() > 19) { @@ -137,7 +152,16 @@ public class DateFormat { return false; } + public static boolean isInputFormatDate(String dateStr, String formatStr) { + try { + return dateStr.equals(dateToString(stringToDate(dateStr, formatStr), formatStr)); + } catch (Exception ex) { + return false; + } + } + public static boolean isDatePattern(String ptn) { - return COMPACT_DATE_PATTERN.equals(ptn) || DEFAULT_DATE_PATTERN.equals(ptn); + return COMPACT_DATE_PATTERN.equals(ptn) || YYYYMMDDHH.equals(ptn) || YYYYMMDDHHMM.equals(ptn) + || YYYYMMDDHHMMSS.equals(ptn); } } diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java b/core-metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java index 2f23bdc..b3bf6cc 100644 --- a/core-metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java +++ b/core-metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java @@ -199,7 +199,7 @@ public class PartitionDesc implements Serializable { StringBuilder builder = new StringBuilder(); if (partDesc.partitionColumnIsYmdInt()) { - buildSingleColumnRangeCondAsYmdInt(builder, partitionDateColumn, startInclusive, endExclusive); + buildSingleColumnRangeCondAsYmdInt(builder, partitionDateColumn, startInclusive, endExclusive, partDesc.getPartitionDateFormat()); } else if (partDesc.partitionColumnIsTimeMillis()) { buildSingleColumnRangeCondAsTimeMillis(builder, partitionDateColumn, startInclusive, endExclusive); } else if (partitionDateColumn != null && partitionTimeColumn == null) { @@ -225,13 +225,13 @@ public class PartitionDesc implements Serializable { } private static void buildSingleColumnRangeCondAsYmdInt(StringBuilder builder, TblColRef partitionColumn, - long startInclusive, long endExclusive) { + long startInclusive, long endExclusive, String partitionColumnDateFormat) { String partitionColumnName = partitionColumn.getIdentity(); builder.append(partitionColumnName + " >= " - + DateFormat.formatToDateStr(startInclusive, DateFormat.COMPACT_DATE_PATTERN)); + + DateFormat.formatToDateStr(startInclusive, partitionColumnDateFormat)); builder.append(" AND "); builder.append(partitionColumnName + " < " - + DateFormat.formatToDateStr(endExclusive, DateFormat.COMPACT_DATE_PATTERN)); + + DateFormat.formatToDateStr(endExclusive, partitionColumnDateFormat)); } private static void buildSingleColumnRangeCondition(StringBuilder builder, TblColRef partitionColumn,