Deepak Shingavi created SPARK-31873:
---------------------------------------

             Summary: Spark Sql Function year does not extract year from 
date/timestamp
                 Key: SPARK-31873
                 URL: https://issues.apache.org/jira/browse/SPARK-31873
             Project: Spark
          Issue Type: Bug
          Components: SQL
    Affects Versions: 2.4.5
            Reporter: Deepak Shingavi


There is a Spark SQL function

org.apache.spark.sql.functions.year which fails in below case


 
{code:java}
// Code to extract year from Timestamp
val df = Seq(
  ("1300-01-03 00:00:00")
).toDF("date_val")
  .withColumn("date_val_ts", to_timestamp(col("date_val")))
  .withColumn("year_val", year(to_timestamp(col("date_val"))))

df.show()
//Output of the above code
+-------------------+-------------------+--------+
|           date_val|        date_val_ts|year_val|
+-------------------+-------------------+--------+
|1300-01-03 00:00:00|1300-01-03 00:00:00|    1299|
+-------------------+-------------------+--------+

{code}
 

The above code works perfectly for all the years greater than 1300

 



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

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

Reply via email to