This is an automated email from the ASF dual-hosted git repository.

wenchen pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new b7810dd  [SPARK-31254][SQL] Use the current session time zone in 
`HiveResult.toHiveString`
b7810dd is described below

commit b7810dd6c6a67dfda307763af8ca13ce4a6f1f99
Author: Maxim Gekk <max.g...@gmail.com>
AuthorDate: Thu Mar 26 17:45:29 2020 +0800

    [SPARK-31254][SQL] Use the current session time zone in 
`HiveResult.toHiveString`
    
    ### What changes were proposed in this pull request?
    In the PR, I propose to define `timestampFormatter`, `dateFormatter` and 
`zoneId` as methods of the `HiveResult` object. This should guarantee that the 
formatters pick the current session time zone in `toHiveString()`
    
    ### Why are the changes needed?
    Currently, date/timestamp formatters in `HiveResult.toHiveString` are 
initialized once on instantiation of the `HiveResult` object, and pick up the 
session time zone. If the sessions time zone is changed, the formatters still 
use the previous one.
    
    ### Does this PR introduce any user-facing change?
    Yes
    
    ### How was this patch tested?
    By existing test suites, in particular, by `HiveResultSuite`
    
    Closes #28024 from MaxGekk/hive-result-datetime-formatters.
    
    Authored-by: Maxim Gekk <max.g...@gmail.com>
    Signed-off-by: Wenchen Fan <wenc...@databricks.com>
    (cherry picked from commit 600319dcb977827028327f9395644ae3d492e0fe)
    Signed-off-by: Wenchen Fan <wenc...@databricks.com>
---
 .../src/main/scala/org/apache/spark/sql/execution/HiveResult.scala  | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git 
a/sql/core/src/main/scala/org/apache/spark/sql/execution/HiveResult.scala 
b/sql/core/src/main/scala/org/apache/spark/sql/execution/HiveResult.scala
index 5a2f16d..ff820bf 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/HiveResult.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/HiveResult.scala
@@ -59,9 +59,9 @@ object HiveResult {
         .map(_.mkString("\t"))
   }
 
-  private lazy val zoneId = 
DateTimeUtils.getZoneId(SQLConf.get.sessionLocalTimeZone)
-  private lazy val dateFormatter = DateFormatter(zoneId)
-  private lazy val timestampFormatter = 
TimestampFormatter.getFractionFormatter(zoneId)
+  private def zoneId = 
DateTimeUtils.getZoneId(SQLConf.get.sessionLocalTimeZone)
+  private def dateFormatter = DateFormatter(zoneId)
+  private def timestampFormatter = 
TimestampFormatter.getFractionFormatter(zoneId)
 
   /** Formats a datum (based on the given data type) and returns the string 
representation. */
   def toHiveString(a: (Any, DataType), nested: Boolean = false): String = a 
match {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to