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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to