0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PySparkでParquetを作るとTimeStampが勝手に時刻補正される

Posted at

以前、PySparkを利用してParquetファイルを作成した。
このとき、「TimeStamp型」の値が勝手に変更される事象に出くわしたので、解決方法をメモ。

目次

  1. 事象
  2. 解決策
  3. 結果
  4. 参考

1. 事象

分かりやすく対象表を。
Parquet変換前のTimeStampをそのまま出力したいのに、
なぜか+9時間されて作成されてしまう。
image.png

この手の問題は、タイムゾーンが絡んでいることが多いが
今回もタイムゾーンの設定が原因だった。

2. 解決策

spark-defaults.confというファイルに
タイムゾーンを記述しているコメント部分があるが、このコメントを外す
※confファイルは、sparkをインストールしたディレクトリ\spark-2.x.x-bin-hadoopx.x\conf\ 内にある

spark-defaults.conf(変更前)
# spark.driver.extraJavaOptions      -Duser.timezone=UTC
# spark.executor.extraJavaOptions    -Duser.timezone=UTC
spark-defaults.conf(変更後)
spark.driver.extraJavaOptions      -Duser.timezone=UTC
spark.executor.extraJavaOptions    -Duser.timezone=UTC

コメントを外したら上書き保存し、一度再起動すると良い
※僕の環境では、再起動するまで挙動がおかしかったため

3. 結果

spark-defaults.confを書き換えたら、タイムスタンプが変換されなくなりました。

4. 参考

Spark Strutured Streaming automatically converts timestamp to local time

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?