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

David Mollitor commented on HIVE-22762:
---------------------------------------

{code:java}
// add @throws JavaDoc
private Timestamp getTimestampFromValues(List<Integer> temporalValues) {
  if (temporalTokens.size() != temporalValues.size()) {
    // use Guava Preconditions.checkState(boolean)
  }

  // Use parameters for ImmutablePair here (and removed future casts)
  List<ImmutablePair> tokensList = new ArrayList<>();

  // Instead of sorting then reversing, just sort in reverse order :)
  // 
https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#reverseOrder-java.util.Comparator-
  tokensList.sort((Comparator<Object>) (o1, o2) -> {
     Token token1 = ((ImmutablePair<Token, Integer>) o1).left;
      Token token2 = ((ImmutablePair<Token, Integer>) o2).left;
      return token1.temporalField.getBaseUnit().getDuration()
          .compareTo(token2.temporalField.getBaseUnit().getDuration());
    });
    Collections.reverse(tokensList);
}
{code}

Rather than adding a new token list that captures all the temporal tokens, I 
would rather see that the method accept a list of tokens and a list of values.  
The tokens can be filtered and sorted in the method.  This way there is only 
ever a single list to keep track of and users (methods) can filter however they 
want on the fly.

{code:java}
List<String> tokens = temporalTokens.stream()
                .filter(token-> isNumericTemporalToken(token.type) || 
isCharacterTemporalToken(token.type))
                .collect(Collectors.toList());
{code}

> Leap day is incorrectly parsed during cast in Hive
> --------------------------------------------------
>
>                 Key: HIVE-22762
>                 URL: https://issues.apache.org/jira/browse/HIVE-22762
>             Project: Hive
>          Issue Type: Bug
>          Components: HiveServer2
>            Reporter: Karen Coppage
>            Assignee: Karen Coppage
>            Priority: Minor
>             Fix For: 4.0.0
>
>         Attachments: HIVE-22762.01.patch, HIVE-22762.01.patch, 
> HIVE-22762.01.patch, HIVE-22762.01.patch, HIVE-22762.02.patch, 
> HIVE-22762.03.patch, HIVE-22762.03.patch
>
>
> While casting a string to a date with a custom date format having day token 
> before year and moth tokens, the date is parsed incorrectly for leap days.
> h3. How to reproduce
> Execute {code}select cast("29 02 0" as date format "dd mm rr"){code} with 
> Hive. The query  results in *2020-02-28*, incorrectly.
> ----
> Executing the another cast with a slightly modified representation of the 
> date (day is preceded by year and moth) is however correctly parsed:
> {code}select cast("0 02 29" as date format "rr mm dd"){code}
> It returns *2020-02-29*.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to