Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E09A1200C1F for ; Fri, 3 Feb 2017 12:11:37 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id DF402160B48; Fri, 3 Feb 2017 11:11:37 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 170F2160B55 for ; Fri, 3 Feb 2017 12:11:36 +0100 (CET) Received: (qmail 29759 invoked by uid 500); 3 Feb 2017 11:11:35 -0000 Mailing-List: contact dev-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list dev@drill.apache.org Received: (qmail 29424 invoked by uid 99); 3 Feb 2017 11:11:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Feb 2017 11:11:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 35791DF9AB; Fri, 3 Feb 2017 11:11:35 +0000 (UTC) From: Serhii-Harnyk To: dev@drill.apache.org Reply-To: dev@drill.apache.org References: In-Reply-To: Subject: [GitHub] drill pull request #581: DRILL-4864: Add ANSI format for date/time functions Content-Type: text/plain Message-Id: <20170203111135.35791DF9AB@git1-us-west.apache.org> Date: Fri, 3 Feb 2017 11:11:35 +0000 (UTC) archived-at: Fri, 03 Feb 2017 11:11:38 -0000 Github user Serhii-Harnyk commented on a diff in the pull request: https://github.com/apache/drill/pull/581#discussion_r99313550 --- Diff: logical/src/main/java/org/apache/drill/common/expression/fn/JodaDateValidator.java --- @@ -0,0 +1,216 @@ +/* +* 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.drill.common.expression.fn; + +import com.google.common.collect.Sets; +import org.apache.commons.lang3.StringUtils; +import org.apache.drill.common.map.CaseInsensitiveMap; + +import java.util.Comparator; +import java.util.Set; + +public class JodaDateValidator { + + private static final Set postgresValuesForDeleting = Sets.newTreeSet(new LengthDescComparator()); + private static final CaseInsensitiveMap postgresToJodaMap = CaseInsensitiveMap.newTreeMap(new LengthDescComparator()); + + // tokens for deleting + public static final String SUFFIX_SP = "sp"; + public static final String PREFIX_FM = "fm"; + public static final String PREFIX_FX = "fx"; + public static final String PREFIX_TM = "tm"; + + // postgres patterns + public static final String POSTGRES_FULL_NAME_OF_DAY = "day"; + public static final String POSTGRES_DAY_OF_YEAR = "ddd"; + public static final String POSTGRES_DAY_OF_MONTH = "dd"; + public static final String POSTGRES_DAY_OF_WEEK = "d"; + public static final String POSTGRES_NAME_OF_MONTH = "month"; + public static final String POSTGRES_ABR_NAME_OF_MONTH = "mon"; + public static final String POSTGRES_FULL_ERA_NAME = "ee"; + public static final String POSTGRES_NAME_OF_DAY = "dy"; + public static final String POSTGRES_TIME_ZONE_NAME = "tz"; + public static final String POSTGRES_HOUR_12_NAME = "hh"; + public static final String POSTGRES_HOUR_12_OTHER_NAME = "hh12"; + public static final String POSTGRES_HOUR_24_NAME = "hh24"; + public static final String POSTGRES_MINUTE_OF_HOUR_NAME = "mi"; + public static final String POSTGRES_SECOND_OF_MINUTE_NAME = "ss"; + public static final String POSTGRES_MILLISECOND_OF_MINUTE_NAME = "ms"; + public static final String POSTGRES_WEEK_OF_YEAR = "ww"; + public static final String POSTGRES_MONTH = "mm"; + public static final String POSTGRES_HALFDAY_AM = "am"; + public static final String POSTGRES_HALFDAY_PM = "pm"; + + // jodaTime patterns + public static final String JODA_FULL_NAME_OF_DAY = "EEEE"; + public static final String JODA_DAY_OF_YEAR = "D"; + public static final String JODA_DAY_OF_MONTH = "d"; + public static final String JODA_DAY_OF_WEEK = "e"; + public static final String JODA_NAME_OF_MONTH = "MMMM"; + public static final String JODA_ABR_NAME_OF_MONTH = "MMM"; + public static final String JODA_FULL_ERA_NAME = "G"; + public static final String JODA_NAME_OF_DAY = "E"; + public static final String JODA_TIME_ZONE_NAME = "TZ"; + public static final String JODA_HOUR_12_NAME = "h"; + public static final String JODA_HOUR_12_OTHER_NAME = "h"; + public static final String JODA_HOUR_24_NAME = "H"; + public static final String JODA_MINUTE_OF_HOUR_NAME = "m"; + public static final String JODA_SECOND_OF_MINUTE_NAME = "s"; + public static final String JODA_MILLISECOND_OF_MINUTE_NAME = "SSS"; + public static final String JODA_WEEK_OF_YEAR = "w"; + public static final String JODA_MONTH = "MM"; + public static final String JODA_HALFDAY = "aa"; + + static { + postgresToJodaMap.put(POSTGRES_FULL_NAME_OF_DAY, JODA_FULL_NAME_OF_DAY); + postgresToJodaMap.put(POSTGRES_DAY_OF_YEAR, JODA_DAY_OF_YEAR); + postgresToJodaMap.put(POSTGRES_DAY_OF_MONTH, JODA_DAY_OF_MONTH); + postgresToJodaMap.put(POSTGRES_DAY_OF_WEEK, JODA_DAY_OF_WEEK); + postgresToJodaMap.put(POSTGRES_NAME_OF_MONTH, JODA_NAME_OF_MONTH); + postgresToJodaMap.put(POSTGRES_ABR_NAME_OF_MONTH, JODA_ABR_NAME_OF_MONTH); + postgresToJodaMap.put(POSTGRES_FULL_ERA_NAME, JODA_FULL_ERA_NAME); + postgresToJodaMap.put(POSTGRES_NAME_OF_DAY, JODA_NAME_OF_DAY); + postgresToJodaMap.put(POSTGRES_TIME_ZONE_NAME, JODA_TIME_ZONE_NAME); + postgresToJodaMap.put(POSTGRES_HOUR_12_NAME, JODA_HOUR_12_NAME); + postgresToJodaMap.put(POSTGRES_HOUR_12_OTHER_NAME, JODA_HOUR_12_OTHER_NAME); + postgresToJodaMap.put(POSTGRES_HOUR_24_NAME, JODA_HOUR_24_NAME); + postgresToJodaMap.put(POSTGRES_MINUTE_OF_HOUR_NAME, JODA_MINUTE_OF_HOUR_NAME); + postgresToJodaMap.put(POSTGRES_SECOND_OF_MINUTE_NAME, JODA_SECOND_OF_MINUTE_NAME); + postgresToJodaMap.put(POSTGRES_MILLISECOND_OF_MINUTE_NAME, JODA_MILLISECOND_OF_MINUTE_NAME); + postgresToJodaMap.put(POSTGRES_WEEK_OF_YEAR, JODA_WEEK_OF_YEAR); + postgresToJodaMap.put(POSTGRES_MONTH, JODA_MONTH); + postgresToJodaMap.put(POSTGRES_HALFDAY_AM, JODA_HALFDAY); + postgresToJodaMap.put(POSTGRES_HALFDAY_PM, JODA_HALFDAY); + } + + static { + postgresValuesForDeleting.add(SUFFIX_SP); + postgresValuesForDeleting.add(PREFIX_FM); + postgresValuesForDeleting.add(PREFIX_FX); + postgresValuesForDeleting.add(PREFIX_TM); + } + + /** + * Replaces all postgres patterns from {@param pattern}, + * available in postgresToJodaMap keys to jodaTime equivalents. + * + * @param pattern date pattern in postgres format + * @return date pattern with replaced patterns in joda format + */ + public static String toJodaFormat(String pattern) { --- End diff -- Yes, you are right. We limited by the set of the date patterns that supports JodaTime. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---