更改 sparklyr 中的 JVM 时区

changing the JVM timezone in sparklyr

我拼命地尝试在 Sparklyr 中更改 JVM 的时区(使用 spark 2.1.0)。我想要 GMT 无处不在。

我正在设置:

config$`driver.extraJavaOptions` <-"Duser.timezone=GMT"

在我的 spark_config() 文件中,但不幸的是,在 Spark UI 中,我仍然看到(在系统属性下)user.timezone 设置为 America/New_York.

有什么想法吗? 谢谢!

几件事:

  • 属性 的名称是 spark.driver.extraJavaOptions
  • 该值缺少前导 -。应该是 -Duser.timezone=GMT.
  • 为了保持一致性,您需要 spark.driver.extraJavaOptionsspark.executor.extraJavaOptions
  • 一般情况下 spark.driver.extraJavaOptions 和类似的属性应该在应用程序之外设置。如 the official documentation 中所述:

    In client mode, this config must not be set through the SparkConf directly in your application, because the driver JVM has already started at that point. Instead, please set this through the --driver-java-options command line option or in your default properties file.

    在驱动程序上调用 corresponding Java methods 应该有效

    # sc is spark_shell_connection / spark_connection
    sparklyr::invoke_static(sc, "java.util.TimeZone",  "getTimeZone", "GMT") %>%
      sparklyr::invoke_static(sc, "java.util.TimeZone", "setDefault", .)
    

    但可能不会反映在 UI 中,您仍然需要 spark.executor.extraJavaOptions

一般情况下,您应该在配置目录中编辑 spark-defualts.conf 以包含

spark.driver.extraJavaOptions -Duser.timezone=GMT
spark.executor.extraJavaOptions -Duser.timezone=GMT

如果您无法修改主要配置,您可以创建一个应用程序特定目录并使用 SPARK_CONF_DIR 环境指向它 variabl.e

在最近的版本中,您还可以在应用程序本身中设置 spark.sql.session.timeZone(请注意,它不同于相应的 JVM 选项,并且仅影响 Spark 查询)。