Skip to content

Commit 600319d

Browse files
MaxGekkcloud-fan
authored andcommitted
[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.gekk@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
1 parent 3bd10ce commit 600319d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/HiveResult.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ object HiveResult {
5959
.map(_.mkString("\t"))
6060
}
6161

62-
private lazy val zoneId = DateTimeUtils.getZoneId(SQLConf.get.sessionLocalTimeZone)
63-
private lazy val dateFormatter = DateFormatter(zoneId)
64-
private lazy val timestampFormatter = TimestampFormatter.getFractionFormatter(zoneId)
62+
private def zoneId = DateTimeUtils.getZoneId(SQLConf.get.sessionLocalTimeZone)
63+
private def dateFormatter = DateFormatter(zoneId)
64+
private def timestampFormatter = TimestampFormatter.getFractionFormatter(zoneId)
6565

6666
/** Formats a datum (based on the given data type) and returns the string representation. */
6767
def toHiveString(a: (Any, DataType), nested: Boolean = false): String = a match {

0 commit comments

Comments
 (0)