@@ -2209,6 +2209,63 @@ class CometExecSuite extends CometTestBase {
22092209 }
22102210 }
22112211
2212+ test(" LocalTableScanExec with timestamps in non-UTC timezone" ) {
2213+ withSQLConf(
2214+ CometConf .COMET_EXEC_LOCAL_TABLE_SCAN_ENABLED .key -> " true" ,
2215+ SESSION_LOCAL_TIMEZONE .key -> " America/Los_Angeles" ) {
2216+ val df = Seq (
2217+ (1 , java.sql.Timestamp .valueOf(" 2024-01-15 10:30:00" )),
2218+ (2 , java.sql.Timestamp .valueOf(" 2024-06-15 14:00:00" )),
2219+ (3 , java.sql.Timestamp .valueOf(" 2024-12-25 08:00:00" )))
2220+ .toDF(" id" , " ts" )
2221+ .orderBy(" ts" )
2222+ checkSparkAnswerAndOperator(df)
2223+ }
2224+ }
2225+
2226+ test(" SparkToColumnar with timestamps in non-UTC timezone" ) {
2227+ withTempDir { dir =>
2228+ val path = new java.io.File (dir, " data" ).getAbsolutePath
2229+ Seq (
2230+ (1 , java.sql.Timestamp .valueOf(" 2024-01-15 10:30:00" )),
2231+ (2 , java.sql.Timestamp .valueOf(" 2024-06-15 14:00:00" )),
2232+ (3 , java.sql.Timestamp .valueOf(" 2024-12-25 08:00:00" )))
2233+ .toDF(" id" , " ts" )
2234+ .write
2235+ .parquet(path)
2236+ withSQLConf(
2237+ CometConf .COMET_NATIVE_SCAN_ENABLED .key -> " false" ,
2238+ CometConf .COMET_SPARK_TO_ARROW_ENABLED .key -> " true" ,
2239+ CometConf .COMET_CONVERT_FROM_PARQUET_ENABLED .key -> " true" ,
2240+ SESSION_LOCAL_TIMEZONE .key -> " America/Los_Angeles" ) {
2241+ val df = spark.read.parquet(path).orderBy(" ts" )
2242+ checkSparkAnswerAndOperator(df)
2243+ }
2244+ }
2245+ }
2246+
2247+ test(" sort on timestamps with non-UTC timezone via LocalTableScan" ) {
2248+ // When session timezone is non-UTC, CometLocalTableScanExec and
2249+ // CometSparkToColumnarExec must use UTC for the Arrow schema timezone
2250+ // to match the native side's expectations. Without this, the native
2251+ // ScanExec sees a timezone mismatch and performs an unnecessary cast.
2252+ // The cast is currently a no-op (Arrow timestamps with timezone are
2253+ // always UTC microseconds), but using UTC avoids the overhead and
2254+ // keeps schemas consistent throughout the native plan.
2255+ withSQLConf(
2256+ CometConf .COMET_EXEC_LOCAL_TABLE_SCAN_ENABLED .key -> " true" ,
2257+ SESSION_LOCAL_TIMEZONE .key -> " America/Los_Angeles" ) {
2258+ val df = Seq (
2259+ (1 , java.sql.Timestamp .valueOf(" 2024-01-15 10:30:00" )),
2260+ (2 , java.sql.Timestamp .valueOf(" 2024-06-15 14:00:00" )),
2261+ (3 , java.sql.Timestamp .valueOf(" 2024-12-25 08:00:00" )))
2262+ .toDF(" id" , " ts" )
2263+ .repartition(2 )
2264+ .orderBy(" ts" )
2265+ checkSparkAnswer(df)
2266+ }
2267+ }
2268+
22122269 test(" Native_datafusion reports correct files and bytes scanned" ) {
22132270 val inputFiles = 2
22142271
0 commit comments