Skip to content

Commit ff55f2c

Browse files
andygroveclaude
andcommitted
fix: remove unsupported timestamp_ntz cast tests and fix date_format test
- Remove cast tests for TimestampNTZType to LongType (Spark doesn't support) - Remove cast tests for numeric types and BinaryType to TimestampNTZType (Spark doesn't support these casts) - Fix date_format timestamp_ntz test by using UTC timezone explicitly (Comet interprets timestamp_ntz as UTC during cast, which differs from Spark's session timezone behavior for non-UTC timezones) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 2e468e6 commit ff55f2c

2 files changed

Lines changed: 16 additions & 57 deletions

File tree

spark/src/test/scala/org/apache/comet/CometCastSuite.scala

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,10 +1038,6 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
10381038

10391039
// CAST from TimestampNTZType
10401040

1041-
test("cast TimestampNTZType to LongType") {
1042-
castTest(generateTimestampNTZs(), DataTypes.LongType)
1043-
}
1044-
10451041
test("cast TimestampNTZType to StringType") {
10461042
castTest(generateTimestampNTZs(), DataTypes.StringType)
10471043
}
@@ -1055,46 +1051,8 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
10551051
}
10561052

10571053
// CAST to TimestampNTZType
1058-
1059-
ignore("cast BooleanType to TimestampNTZType") {
1060-
// Spark does not support this cast
1061-
castTest(generateBools(), DataTypes.TimestampNTZType)
1062-
}
1063-
1064-
ignore("cast ByteType to TimestampNTZType") {
1065-
// Not yet implemented
1066-
castTest(generateBytes(), DataTypes.TimestampNTZType)
1067-
}
1068-
1069-
ignore("cast ShortType to TimestampNTZType") {
1070-
// Not yet implemented
1071-
castTest(generateShorts(), DataTypes.TimestampNTZType)
1072-
}
1073-
1074-
ignore("cast IntegerType to TimestampNTZType") {
1075-
// Not yet implemented
1076-
castTest(generateInts(), DataTypes.TimestampNTZType)
1077-
}
1078-
1079-
ignore("cast LongType to TimestampNTZType") {
1080-
// Not yet implemented
1081-
castTest(generateLongs(), DataTypes.TimestampNTZType)
1082-
}
1083-
1084-
ignore("cast FloatType to TimestampNTZType") {
1085-
// Not yet implemented
1086-
castTest(generateFloats(), DataTypes.TimestampNTZType)
1087-
}
1088-
1089-
ignore("cast DoubleType to TimestampNTZType") {
1090-
// Not yet implemented
1091-
castTest(generateDoubles(), DataTypes.TimestampNTZType)
1092-
}
1093-
1094-
ignore("cast DecimalType(10,2) to TimestampNTZType") {
1095-
// Not yet implemented
1096-
castTest(generateDecimalsPrecision10Scale2(), DataTypes.TimestampNTZType)
1097-
}
1054+
// Note: Spark does not support casting numeric types (Byte, Short, Int, Long, Float, Double,
1055+
// Decimal) or BinaryType to TimestampNTZType, so those tests are not included here.
10981056

10991057
ignore("cast StringType to TimestampNTZType") {
11001058
// Not yet implemented
@@ -1103,11 +1061,6 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
11031061
DataTypes.TimestampNTZType)
11041062
}
11051063

1106-
ignore("cast BinaryType to TimestampNTZType") {
1107-
// Spark does not support this cast
1108-
castTest(generateBinary(), DataTypes.TimestampNTZType)
1109-
}
1110-
11111064
ignore("cast DateType to TimestampNTZType") {
11121065
// Not yet implemented
11131066
castTest(generateDates(), DataTypes.TimestampNTZType)

spark/src/test/scala/org/apache/comet/CometTemporalExpressionSuite.scala

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,20 @@ class CometTemporalExpressionSuite extends CometTestBase with AdaptiveSparkPlanH
177177
}
178178

179179
test("date_format - timestamp_ntz input") {
180-
val r = new Random(42)
181-
val ntzSchema = StructType(Seq(StructField("ts_ntz", DataTypes.TimestampNTZType, true)))
182-
val ntzDF = FuzzDataGenerator.generateDataFrame(r, spark, ntzSchema, 100, DataGenOptions())
183-
ntzDF.createOrReplaceTempView("ntz_tbl")
184-
val supportedFormats = CometDateFormat.supportedFormats.keys.toSeq.filterNot(_.contains("'"))
185-
for (format <- supportedFormats) {
186-
checkSparkAnswerAndOperator(
187-
s"SELECT ts_ntz, date_format(ts_ntz, '$format') from ntz_tbl order by ts_ntz")
180+
// Comet's date_format with timestamp_ntz is only compatible with UTC timezone because
181+
// the cast from timestamp_ntz to timestamp interprets the value as UTC, not the session
182+
// timezone. For non-UTC timezones, Comet falls back to Spark.
183+
withSQLConf(SQLConf.SESSION_LOCAL_TIMEZONE.key -> "UTC") {
184+
val r = new Random(42)
185+
val ntzSchema = StructType(Seq(StructField("ts_ntz", DataTypes.TimestampNTZType, true)))
186+
val ntzDF = FuzzDataGenerator.generateDataFrame(r, spark, ntzSchema, 100, DataGenOptions())
187+
ntzDF.createOrReplaceTempView("ntz_tbl")
188+
val supportedFormats =
189+
CometDateFormat.supportedFormats.keys.toSeq.filterNot(_.contains("'"))
190+
for (format <- supportedFormats) {
191+
checkSparkAnswerAndOperator(
192+
s"SELECT ts_ntz, date_format(ts_ntz, '$format') from ntz_tbl order by ts_ntz")
193+
}
188194
}
189195
}
190196

0 commit comments

Comments
 (0)