Skip to content
Closed
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
ba506a2
Move TimeZoneGMT/UTC to DateTimeTestUtils
MaxGekk Feb 17, 2020
6933070
Remove TimeZoneGMT
MaxGekk Feb 17, 2020
e195d25
gmtId -> utcId
MaxGekk Feb 17, 2020
cf620cb
Remove defaultTimeZone
MaxGekk Feb 17, 2020
b487933
Use Date/TimestampType.InternalType
MaxGekk Feb 17, 2020
b26730c
Use TimeZoneUTC
MaxGekk Feb 17, 2020
0b5711e
Use TimeZoneUTC instead of GMT
MaxGekk Feb 17, 2020
9ba2d3d
Remove SQLDate and SQLTimestamp
MaxGekk Feb 21, 2020
c475f27
Improve a comment
MaxGekk Feb 21, 2020
cbf69fb
Renaming
MaxGekk Feb 21, 2020
dde714b
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Feb 24, 2020
6840291
Fix import
MaxGekk Feb 24, 2020
6a41a3c
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Feb 25, 2020
86ccef1
Fix merge
MaxGekk Feb 26, 2020
1fd3aa2
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Mar 11, 2020
51e0bf1
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Mar 12, 2020
54c0fe9
Fix merge issues
MaxGekk Mar 12, 2020
43246af
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Mar 17, 2020
e12ec28
Fix merge issues
MaxGekk Mar 17, 2020
8cf53c5
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Mar 19, 2020
9d78a7d
Restore TimeZoneUTC in DateTimeUtils
MaxGekk Mar 19, 2020
d45dd85
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Mar 20, 2020
8669e29
Fix merge issue
MaxGekk Mar 20, 2020
aa8a62f
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Mar 23, 2020
0075718
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Mar 24, 2020
9ec98eb
Fix merge issue
MaxGekk Mar 24, 2020
2ca2540
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Mar 26, 2020
d7f343b
Fix merge issues
MaxGekk Mar 26, 2020
aa2059a
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Mar 28, 2020
3b23c52
Fix merge issues
MaxGekk Mar 28, 2020
f79e7b6
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Apr 10, 2020
3215948
Fix merge conflicts
MaxGekk Apr 10, 2020
77a780f
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Apr 15, 2020
7dea87d
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Apr 25, 2020
28c8443
Fix merge conflicts
MaxGekk Apr 25, 2020
113d9a9
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Apr 27, 2020
70a057f
Fix merge conflicts
MaxGekk Apr 27, 2020
a9e73db
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Apr 30, 2020
5dfa257
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk May 14, 2020
1eb480a
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk May 21, 2020
9c53d3d
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk May 29, 2020
b43fe03
Avoid one `*` in fromJulianDay
MaxGekk May 29, 2020
61b85ac
Use toTotalMonths in subtractDates
MaxGekk May 29, 2020
311a47e
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Jun 10, 2020
6c084a1
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Jun 12, 2020
6e7aa16
Merge remote-tracking branch 'remotes/origin/master' into move-time-z…
MaxGekk Jun 16, 2020
b18859a
Resolve merge issue
MaxGekk Jun 16, 2020
f477a71
Remove timestampToString()
MaxGekk Jun 18, 2020
ec386b7
Remove microsToEpochDays() and epochDaysToMicros()
MaxGekk Jun 18, 2020
cf85866
Re-use getLocalDateTime in convertTz
MaxGekk Jun 18, 2020
89d7fad
Re-use getLocalDateTime
MaxGekk Jun 18, 2020
d9699c4
Remove julianCommonEraStart
MaxGekk Jun 18, 2020
d261ba7
Remove instantToDays
MaxGekk Jun 18, 2020
53a33da
Make splitDate private
MaxGekk Jun 18, 2020
ee91211
Remove def daysToMicros(days: Int): Long
MaxGekk Jun 18, 2020
386f6cf
Remove def microsToDays(micros: Long): Int
MaxGekk Jun 18, 2020
c47d522
1.1.1970 -> 1970-01-01
MaxGekk Jun 18, 2020
025ea80
1970-01-01 00:00:00 -> 1970-01-01 00:00:00Z
MaxGekk Jun 18, 2020
8a7ac3f
Make Scala style checker happy
MaxGekk Jun 18, 2020
863d747
Update comments
MaxGekk Jun 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class MicrosCalendar(tz: TimeZone, digitsInFraction: Int)
// Converts parsed `MILLISECOND` field to seconds fraction in microsecond precision.
// For example if the fraction pattern is `SSSS` then `digitsInFraction` = 4, and
// if the `MILLISECOND` field was parsed to `1234`.
def getMicros(): SQLTimestamp = {
def getMicros(): Long = {
// Append 6 zeros to the field: 1234 -> 1234000000
val d = fields(Calendar.MILLISECOND) * MICROS_PER_SECOND
// Take the first 6 digits from `d`: 1234000000 -> 123400
Expand Down Expand Up @@ -149,7 +149,7 @@ class LegacyFastTimestampFormatter(
fastDateFormat.getTimeZone,
fastDateFormat.getPattern.count(_ == 'S'))

def parse(s: String): SQLTimestamp = {
def parse(s: String): Long = {
cal.clear() // Clear the calendar because it can be re-used many times
if (!fastDateFormat.parse(s, new ParsePosition(0), cal)) {
throw new IllegalArgumentException(s"'$s' is an invalid timestamp")
Expand All @@ -160,7 +160,7 @@ class LegacyFastTimestampFormatter(
rebaseJulianToGregorianMicros(julianMicros)
}

def format(timestamp: SQLTimestamp): String = {
def format(timestamp: Long): String = {
Comment thread
MaxGekk marked this conversation as resolved.
Outdated
val julianMicros = rebaseGregorianToJulianMicros(timestamp)
cal.setTimeInMillis(Math.floorDiv(julianMicros, MICROS_PER_SECOND) * MILLIS_PER_SECOND)
cal.setMicros(Math.floorMod(julianMicros, MICROS_PER_SECOND))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import org.apache.spark.sql.catalyst.expressions.aggregate.{CollectList, Collect
import org.apache.spark.sql.catalyst.expressions.codegen.CodegenContext
import org.apache.spark.sql.catalyst.util.DateTimeConstants._
import org.apache.spark.sql.catalyst.util.DateTimeTestUtils._
import org.apache.spark.sql.catalyst.util.DateTimeUtils
import org.apache.spark.sql.catalyst.util.DateTimeUtils._
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._
Expand Down Expand Up @@ -268,13 +267,13 @@ abstract class CastSuiteBase extends SparkFunSuite with ExpressionEvalHelper {

for (tz <- ALL_TIMEZONES) {
val timeZoneId = Option(tz.getId)
var c = Calendar.getInstance(TimeZoneGMT)
var c = Calendar.getInstance(TimeZoneUTC)
c.set(2015, 2, 8, 2, 30, 0)
checkEvaluation(
cast(cast(new Timestamp(c.getTimeInMillis), StringType, timeZoneId),
TimestampType, timeZoneId),
millisToMicros(c.getTimeInMillis))
c = Calendar.getInstance(TimeZoneGMT)
c = Calendar.getInstance(TimeZoneUTC)
c.set(2015, 10, 1, 2, 30, 0)
checkEvaluation(
cast(cast(new Timestamp(c.getTimeInMillis), StringType, timeZoneId),
Expand All @@ -291,7 +290,7 @@ abstract class CastSuiteBase extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(cast(cast(nts, TimestampType, UTC_OPT), StringType, UTC_OPT), nts)
checkEvaluation(
cast(cast(ts, StringType, UTC_OPT), TimestampType, UTC_OPT),
DateTimeUtils.fromJavaTimestamp(ts))
fromJavaTimestamp(ts))

// all convert to string type to check
checkEvaluation(
Expand Down Expand Up @@ -378,11 +377,11 @@ abstract class CastSuiteBase extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(cast(ts, FloatType), 15.003f)
checkEvaluation(cast(ts, DoubleType), 15.003)
checkEvaluation(cast(cast(tss, ShortType), TimestampType),
DateTimeUtils.fromJavaTimestamp(ts) * MILLIS_PER_SECOND)
fromJavaTimestamp(ts) * MILLIS_PER_SECOND)
checkEvaluation(cast(cast(tss, IntegerType), TimestampType),
DateTimeUtils.fromJavaTimestamp(ts) * MILLIS_PER_SECOND)
fromJavaTimestamp(ts) * MILLIS_PER_SECOND)
checkEvaluation(cast(cast(tss, LongType), TimestampType),
DateTimeUtils.fromJavaTimestamp(ts) * MILLIS_PER_SECOND)
fromJavaTimestamp(ts) * MILLIS_PER_SECOND)
checkEvaluation(
cast(cast(millis.toFloat / MILLIS_PER_SECOND, TimestampType), FloatType),
millis.toFloat / MILLIS_PER_SECOND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class CsvExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with P
val schema = StructType(StructField("t", TimestampType) :: Nil)

val csvData1 = "2016-01-01T00:00:00.123Z"
var c = Calendar.getInstance(DateTimeUtils.TimeZoneGMT)
var c = Calendar.getInstance(DateTimeUtils.TimeZoneUTC)
c.set(2016, 0, 1, 0, 0, 0)
c.set(Calendar.MILLISECOND, 123)
checkEvaluation(
Expand Down Expand Up @@ -184,7 +184,7 @@ class CsvExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with P

test("to_csv with timestamp") {
val schema = StructType(StructField("t", TimestampType) :: Nil)
val c = Calendar.getInstance(DateTimeUtils.TimeZoneGMT)
val c = Calendar.getInstance(DateTimeUtils.TimeZoneUTC)
c.set(2016, 0, 1, 0, 0, 0)
c.set(Calendar.MILLISECOND, 0)
val struct = Literal.create(create_row(c.getTimeInMillis * 1000L), schema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.apache.spark.sql.catalyst.expressions.codegen.GenerateUnsafeProjectio
import org.apache.spark.sql.catalyst.util.{DateTimeUtils, IntervalUtils, TimestampFormatter}
import org.apache.spark.sql.catalyst.util.DateTimeConstants._
import org.apache.spark.sql.catalyst.util.DateTimeTestUtils._
import org.apache.spark.sql.catalyst.util.DateTimeUtils.TimeZoneUTC
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._
import org.apache.spark.unsafe.types.{CalendarInterval, UTF8String}
Expand Down Expand Up @@ -803,7 +804,7 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
val sdf2 = new SimpleDateFormat(fmt2, Locale.US)
val fmt3 = "yy-MM-dd"
val sdf3 = new SimpleDateFormat(fmt3, Locale.US)
sdf3.setTimeZone(TimeZone.getTimeZone(UTC))
sdf3.setTimeZone(TimeZoneUTC)

withDefaultTimeZone(UTC) {
for (zid <- outstandingZoneIds) {
Expand Down Expand Up @@ -874,7 +875,7 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
val sdf2 = new SimpleDateFormat(fmt2, Locale.US)
val fmt3 = "yy-MM-dd"
val sdf3 = new SimpleDateFormat(fmt3, Locale.US)
sdf3.setTimeZone(TimeZone.getTimeZone(UTC))
sdf3.setTimeZone(TimeZoneUTC)

withDefaultTimeZone(UTC) {
for (zid <- outstandingZoneIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ class ObjectExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
"fromPrimitiveArray", ObjectType(classOf[Array[Int]]),
Array[Int](1, 2, 3), UnsafeArrayData.fromPrimitiveArray(Array[Int](1, 2, 3))),
(DateTimeUtils.getClass, ObjectType(classOf[Date]),
"toJavaDate", ObjectType(classOf[DateTimeUtils.SQLDate]), 77777,
"toJavaDate", ObjectType(classOf[Int]), 77777,
DateTimeUtils.toJavaDate(77777)),
(DateTimeUtils.getClass, ObjectType(classOf[Timestamp]),
"toJavaTimestamp", ObjectType(classOf[DateTimeUtils.SQLTimestamp]),
"toJavaTimestamp", ObjectType(classOf[Long]),
88888888.toLong, DateTimeUtils.toJavaTimestamp(88888888))
).foreach { case (cls, dataType, methodName, argType, arg, expected) =>
checkObjectExprEvaluation(StaticInvoke(cls, dataType, methodName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import org.apache.spark.sql.types._

class JacksonGeneratorSuite extends SparkFunSuite {

val gmtId = DateTimeUtils.TimeZoneGMT.getID
val option = new JSONOptions(Map.empty, gmtId)
val utcId = DateTimeUtils.TimeZoneUTC.getID
val option = new JSONOptions(Map.empty, utcId)

test("initial with StructType and write out a row") {
val dataType = StructType(StructField("a", IntegerType) :: Nil)
Expand All @@ -45,7 +45,7 @@ class JacksonGeneratorSuite extends SparkFunSuite {
val input = InternalRow(null)
val writer = new CharArrayWriter()
val allowNullOption =
new JSONOptions(Map("ignoreNullFields" -> "false"), gmtId)
new JSONOptions(Map("ignoreNullFields" -> "false"), utcId)
val gen = new JacksonGenerator(dataType, writer, allowNullOption)
gen.write(input)
gen.flush()
Expand All @@ -59,7 +59,7 @@ class JacksonGeneratorSuite extends SparkFunSuite {
val input = InternalRow(InternalRow(null))
val writer = new CharArrayWriter()
val allowNullOption =
new JSONOptions(Map("ignoreNullFields" -> "false"), gmtId)
new JSONOptions(Map("ignoreNullFields" -> "false"), utcId)
val gen = new JacksonGenerator(dataType, writer, allowNullOption)
gen.write(input)
gen.flush()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DateTimeUtilsSuite extends SparkFunSuite with Matchers with SQLHelper {
private def defaultZoneId = ZoneId.systemDefault()

test("nanoseconds truncation") {
val tf = TimestampFormatter.getFractionFormatter(DateTimeUtils.defaultTimeZone.toZoneId)
val tf = TimestampFormatter.getFractionFormatter(ZoneId.systemDefault())
def checkStringToTimestamp(originalTime: String, expectedParsedTime: String): Unit = {
val parsedTimestampOp = DateTimeUtils.stringToTimestamp(
UTF8String.fromString(originalTime), defaultZoneId)
Expand Down Expand Up @@ -121,7 +121,7 @@ class DateTimeUtilsSuite extends SparkFunSuite with Matchers with SQLHelper {
checkFromToJavaDate(new Date(df2.parse("1776-07-04 18:30:00 UTC").getTime))
}

private def toDate(s: String, zoneId: ZoneId = UTC): Option[SQLDate] = {
private def toDate(s: String, zoneId: ZoneId = UTC): Option[Int] = {
stringToDate(UTF8String.fromString(s), zoneId)
}

Expand Down Expand Up @@ -149,7 +149,7 @@ class DateTimeUtilsSuite extends SparkFunSuite with Matchers with SQLHelper {
assert(toDate("1999 08").isEmpty)
}

private def toTimestamp(str: String, zoneId: ZoneId): Option[SQLTimestamp] = {
private def toTimestamp(str: String, zoneId: ZoneId): Option[Long] = {
stringToTimestamp(UTF8String.fromString(str), zoneId)
}

Expand Down Expand Up @@ -520,7 +520,7 @@ class DateTimeUtilsSuite extends SparkFunSuite with Matchers with SQLHelper {
def testTrunc(
level: Int,
expected: String,
inputTS: SQLTimestamp,
inputTS: Long,
zoneId: ZoneId = defaultZoneId): Unit = {
val truncated =
DateTimeUtils.truncTimestamp(inputTS, level, zoneId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class RebaseDateTimeSuite extends SparkFunSuite with Matchers with SQLHelper {
Math.floor(millisLocal.toDouble / MILLIS_PER_DAY).toInt
}
private def fromJavaDateLegacy(date: Date): Int = {
millisToDaysLegacy(date.getTime, defaultTimeZone())
millisToDaysLegacy(date.getTime, TimeZone.getTimeZone(ZoneId.systemDefault()))
}

test("rebase gregorian to/from julian days") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

package org.apache.spark.sql.util

import java.time.ZoneId

import org.apache.arrow.vector.types.pojo.ArrowType

import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.catalyst.util.DateTimeTestUtils.LA
import org.apache.spark.sql.catalyst.util.DateTimeUtils
import org.apache.spark.sql.types._

class ArrowUtilsSuite extends SparkFunSuite {
Expand Down Expand Up @@ -63,7 +64,7 @@ class ArrowUtilsSuite extends SparkFunSuite {
assert(ArrowUtils.fromArrowSchema(arrowSchema) === schema)
}

roundtripWithTz(DateTimeUtils.defaultTimeZone().getID)
roundtripWithTz(ZoneId.systemDefault().getId)
roundtripWithTz("Asia/Tokyo")
roundtripWithTz("UTC")
roundtripWithTz(LA.getId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName._

import org.apache.spark.sql.catalyst.util.{CaseInsensitiveMap, DateTimeUtils}
import org.apache.spark.sql.catalyst.util.DateTimeUtils.SQLDate
import org.apache.spark.sql.sources
import org.apache.spark.unsafe.types.UTF8String

Expand Down Expand Up @@ -124,7 +123,7 @@ class ParquetFilters(
private val ParquetTimestampMicrosType = ParquetSchemaType(TIMESTAMP_MICROS, INT64, 0, null)
private val ParquetTimestampMillisType = ParquetSchemaType(TIMESTAMP_MILLIS, INT64, 0, null)

private def dateToDays(date: Any): SQLDate = date match {
private def dateToDays(date: Any): Int = date match {
case d: Date => DateTimeUtils.fromJavaDate(d)
case ld: LocalDate => DateTimeUtils.localDateToDays(ld)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import org.apache.spark.internal.Logging
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, CaseInsensitiveMap, DateTimeUtils, GenericArrayData}
import org.apache.spark.sql.catalyst.util.DateTimeUtils.SQLTimestamp
import org.apache.spark.sql.catalyst.util.RebaseDateTime._
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._
Expand Down Expand Up @@ -757,7 +756,7 @@ private[parquet] object ParquetRowConverter {
unscaled
}

def binaryToSQLTimestamp(binary: Binary): SQLTimestamp = {
def binaryToSQLTimestamp(binary: Binary): Long = {
assert(binary.length() == 12, s"Timestamps (with nanoseconds) are expected to be stored in" +
s" 12-byte long binaries. Found a ${binary.length()}-byte binary instead.")
val buffer = binary.toByteBuffer.order(ByteOrder.LITTLE_ENDIAN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.apache.spark.sql

import java.nio.charset.StandardCharsets
import java.sql.{Date, Timestamp}
import java.util.TimeZone

import scala.util.Random

Expand All @@ -28,8 +27,7 @@ import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions.Expression
import org.apache.spark.sql.catalyst.expressions.codegen.CodegenFallback
import org.apache.spark.sql.catalyst.plans.logical.OneRowRelation
import org.apache.spark.sql.catalyst.util.DateTimeTestUtils
import org.apache.spark.sql.catalyst.util.DateTimeTestUtils.UTC
import org.apache.spark.sql.catalyst.util.DateTimeTestUtils.{withDefaultTimeZone, UTC}
import org.apache.spark.sql.functions._
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.test.SharedSparkSession
Expand Down Expand Up @@ -1029,7 +1027,7 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSparkSession {
Timestamp.valueOf("2018-01-01 12:00:00"),
Timestamp.valueOf("2018-01-02 00:00:00")))))

DateTimeTestUtils.withDefaultTimeZone(UTC) {
withDefaultTimeZone(UTC) {
checkAnswer(
spark.sql("select sequence(" +
" cast('2018-01-01' as date)" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.analysis.NoSuchTableException
import org.apache.spark.sql.catalyst.catalog.CatalogColumnStat
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.catalyst.util.{DateTimeTestUtils, DateTimeUtils}
import org.apache.spark.sql.catalyst.util.DateTimeTestUtils
import org.apache.spark.sql.catalyst.util.DateTimeUtils.TimeZoneUTC
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.test.SharedSparkSession
import org.apache.spark.sql.test.SQLTestData.ArrayData
Expand Down Expand Up @@ -483,11 +484,11 @@ class StatisticsCollectionSuite extends StatisticsCollectionTestBase with Shared

DateTimeTestUtils.outstandingZoneIds.foreach { zid =>
val timeZone = TimeZone.getTimeZone(zid)
checkTimestampStats(DateType, DateTimeUtils.TimeZoneUTC, timeZone) { stats =>
checkTimestampStats(DateType, TimeZoneUTC, timeZone) { stats =>
assert(stats.min.get.asInstanceOf[Int] == TimeUnit.SECONDS.toDays(start))
assert(stats.max.get.asInstanceOf[Int] == TimeUnit.SECONDS.toDays(end - 1))
}
checkTimestampStats(TimestampType, DateTimeUtils.TimeZoneUTC, timeZone) { stats =>
checkTimestampStats(TimestampType, TimeZoneUTC, timeZone) { stats =>
assert(stats.min.get.asInstanceOf[Long] == TimeUnit.SECONDS.toMicros(start))
assert(stats.max.get.asInstanceOf[Long] == TimeUnit.SECONDS.toMicros(end - 1))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.io.File
import java.math.BigInteger
import java.sql.{Date, Timestamp}
import java.time.{ZoneId, ZoneOffset}
import java.util.{Calendar, Locale, TimeZone}
import java.util.{Calendar, Locale}

import scala.collection.mutable.ArrayBuffer

Expand All @@ -35,6 +35,7 @@ import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.catalog.ExternalCatalogUtils
import org.apache.spark.sql.catalyst.expressions.Literal
import org.apache.spark.sql.catalyst.util.{DateFormatter, DateTimeUtils, TimestampFormatter}
import org.apache.spark.sql.catalyst.util.DateTimeUtils.TimeZoneUTC
import org.apache.spark.sql.execution.datasources._
import org.apache.spark.sql.execution.datasources.{PartitionPath => Partition}
import org.apache.spark.sql.execution.datasources.v2.{DataSourceV2Relation, FileTable}
Expand Down Expand Up @@ -88,7 +89,7 @@ abstract class ParquetPartitionDiscoverySuite
check("1990-02-24 12:00:30",
Literal.create(Timestamp.valueOf("1990-02-24 12:00:30"), TimestampType))

val c = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
val c = Calendar.getInstance(TimeZoneUTC)
c.set(1990, 1, 24, 12, 0, 30)
c.set(Calendar.MILLISECOND, 0)
check("1990-02-24 12:00:30",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.sql.sources

import java.time.ZoneId

import org.apache.spark.sql.AnalysisException
import org.apache.spark.sql.catalyst.util.DateTimeUtils
import org.apache.spark.sql.execution.datasources.DataSource
Expand All @@ -27,7 +29,7 @@ class ResolvedDataSourceSuite extends SharedSparkSession {
DataSource(
sparkSession = spark,
className = name,
options = Map(DateTimeUtils.TIMEZONE_OPTION -> DateTimeUtils.defaultTimeZone().getID)
options = Map(DateTimeUtils.TIMEZONE_OPTION -> ZoneId.systemDefault().getId)
).providingClass

test("jdbc") {
Expand Down