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

Peter Vary commented on HIVE-17230:
-----------------------------------

The root cause of the issue is, that HiveCLI writes out the value with 
TimestampWritable.toString() method which specifically changes the output of 
the timeStamp.toString() for an unknown reason since the "inception" of this 
code :)
{code:title=TimestampWritable}
  @Override
  public String toString() {
    if (timestampEmpty) {
      populateTimestamp();
    }

    String timestampString = timestamp.toString();
    if (timestampString.length() > 19) {
      if (timestampString.length() == 21) {
        if (timestampString.substring(19).compareTo(".0") == 0) {
          return threadLocalDateFormat.get().format(timestamp);
        }
      }
      return threadLocalDateFormat.get().format(timestamp) + 
timestampString.substring(19);
    }

    return threadLocalDateFormat.get().format(timestamp);
  }
{code}

The BeeLine receives a Timestamp object and calls it's toString without any 
changes:
{code:title=org.apache.hive.beeline.Rows}
    Row(int size, ResultSet rs) throws SQLException {
[..]
      for (int i = 0; i < size; i++) {
        if (numberFormat != null) {
          Object o = rs.getObject(i + 1);
          if (o == null) {
            values[i] = null;
          }  else if (o instanceof Number) {
            values[i] = numberFormat.format(o);
          } else {
            values[i] = o.toString();       <--- This row prints out the 
Timestamp object
          }
        } else {
          values[i] = rs.getString(i + 1);
        }
        values[i] = values[i] == null ? nullStr : values[i];
        sizes[i] = values[i].length();
      }
    }
{code}

> Timestamp format different in HiveCLI and Beeline
> -------------------------------------------------
>
>                 Key: HIVE-17230
>                 URL: https://issues.apache.org/jira/browse/HIVE-17230
>             Project: Hive
>          Issue Type: Bug
>          Components: Beeline, CLI
>            Reporter: Peter Vary
>            Assignee: Peter Vary
>
> The issue can be reproduced with the following commands:
> {code}
> create table timestamp_test(t timestamp);
> insert into table timestamp_test values('2000-01-01 01:00:00');
> select * from timestamp_test;
> {code}
> The timestamp is displayed without nanoseconds in HiveCLI:
> {code}
> 2000-01-01 01:00:00
> {code}
> When the exact same timestamp is displayed in BeeLine it displays:
> {code}
> 2000-01-01 01:00:00.0
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to