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

Andreas Költringer commented on SPARK-28515:
--------------------------------------------

I used it with Python 3.7. But I don't think this is of any relevance here, b/c 
I'm not using any Python UDF's - the Python Code thus should be purely an 
interface to what happens inside the JVM.

> to_timestamp returns null for summer time switch dates
> ------------------------------------------------------
>
>                 Key: SPARK-28515
>                 URL: https://issues.apache.org/jira/browse/SPARK-28515
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 2.4.3
>         Environment: Spark 2.4.3 on Linux 64bit, openjdk-8-jre-headless
>            Reporter: Andreas Költringer
>            Priority: Major
>
> I am not sure if this is a bug - but it was a very unexpected behavior, so 
> I'd like some clarification.
> When parsing datetime-strings, when the date-time in question falls into the 
> range of a "summer time switch" (e.g. in (most of) Europe, on 2015-03-29 at 
> 2am the clock was forwarded to 3am), the {{to_timestamp}} method returns 
> {{NULL}}.
> Minimal Example (using Python):
> {code:java}
> >>> df = spark.createDataFrame([('201503290159',), ('201503290200',)], 
> >>> ['date_str'])
> >>> df.withColumn('timestamp', F.to_timestamp('date_str', 
> >>> 'yyyyMMddhhmm')).show()
> ---------------------------------+
> |    date_str|          timestamp|
> ---------------------------------+
> |201503290159|2015-03-29 01:59:00|
> |201503290200|               null|
> ---------------------------------+ {code}
> A solution (or workaround) is to set the time zone for Spark to UTC:
> {{spark.conf.set("spark.sql.session.timeZone", "UTC")}}
> (see e.g. [https://stackoverflow.com/q/52594762)]
> Plain Java does not do this, e.g. this works as expected:
>  
> {code:java}
> SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmm");
> Date parsedDate = dateFormat.parse("201503290201");
> Timestamp timestamp = new java.sql.Timestamp(parsedDate.getTime());{code}
> So, is this really the intended behaviour? Is there documentation about this? 
> THX.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to