Skip to content

Apache DataFusion SQL Query Engine

fix: DataFusion benchmark panicked: failed to cast '2013-07-01' to UInt16 (#21498)

Zhen Chen5e60df613608
diff --git a/datafusion/core/benches/sql_planner.rs b/datafusion/core/benches/sql_planner.rs
index 59502da987..fcc8da30fe 100644
--- a/datafusion/core/benches/sql_planner.rs
+++ b/datafusion/core/benches/sql_planner.rs
@@ -130,7 +130,8 @@ fn register_clickbench_hits_table(rt: &Runtime) -> SessionContext {
format!("{BENCHMARKS_PATH_2}{CLICKBENCH_DATA_PATH}")
};
- let sql = format!("CREATE EXTERNAL TABLE hits STORED AS PARQUET LOCATION '{path}'");
+ let sql =
+ format!("CREATE EXTERNAL TABLE hits_raw STORED AS PARQUET LOCATION '{path}'");
// ClickBench partitioned dataset was written by an ancient version of pyarrow that
// that wrote strings with the wrong logical type. To read it correctly, we must
@@ -139,6 +140,17 @@ fn register_clickbench_hits_table(rt: &Runtime) -> SessionContext {
.unwrap();
rt.block_on(ctx.sql(&sql)).unwrap();
+ // ClickBench stores EventDate as UInt16 (days since 1970-01-01). Create a view
+ // that exposes it as SQL DATE so that queries comparing it with date literals
+ // (e.g. "EventDate >= '2013-07-01'") work correctly during planning.
+ rt.block_on(ctx.sql(
+ "CREATE VIEW hits AS \
+ SELECT * EXCEPT (\"EventDate\"), \
+ CAST(CAST(\"EventDate\" AS INTEGER) AS DATE) AS \"EventDate\" \
+ FROM hits_raw",
+ ))
+ .unwrap();
+
let count =
rt.block_on(async { ctx.table("hits").await.unwrap().count().await.unwrap() });
assert!(count > 0);