Spark spark.sql.session.timeZone doesn't work with JSON source

3.1k Views Asked by At

Does Spark v2.3.1 depends on local timezone when reading from JSON file?

My src/test/resources/data/tmp.json:

[
  {
    "timestamp": "1970-01-01 00:00:00.000"
  }
]

and Spark code:

SparkSession.builder()
    .appName("test")
    .master("local")
    .config("spark.sql.session.timeZone", "UTC")
    .getOrCreate()
    .read()
    .option("multiLine", true).option("mode", "PERMISSIVE")
    .schema(new StructType()
        .add(new StructField("timestamp", DataTypes.TimestampType, true, Metadata.empty())))
    .json("src/test/resources/data/tmp.json")
    .show();

Result:

+-------------------+
|          timestamp|
+-------------------+
|1969-12-31 22:00:00|
+-------------------+

How to make spark return 1970-01-01 00:00:00.000?

P.S. This question is not a duplicate of Spark Strutured Streaming automatically converts timestamp to local time, because provided there solution not work for me and is already included (see .config("spark.sql.session.timeZone", "UTC")) into my question.

0

There are 0 best solutions below