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









up vote
2
down vote

favorite












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.










share|improve this question























  • Could you confirm that org.apache.spark.sql.RuntimeConfig actually reflects the configuration? Does the other solution fix the problem?
    – user6910411
    Nov 11 at 18:57










  • Actually nevermind. Setting user.timezone does solve the problem. As of this it qualifies for JIRA ticket, if there isn't one already. The behavior is not only confusing, but also inconsistent between different data sources.
    – user6910411
    Nov 11 at 19:31






  • 1




    @user6910411 solved with TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
    – VB_
    Nov 11 at 21:13






  • 1




    That however, wont' help you in a distributed mode.
    – user6910411
    Nov 12 at 11:14










  • @user6910411 yeah, good point
    – VB_
    Nov 12 at 11:51














up vote
2
down vote

favorite












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.










share|improve this question























  • Could you confirm that org.apache.spark.sql.RuntimeConfig actually reflects the configuration? Does the other solution fix the problem?
    – user6910411
    Nov 11 at 18:57










  • Actually nevermind. Setting user.timezone does solve the problem. As of this it qualifies for JIRA ticket, if there isn't one already. The behavior is not only confusing, but also inconsistent between different data sources.
    – user6910411
    Nov 11 at 19:31






  • 1




    @user6910411 solved with TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
    – VB_
    Nov 11 at 21:13






  • 1




    That however, wont' help you in a distributed mode.
    – user6910411
    Nov 12 at 11:14










  • @user6910411 yeah, good point
    – VB_
    Nov 12 at 11:51












up vote
2
down vote

favorite









up vote
2
down vote

favorite











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.










share|improve this question















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.







apache-spark apache-spark-sql apache-spark-2.3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 20:55









Community

11




11










asked Nov 11 at 17:44









VB_

18.5k2279159




18.5k2279159











  • Could you confirm that org.apache.spark.sql.RuntimeConfig actually reflects the configuration? Does the other solution fix the problem?
    – user6910411
    Nov 11 at 18:57










  • Actually nevermind. Setting user.timezone does solve the problem. As of this it qualifies for JIRA ticket, if there isn't one already. The behavior is not only confusing, but also inconsistent between different data sources.
    – user6910411
    Nov 11 at 19:31






  • 1




    @user6910411 solved with TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
    – VB_
    Nov 11 at 21:13






  • 1




    That however, wont' help you in a distributed mode.
    – user6910411
    Nov 12 at 11:14










  • @user6910411 yeah, good point
    – VB_
    Nov 12 at 11:51
















  • Could you confirm that org.apache.spark.sql.RuntimeConfig actually reflects the configuration? Does the other solution fix the problem?
    – user6910411
    Nov 11 at 18:57










  • Actually nevermind. Setting user.timezone does solve the problem. As of this it qualifies for JIRA ticket, if there isn't one already. The behavior is not only confusing, but also inconsistent between different data sources.
    – user6910411
    Nov 11 at 19:31






  • 1




    @user6910411 solved with TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
    – VB_
    Nov 11 at 21:13






  • 1




    That however, wont' help you in a distributed mode.
    – user6910411
    Nov 12 at 11:14










  • @user6910411 yeah, good point
    – VB_
    Nov 12 at 11:51















Could you confirm that org.apache.spark.sql.RuntimeConfig actually reflects the configuration? Does the other solution fix the problem?
– user6910411
Nov 11 at 18:57




Could you confirm that org.apache.spark.sql.RuntimeConfig actually reflects the configuration? Does the other solution fix the problem?
– user6910411
Nov 11 at 18:57












Actually nevermind. Setting user.timezone does solve the problem. As of this it qualifies for JIRA ticket, if there isn't one already. The behavior is not only confusing, but also inconsistent between different data sources.
– user6910411
Nov 11 at 19:31




Actually nevermind. Setting user.timezone does solve the problem. As of this it qualifies for JIRA ticket, if there isn't one already. The behavior is not only confusing, but also inconsistent between different data sources.
– user6910411
Nov 11 at 19:31




1




1




@user6910411 solved with TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
– VB_
Nov 11 at 21:13




@user6910411 solved with TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
– VB_
Nov 11 at 21:13




1




1




That however, wont' help you in a distributed mode.
– user6910411
Nov 12 at 11:14




That however, wont' help you in a distributed mode.
– user6910411
Nov 12 at 11:14












@user6910411 yeah, good point
– VB_
Nov 12 at 11:51




@user6910411 yeah, good point
– VB_
Nov 12 at 11:51

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251473%2fspark-spark-sql-session-timezone-doesnt-work-with-json-source%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251473%2fspark-spark-sql-session-timezone-doesnt-work-with-json-source%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto