Skip to content

Commit d575a45

Browse files
committed
Revert "[SPARK-25496][SQL] Deprecate from_utc_timestamp and to_utc_timestamp"
This reverts commit c5e83ab.
1 parent a0d807d commit d575a45

File tree

11 files changed

+109
-199
lines changed

11 files changed

+109
-199
lines changed

R/pkg/R/functions.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,6 @@ setMethod("schema_of_csv", signature(x = "characterOrColumn"),
24592459
#' @note from_utc_timestamp since 1.5.0
24602460
setMethod("from_utc_timestamp", signature(y = "Column", x = "character"),
24612461
function(y, x) {
2462-
.Deprecated(msg = "from_utc_timestamp is deprecated. See SPARK-25496.")
24632462
jc <- callJStatic("org.apache.spark.sql.functions", "from_utc_timestamp", y@jc, x)
24642463
column(jc)
24652464
})
@@ -2518,7 +2517,6 @@ setMethod("next_day", signature(y = "Column", x = "character"),
25182517
#' @note to_utc_timestamp since 1.5.0
25192518
setMethod("to_utc_timestamp", signature(y = "Column", x = "character"),
25202519
function(y, x) {
2521-
.Deprecated(msg = "to_utc_timestamp is deprecated. See SPARK-25496.")
25222520
jc <- callJStatic("org.apache.spark.sql.functions", "to_utc_timestamp", y@jc, x)
25232521
column(jc)
25242522
})

R/pkg/tests/fulltests/test_sparkSQL.R

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,20 +1905,10 @@ test_that("date functions on a DataFrame", {
19051905
df2 <- createDataFrame(l2)
19061906
expect_equal(collect(select(df2, minute(df2$b)))[, 1], c(34, 24))
19071907
expect_equal(collect(select(df2, second(df2$b)))[, 1], c(0, 34))
1908-
conf <- callJMethod(sparkSession, "conf")
1909-
isUtcTimestampFuncEnabled <- callJMethod(conf, "get", "spark.sql.legacy.utcTimestampFunc.enabled")
1910-
callJMethod(conf, "set", "spark.sql.legacy.utcTimestampFunc.enabled", "true")
1911-
tryCatch({
1912-
# Both from_utc_timestamp and to_utc_timestamp are deprecated as of SPARK-25496
1913-
expect_equal(suppressWarnings(collect(select(df2, from_utc_timestamp(df2$b, "JST"))))[, 1],
1914-
c(as.POSIXct("2012-12-13 21:34:00 UTC"), as.POSIXct("2014-12-15 10:24:34 UTC")))
1915-
expect_equal(suppressWarnings(collect(select(df2, to_utc_timestamp(df2$b, "JST"))))[, 1],
1916-
c(as.POSIXct("2012-12-13 03:34:00 UTC"), as.POSIXct("2014-12-14 16:24:34 UTC")))
1917-
},
1918-
finally = {
1919-
# Reverting the conf back
1920-
callJMethod(conf, "set", "spark.sql.legacy.utcTimestampFunc.enabled", isUtcTimestampFuncEnabled)
1921-
})
1908+
expect_equal(collect(select(df2, from_utc_timestamp(df2$b, "JST")))[, 1],
1909+
c(as.POSIXct("2012-12-13 21:34:00 UTC"), as.POSIXct("2014-12-15 10:24:34 UTC")))
1910+
expect_equal(collect(select(df2, to_utc_timestamp(df2$b, "JST")))[, 1],
1911+
c(as.POSIXct("2012-12-13 03:34:00 UTC"), as.POSIXct("2014-12-14 16:24:34 UTC")))
19221912
expect_gt(collect(select(df2, unix_timestamp()))[1, 1], 0)
19231913
expect_gt(collect(select(df2, unix_timestamp(df2$b)))[1, 1], 0)
19241914
expect_gt(collect(select(df2, unix_timestamp(lit("2015-01-01"), "yyyy-MM-dd")))[1, 1], 0)

python/pyspark/sql/functions.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,10 +1306,7 @@ def from_utc_timestamp(timestamp, tz):
13061306
[Row(local_time=datetime.datetime(1997, 2, 28, 2, 30))]
13071307
>>> df.select(from_utc_timestamp(df.ts, df.tz).alias('local_time')).collect()
13081308
[Row(local_time=datetime.datetime(1997, 2, 28, 19, 30))]
1309-
1310-
.. note:: Deprecated in 3.0. See SPARK-25496
13111309
"""
1312-
warnings.warn("Deprecated in 3.0. See SPARK-25496", DeprecationWarning)
13131310
sc = SparkContext._active_spark_context
13141311
if isinstance(tz, Column):
13151312
tz = _to_java_column(tz)
@@ -1343,10 +1340,7 @@ def to_utc_timestamp(timestamp, tz):
13431340
[Row(utc_time=datetime.datetime(1997, 2, 28, 18, 30))]
13441341
>>> df.select(to_utc_timestamp(df.ts, df.tz).alias('utc_time')).collect()
13451342
[Row(utc_time=datetime.datetime(1997, 2, 28, 1, 30))]
1346-
1347-
.. note:: Deprecated in 3.0. See SPARK-25496
13481343
"""
1349-
warnings.warn("Deprecated in 3.0. See SPARK-25496", DeprecationWarning)
13501344
sc = SparkContext._active_spark_context
13511345
if isinstance(tz, Column):
13521346
tz = _to_java_column(tz)
@@ -3197,13 +3191,9 @@ def _test():
31973191
globs['sc'] = sc
31983192
globs['spark'] = spark
31993193
globs['df'] = spark.createDataFrame([Row(name='Alice', age=2), Row(name='Bob', age=5)])
3200-
3201-
spark.conf.set("spark.sql.legacy.utcTimestampFunc.enabled", "true")
32023194
(failure_count, test_count) = doctest.testmod(
32033195
pyspark.sql.functions, globs=globs,
32043196
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
3205-
spark.conf.unset("spark.sql.legacy.utcTimestampFunc.enabled")
3206-
32073197
spark.stop()
32083198
if failure_count:
32093199
sys.exit(-1)

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ import scala.util.control.NonFatal
2626

2727
import org.apache.commons.lang3.StringEscapeUtils
2828

29-
import org.apache.spark.sql.AnalysisException
3029
import org.apache.spark.sql.catalyst.InternalRow
3130
import org.apache.spark.sql.catalyst.expressions.codegen._
3231
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
3332
import org.apache.spark.sql.catalyst.util.{DateTimeUtils, TimestampFormatter}
3433
import org.apache.spark.sql.catalyst.util.DateTimeUtils._
35-
import org.apache.spark.sql.internal.SQLConf
3634
import org.apache.spark.sql.types._
3735
import org.apache.spark.unsafe.types.{CalendarInterval, UTF8String}
3836

@@ -1023,11 +1021,6 @@ case class TimeAdd(start: Expression, interval: Expression, timeZoneId: Option[S
10231021
case class FromUTCTimestamp(left: Expression, right: Expression)
10241022
extends BinaryExpression with ImplicitCastInputTypes {
10251023

1026-
if (!SQLConf.get.utcTimestampFuncEnabled) {
1027-
throw new AnalysisException(s"The $prettyName function has been disabled since Spark 3.0." +
1028-
s"Set ${SQLConf.UTC_TIMESTAMP_FUNC_ENABLED.key} to true to enable this function.")
1029-
}
1030-
10311024
override def inputTypes: Seq[AbstractDataType] = Seq(TimestampType, StringType)
10321025
override def dataType: DataType = TimestampType
10331026
override def prettyName: String = "from_utc_timestamp"
@@ -1234,11 +1227,6 @@ case class MonthsBetween(
12341227
case class ToUTCTimestamp(left: Expression, right: Expression)
12351228
extends BinaryExpression with ImplicitCastInputTypes {
12361229

1237-
if (!SQLConf.get.utcTimestampFuncEnabled) {
1238-
throw new AnalysisException(s"The $prettyName function has been disabled since Spark 3.0. " +
1239-
s"Set ${SQLConf.UTC_TIMESTAMP_FUNC_ENABLED.key} to true to enable this function.")
1240-
}
1241-
12421230
override def inputTypes: Seq[AbstractDataType] = Seq(TimestampType, StringType)
12431231
override def dataType: DataType = TimestampType
12441232
override def prettyName: String = "to_utc_timestamp"

sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,12 +1723,6 @@ object SQLConf {
17231723
"and java.sql.Date are used for the same purpose.")
17241724
.booleanConf
17251725
.createWithDefault(false)
1726-
1727-
val UTC_TIMESTAMP_FUNC_ENABLED = buildConf("spark.sql.legacy.utcTimestampFunc.enabled")
1728-
.doc("The configuration property enables the to_utc_timestamp() " +
1729-
"and from_utc_timestamp() functions.")
1730-
.booleanConf
1731-
.createWithDefault(false)
17321726
}
17331727

17341728
/**
@@ -1922,8 +1916,6 @@ class SQLConf extends Serializable with Logging {
19221916

19231917
def datetimeJava8ApiEnabled: Boolean = getConf(DATETIME_JAVA8API_ENABLED)
19241918

1925-
def utcTimestampFuncEnabled: Boolean = getConf(UTC_TIMESTAMP_FUNC_ENABLED)
1926-
19271919
/**
19281920
* Returns the [[Resolver]] for the current configuration, which can be used to determine if two
19291921
* identifiers are equal.

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CodeGenerationSuite.scala

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package org.apache.spark.sql.catalyst.expressions
1919

2020
import java.sql.Timestamp
2121

22-
import org.apache.log4j.AppenderSkeleton
22+
import org.apache.log4j.{Appender, AppenderSkeleton, Logger}
2323
import org.apache.log4j.spi.LoggingEvent
2424

2525
import org.apache.spark.SparkFunSuite
@@ -31,7 +31,6 @@ import org.apache.spark.sql.catalyst.expressions.codegen._
3131
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
3232
import org.apache.spark.sql.catalyst.expressions.objects._
3333
import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, DateTimeUtils}
34-
import org.apache.spark.sql.internal.SQLConf
3534
import org.apache.spark.sql.types._
3635
import org.apache.spark.unsafe.types.UTF8String
3736
import org.apache.spark.util.ThreadUtils
@@ -190,42 +189,36 @@ class CodeGenerationSuite extends SparkFunSuite with ExpressionEvalHelper {
190189
}
191190

192191
test("SPARK-17702: split wide constructor into blocks due to JVM code size limit") {
193-
withSQLConf(SQLConf.UTC_TIMESTAMP_FUNC_ENABLED.key -> "true") {
194-
val length = 5000
195-
val expressions = Seq.fill(length) {
196-
ToUTCTimestamp(
197-
Literal.create(Timestamp.valueOf("2015-07-24 00:00:00"), TimestampType),
198-
Literal.create("PST", StringType))
199-
}
200-
val plan = GenerateMutableProjection.generate(expressions)
201-
val actual = plan(new GenericInternalRow(length)).toSeq(expressions.map(_.dataType))
202-
val expected = Seq.fill(length)(
203-
DateTimeUtils.fromJavaTimestamp(Timestamp.valueOf("2015-07-24 07:00:00")))
204-
205-
if (actual != expected) {
206-
fail(
207-
s"Incorrect Evaluation: expressions: $expressions, actual: $actual, expected: $expected")
208-
}
192+
val length = 5000
193+
val expressions = Seq.fill(length) {
194+
ToUTCTimestamp(
195+
Literal.create(Timestamp.valueOf("2015-07-24 00:00:00"), TimestampType),
196+
Literal.create("PST", StringType))
197+
}
198+
val plan = GenerateMutableProjection.generate(expressions)
199+
val actual = plan(new GenericInternalRow(length)).toSeq(expressions.map(_.dataType))
200+
val expected = Seq.fill(length)(
201+
DateTimeUtils.fromJavaTimestamp(Timestamp.valueOf("2015-07-24 07:00:00")))
202+
203+
if (actual != expected) {
204+
fail(s"Incorrect Evaluation: expressions: $expressions, actual: $actual, expected: $expected")
209205
}
210206
}
211207

212208
test("SPARK-22226: group splitted expressions into one method per nested class") {
213-
withSQLConf(SQLConf.UTC_TIMESTAMP_FUNC_ENABLED.key -> "true") {
214-
val length = 10000
215-
val expressions = Seq.fill(length) {
216-
ToUTCTimestamp(
217-
Literal.create(Timestamp.valueOf("2017-10-10 00:00:00"), TimestampType),
218-
Literal.create("PST", StringType))
219-
}
220-
val plan = GenerateMutableProjection.generate(expressions)
221-
val actual = plan(new GenericInternalRow(length)).toSeq(expressions.map(_.dataType))
222-
val expected = Seq.fill(length)(
223-
DateTimeUtils.fromJavaTimestamp(Timestamp.valueOf("2017-10-10 07:00:00")))
224-
225-
if (actual != expected) {
226-
fail(
227-
s"Incorrect Evaluation: expressions: $expressions, actual: $actual, expected: $expected")
228-
}
209+
val length = 10000
210+
val expressions = Seq.fill(length) {
211+
ToUTCTimestamp(
212+
Literal.create(Timestamp.valueOf("2017-10-10 00:00:00"), TimestampType),
213+
Literal.create("PST", StringType))
214+
}
215+
val plan = GenerateMutableProjection.generate(expressions)
216+
val actual = plan(new GenericInternalRow(length)).toSeq(expressions.map(_.dataType))
217+
val expected = Seq.fill(length)(
218+
DateTimeUtils.fromJavaTimestamp(Timestamp.valueOf("2017-10-10 07:00:00")))
219+
220+
if (actual != expected) {
221+
fail(s"Incorrect Evaluation: expressions: $expressions, actual: $actual, expected: $expected")
229222
}
230223
}
231224

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ import java.util.concurrent.TimeUnit
2525
import java.util.concurrent.TimeUnit._
2626

2727
import org.apache.spark.SparkFunSuite
28-
import org.apache.spark.sql.AnalysisException
2928
import org.apache.spark.sql.catalyst.expressions.codegen.GenerateUnsafeProjection
3029
import org.apache.spark.sql.catalyst.util.{DateTimeUtils, TimestampFormatter}
3130
import org.apache.spark.sql.catalyst.util.DateTimeTestUtils._
3231
import org.apache.spark.sql.catalyst.util.DateTimeUtils.TimeZoneGMT
33-
import org.apache.spark.sql.internal.SQLConf
3432
import org.apache.spark.sql.types._
3533
import org.apache.spark.unsafe.types.CalendarInterval
3634

@@ -818,29 +816,21 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
818816
NonFoldableLiteral.create(tz, StringType)),
819817
if (expected != null) Timestamp.valueOf(expected) else null)
820818
}
821-
withSQLConf(SQLConf.UTC_TIMESTAMP_FUNC_ENABLED.key -> "true") {
822-
test("2015-07-24 00:00:00", "PST", "2015-07-24 07:00:00")
823-
test("2015-01-24 00:00:00", "PST", "2015-01-24 08:00:00")
824-
test(null, "UTC", null)
825-
test("2015-07-24 00:00:00", null, null)
826-
test(null, null, null)
827-
}
828-
val msg = intercept[AnalysisException] {
829-
test("2015-07-24 00:00:00", "PST", "2015-07-24 07:00:00")
830-
}.getMessage
831-
assert(msg.contains(SQLConf.UTC_TIMESTAMP_FUNC_ENABLED.key))
819+
test("2015-07-24 00:00:00", "PST", "2015-07-24 07:00:00")
820+
test("2015-01-24 00:00:00", "PST", "2015-01-24 08:00:00")
821+
test(null, "UTC", null)
822+
test("2015-07-24 00:00:00", null, null)
823+
test(null, null, null)
832824
}
833825

834826
test("to_utc_timestamp - invalid time zone id") {
835-
withSQLConf(SQLConf.UTC_TIMESTAMP_FUNC_ENABLED.key -> "true") {
836-
Seq("Invalid time zone", "\"quote", "UTC*42").foreach { invalidTz =>
837-
val msg = intercept[java.time.DateTimeException] {
838-
GenerateUnsafeProjection.generate(
839-
ToUTCTimestamp(
840-
Literal(Timestamp.valueOf("2015-07-24 00:00:00")), Literal(invalidTz)) :: Nil)
841-
}.getMessage
842-
assert(msg.contains(invalidTz))
843-
}
827+
Seq("Invalid time zone", "\"quote", "UTC*42").foreach { invalidTz =>
828+
val msg = intercept[java.time.DateTimeException] {
829+
GenerateUnsafeProjection.generate(
830+
ToUTCTimestamp(
831+
Literal(Timestamp.valueOf("2015-07-24 00:00:00")), Literal(invalidTz)) :: Nil)
832+
}.getMessage
833+
assert(msg.contains(invalidTz))
844834
}
845835
}
846836

@@ -857,28 +847,19 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
857847
NonFoldableLiteral.create(tz, StringType)),
858848
if (expected != null) Timestamp.valueOf(expected) else null)
859849
}
860-
withSQLConf(SQLConf.UTC_TIMESTAMP_FUNC_ENABLED.key -> "true") {
861-
test("2015-07-24 00:00:00", "PST", "2015-07-23 17:00:00")
862-
test("2015-01-24 00:00:00", "PST", "2015-01-23 16:00:00")
863-
test(null, "UTC", null)
864-
test("2015-07-24 00:00:00", null, null)
865-
test(null, null, null)
866-
}
867-
val msg = intercept[AnalysisException] {
868-
test("2015-07-24 00:00:00", "PST", "2015-07-23 17:00:00")
869-
}.getMessage
870-
assert(msg.contains(SQLConf.UTC_TIMESTAMP_FUNC_ENABLED.key))
850+
test("2015-07-24 00:00:00", "PST", "2015-07-23 17:00:00")
851+
test("2015-01-24 00:00:00", "PST", "2015-01-23 16:00:00")
852+
test(null, "UTC", null)
853+
test("2015-07-24 00:00:00", null, null)
854+
test(null, null, null)
871855
}
872856

873857
test("from_utc_timestamp - invalid time zone id") {
874-
withSQLConf(SQLConf.UTC_TIMESTAMP_FUNC_ENABLED.key -> "true") {
875-
Seq("Invalid time zone", "\"quote", "UTC*42").foreach { invalidTz =>
876-
val msg = intercept[java.time.DateTimeException] {
877-
GenerateUnsafeProjection.generate(
878-
FromUTCTimestamp(Literal(0), Literal(invalidTz)) :: Nil)
879-
}.getMessage
880-
assert(msg.contains(invalidTz))
881-
}
858+
Seq("Invalid time zone", "\"quote", "UTC*42").foreach { invalidTz =>
859+
val msg = intercept[java.time.DateTimeException] {
860+
GenerateUnsafeProjection.generate(FromUTCTimestamp(Literal(0), Literal(invalidTz)) :: Nil)
861+
}.getMessage
862+
assert(msg.contains(invalidTz))
882863
}
883864
}
884865
}

sql/core/src/main/scala/org/apache/spark/sql/functions.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,7 +2988,6 @@ object functions {
29882988
* @group datetime_funcs
29892989
* @since 1.5.0
29902990
*/
2991-
@deprecated("This function is deprecated and will be removed in future versions.", "3.0.0")
29922991
def from_utc_timestamp(ts: Column, tz: String): Column = withExpr {
29932992
FromUTCTimestamp(ts.expr, Literal(tz))
29942993
}
@@ -3000,7 +2999,6 @@ object functions {
30002999
* @group datetime_funcs
30013000
* @since 2.4.0
30023001
*/
3003-
@deprecated("This function is deprecated and will be removed in future versions.", "3.0.0")
30043002
def from_utc_timestamp(ts: Column, tz: Column): Column = withExpr {
30053003
FromUTCTimestamp(ts.expr, tz.expr)
30063004
}
@@ -3019,7 +3017,6 @@ object functions {
30193017
* @group datetime_funcs
30203018
* @since 1.5.0
30213019
*/
3022-
@deprecated("This function is deprecated and will be removed in future versions.", "3.0.0")
30233020
def to_utc_timestamp(ts: Column, tz: String): Column = withExpr {
30243021
ToUTCTimestamp(ts.expr, Literal(tz))
30253022
}
@@ -3031,7 +3028,6 @@ object functions {
30313028
* @group datetime_funcs
30323029
* @since 2.4.0
30333030
*/
3034-
@deprecated("This function is deprecated and will be removed in future versions.", "3.0.0")
30353031
def to_utc_timestamp(ts: Column, tz: Column): Column = withExpr {
30363032
ToUTCTimestamp(ts.expr, tz.expr)
30373033
}

0 commit comments

Comments
 (0)