MaxGekk commented on code in PR #48624:
URL: https://github.com/apache/spark/pull/48624#discussion_r1816844148
##########
sql/core/src/test/scala/org/apache/spark/sql/DateFunctionsSuite.scala:
##########
@@ -1366,6 +1366,65 @@ class DateFunctionsSuite extends QueryTest with
SharedSparkSession {
checkAnswer(result1, result2)
}
+ test("try_make_timestamp") {
+ val df = Seq((100, 11, 1, 12, 30, 01.001001, "UTC")).
+ toDF("year", "month", "day", "hour", "min", "sec", "timezone")
+
+ val result1 = df.selectExpr(s"try_make_timestamp(year, month, day, hour,
min, sec, timezone)")
Review Comment:
Could you test `try_make_timestamp` from Scala/Java API.
##########
docs/sql-ref-ansi-compliance.md:
##########
@@ -380,6 +380,7 @@ When ANSI mode is on, it throws exceptions for invalid
operations. You can use t
- `try_element_at`: identical to the function `element_at`, except that it
returns `NULL` result instead of throwing an exception on array's index out of
bound.
- `try_to_timestamp`: identical to the function `to_timestamp`, except that
it returns `NULL` result instead of throwing an exception on string parsing
error.
- `try_parse_url`: identical to the function `parse_url`, except that it
returns `NULL` result instead of throwing an exception on url parsing error.
+ - `try_make_timestamp`: identical to the function `make_timestamp`, except
that it returns `NULL` result instead of throwing an exception on string
parsing error.
Review Comment:
How about others `try_make_timestamp_ltz` and `try_make_timestamp_ntz`.
Should we add them here too?
##########
sql/core/src/test/scala/org/apache/spark/sql/DateFunctionsSuite.scala:
##########
@@ -1366,6 +1366,65 @@ class DateFunctionsSuite extends QueryTest with
SharedSparkSession {
checkAnswer(result1, result2)
}
+ test("try_make_timestamp") {
+ val df = Seq((100, 11, 1, 12, 30, 01.001001, "UTC")).
+ toDF("year", "month", "day", "hour", "min", "sec", "timezone")
+
+ val result1 = df.selectExpr(s"try_make_timestamp(year, month, day, hour,
min, sec, timezone)")
+ withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") {
+ val result2 = df.select(make_timestamp(
+ col("year"), col("month"), col("day"), col("hour"),
+ col("min"), col("sec"), col("timezone")))
+ checkAnswer(result1, result2)
+ }
+
+ val result3 = df.selectExpr(s"try_make_timestamp(year, month, day, hour,
min, sec)")
+ withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") {
+ val result4 = df.select(make_timestamp(
+ col("year"), col("month"), col("day"), col("hour"),
+ col("min"), col("sec")))
+ checkAnswer(result3, result4)
+ }
+ }
+
+ test("try_make_timestamp_ntz") {
+ val df = Seq((100, 11, 1, 12, 30, 01.001001)).
+ toDF("year", "month", "day", "hour", "min", "sec")
+
+ val result1 = df.selectExpr(
+ s"try_make_timestamp_ntz(year, month, day, hour, min, sec)")
+ withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") {
+ val result2 = df.select(make_timestamp_ntz(
+ col("year"), col("month"), col("day"), col("hour"),
+ col("min"), col("sec")))
+ checkAnswer(result1, result2)
+ }
+ }
+
+ test("try_make_timestamp_ltz") {
+ val df = Seq((100, 11, 1, 12, 30, 01.001001, "UTC")).
+ toDF("year", "month", "day", "hour", "min", "sec", "timezone")
+
+ val result1 = df.selectExpr(
+ s"try_make_timestamp_ltz(year, month, day, hour, min, sec, timezone)")
Review Comment:
remove s
##########
python/pyspark/sql/functions/builtin.py:
##########
@@ -21314,6 +21314,109 @@ def make_timestamp(
)
+@_try_remote_functions
+def try_make_timestamp(
Review Comment:
@HyukjinKwon @zhengruifeng Could you look at the PR, please, especially at
the python-related changes.
##########
sql/core/src/test/scala/org/apache/spark/sql/DateFunctionsSuite.scala:
##########
@@ -1366,6 +1366,65 @@ class DateFunctionsSuite extends QueryTest with
SharedSparkSession {
checkAnswer(result1, result2)
}
+ test("try_make_timestamp") {
+ val df = Seq((100, 11, 1, 12, 30, 01.001001, "UTC")).
+ toDF("year", "month", "day", "hour", "min", "sec", "timezone")
+
+ val result1 = df.selectExpr(s"try_make_timestamp(year, month, day, hour,
min, sec, timezone)")
+ withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") {
+ val result2 = df.select(make_timestamp(
+ col("year"), col("month"), col("day"), col("hour"),
+ col("min"), col("sec"), col("timezone")))
+ checkAnswer(result1, result2)
+ }
+
+ val result3 = df.selectExpr(s"try_make_timestamp(year, month, day, hour,
min, sec)")
+ withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") {
+ val result4 = df.select(make_timestamp(
+ col("year"), col("month"), col("day"), col("hour"),
+ col("min"), col("sec")))
+ checkAnswer(result3, result4)
+ }
+ }
+
+ test("try_make_timestamp_ntz") {
+ val df = Seq((100, 11, 1, 12, 30, 01.001001)).
+ toDF("year", "month", "day", "hour", "min", "sec")
+
+ val result1 = df.selectExpr(
+ s"try_make_timestamp_ntz(year, month, day, hour, min, sec)")
+ withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") {
+ val result2 = df.select(make_timestamp_ntz(
+ col("year"), col("month"), col("day"), col("hour"),
+ col("min"), col("sec")))
+ checkAnswer(result1, result2)
+ }
+ }
+
+ test("try_make_timestamp_ltz") {
+ val df = Seq((100, 11, 1, 12, 30, 01.001001, "UTC")).
+ toDF("year", "month", "day", "hour", "min", "sec", "timezone")
+
+ val result1 = df.selectExpr(
+ s"try_make_timestamp_ltz(year, month, day, hour, min, sec, timezone)")
+ withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") {
+ val result2 = df.select(make_timestamp_ltz(
+ col("year"), col("month"), col("day"), col("hour"),
+ col("min"), col("sec"), col("timezone")))
+ checkAnswer(result1, result2)
+ }
+
+ val result3 = df.selectExpr(
+ s"try_make_timestamp_ltz(year, month, day, hour, min, sec)")
Review Comment:
s" is not needed. please, remove it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]