Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pyspark to_date()函数在Windows和WSL Ubuntu上给出了不同的答案_Windows_Datetime_Pyspark_Windows Subsystem For Linux - Fatal编程技术网

Pyspark to_date()函数在Windows和WSL Ubuntu上给出了不同的答案

Pyspark to_date()函数在Windows和WSL Ubuntu上给出了不同的答案,windows,datetime,pyspark,windows-subsystem-for-linux,Windows,Datetime,Pyspark,Windows Subsystem For Linux,我有一个函数,它将一个int转换成一个日期,然后将该日期输入datediff,以查找事件发生后的天数。我们的一个测试通过了PySpark Windows和Azure DevOps管道,但在WSL Ubuntu的PySpark上运行时失败。我们已经将其缩小到在两个平台上产生不同结果的to_date()函数,但不理解为什么 import pyspark.sql.functions as F import datetime def from_int_to_date(int_date: int) -&g

我有一个函数,它将一个int转换成一个日期,然后将该日期输入datediff,以查找事件发生后的天数。我们的一个测试通过了PySpark Windows和Azure DevOps管道,但在WSL Ubuntu的PySpark上运行时失败。我们已经将其缩小到在两个平台上产生不同结果的
to_date()
函数,但不理解为什么

import pyspark.sql.functions as F
import datetime
def from_int_to_date(int_date: int) -> datetime.datetime:
    """
    Convert an integer in YYYYMMDD format into a datetime object
    """
    return datetime.datetime.strptime(str(int_date), "%Y%m%d")

如果我计算
F.to_date(F.lit(从_int_到_date(20190401))
我在Windows上得到
列用配置
spark.sql.session.timezone
将时区设置为spark驱动程序,这样你就不会依赖系统时钟

spark.conf.set("spark.sql.session.timeZone", "Europe/London")

即使创建了spark会话,也可以解决此选项。

我的猜测是,一个系统的时区设置为UTC+0,另一个系统的时区设置为Europe/London(仅在冬季与UTC相同)。似乎有一种方法可以用来手动指定时区。(这是一个注释,不是答案,因为我不是100%确定,而且我对它的了解还不够,无法给出示例代码。)您也可以尝试设置环境变量
TZ
。非常感谢!你为我指明了正确的方向。我期望TZ从Windows映射到WSL,但显然这是一个已知的问题,它没有正确地发生。我已经按照这里的建议应用了时区修正,现在一切都过去了,这就是我刚刚要写的,阅读赏金名单上的标题。但是是的,谢里特应该得到赏金