Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GLUTEN-6227][VL] Add unit tests in unix_timestamp for Spark legacy parser policy #7975

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.spark.sql

import org.apache.spark.SparkUpgradeException
import org.apache.spark.sql.catalyst.util.DateTimeUtils
import org.apache.spark.sql.functions._
import org.apache.spark.sql.internal.SQLConf
Expand All @@ -25,6 +26,7 @@ import java.time.{LocalDateTime, ZoneId}
import java.util.concurrent.TimeUnit

class GlutenDateFunctionsSuite extends DateFunctionsSuite with GlutenSQLTestsTrait {

import testImplicits._

private def secs(millis: Long): Long = TimeUnit.MILLISECONDS.toSeconds(millis)
Expand Down Expand Up @@ -112,18 +114,15 @@ class GlutenDateFunctionsSuite extends DateFunctionsSuite with GlutenSQLTestsTra
df1.selectExpr(s"unix_timestamp(x, 'yyyy-MM-dd mm:HH:ss')"),
Seq(Row(secs(ts4.getTime)), Row(null), Row(secs(ts3.getTime)), Row(null)))

// legacyParserPolicy is not respected by Gluten.
// invalid format
// val invalid = df1.selectExpr(s"unix_timestamp(x, 'yyyy-MM-dd aa:HH:ss')")
// if (legacyParserPolicy == "legacy") {
// checkAnswer(invalid,
// Seq(Row(null), Row(null), Row(null), Row(null)))
// } else {
// val e = intercept[SparkUpgradeException](invalid.collect())
// assert(e.getCause.isInstanceOf[IllegalArgumentException])
// assert( e.getMessage.contains(
// "You may get a different result due to the upgrading to Spark"))
// }
val invalid = df1.selectExpr(s"unix_timestamp(x, 'yyyy-MM-dd aa:HH:ss')")
if (legacyParserPolicy == "legacy") {
checkAnswer(invalid, Seq(Row(null), Row(null), Row(null), Row(null)))
} else {
val e = intercept[SparkUpgradeException](invalid.collect())
assert(e.getCause.isInstanceOf[IllegalArgumentException])
assert(
e.getMessage.contains("You may get a different result due to the upgrading to Spark"))
}

// February
val y1 = "2016-02-29"
Expand All @@ -140,6 +139,21 @@ class GlutenDateFunctionsSuite extends DateFunctionsSuite with GlutenSQLTestsTra
Row(new java.util.Date(TimeUnit.SECONDS.toMillis(now))))
}
}

val df = Seq(("2016-04-08 00:00:00")).toDF("d")
val fmt = "yyyy-MM-dd"
withSQLConf(SQLConf.LEGACY_TIME_PARSER_POLICY.key -> "legacy") {
val result = df.selectExpr(s"unix_timestamp(d, '$fmt')")
checkAnswer(result, Seq(Row(1460041200)))
}

withSQLConf(SQLConf.LEGACY_TIME_PARSER_POLICY.key -> "correct") {
val result = df.selectExpr(s"unix_timestamp(d, '$fmt')")
val e = intercept[SparkUpgradeException](result.collect())
assert(e.getCause.isInstanceOf[IllegalArgumentException])
assert(e.getMessage.contains("You may get a different result due to the upgrading to Spark"))
}

}

testGluten("to_unix_timestamp") {
Expand Down
Loading