Skip to content

Commit

Permalink
add fuzz test with unsupported date filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
vidyasankarv committed May 15, 2024
1 parent 362363f commit cdf8888
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions spark/src/test/scala/org/apache/comet/CometCastSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package org.apache.comet
import java.io.File

import scala.util.Random
import scala.util.matching.Regex

import org.apache.spark.sql.{CometTestBase, DataFrame, SaveMode}
import org.apache.spark.sql.catalyst.expressions.Cast
Expand Down Expand Up @@ -566,7 +567,6 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
}

test("cast StringType to DateType") {
// https://github.com/apache/datafusion-comet/issues/327
val validDates = Seq(
"262142-01-01",
"262142-01-01 ",
Expand Down Expand Up @@ -607,13 +607,12 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
"2020-mar-20",
"not_a_date",
"T2")
castTest((validDates ++ invalidDates).toDF("a"), DataTypes.DateType)
}

// due to limitations of NaiveDate we only support years between 262143 BC and 262142 AD"
// we can't test all possible fuzz dates
ignore("cast StringType to DataType - Fuzz Test") {
castTest(generateStrings(datePattern, 8).toDF("a"), DataTypes.DateType)
// due to limitations of NaiveDate we only support years between 262143 BC and 262142 AD"
val unsupportedYearPattern: Regex = "^\\s*[0-9]{5,}".r
val fuzzDates = generateStrings(datePattern, 8)
.filterNot(str => unsupportedYearPattern.findFirstMatchIn(str).isDefined)
castTest((validDates ++ invalidDates ++ fuzzDates).toDF("a"), DataTypes.DateType)
}

test("cast StringType to TimestampType disabled by default") {
Expand Down

0 comments on commit cdf8888

Please sign in to comment.