You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Qiu Wenxiang (Jira)" <ji...@apache.org> on 2020/08/12 15:59:00 UTC

[jira] [Created] (SPARK-32602) Data with date type are saved into hive table with wrong value '1970-01-01'

Qiu Wenxiang created SPARK-32602:
------------------------------------

             Summary: Data with date type are saved into hive table with wrong value '1970-01-01'
                 Key: SPARK-32602
                 URL: https://issues.apache.org/jira/browse/SPARK-32602
             Project: Spark
          Issue Type: Bug
          Components: SQL
    Affects Versions: 3.0.0
            Reporter: Qiu Wenxiang


 

How to reproduce:
{code:java}
scala> spark.sql("create table t1(d date)")
res2: org.apache.spark.sql.DataFrame = []
scala> spark.sql("insert into table t1 values(cast('2020-08-09' as date))")
res3: org.apache.spark.sql.DataFrame = []
scala> spark.sql("select d from t1").show
+----------+
|         d|
+----------+
|1970-01-01|
+----------+  
{code}
 

Spark 3.0 introduced DaysWritable which extends DateWrite from hive to handle date type. DaysWritable.toString() is called to write its value into hive table. DateWrite.toString() is defined as:

 
{code:java}
@Override
public String toString() {
 // For toString, the time does not matter
 return get(false).toString();
}

public Date get(boolean doesTimeMatter) {
  return new Date(daysToMillis(daysSinceEpoch, doesTimeMatter));
}
{code}
 

DaysWritable didn't override toString(), neither get(boolean doesTimeMatter)。It did override get():
{code:java}
override def get(): Date = new Date(DateWritable.daysToMillis(julianDays))
{code}
but this didn't help with toString(), so with daysSinceEpoch in DateWritable always as 0, calls to DaysWritable.toString() will always return '1970-01-01', and as a result date value stored into hive table will always have value '1970-01-01'。



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

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org