Skip to content

Commit 5e60df6

Browse files
authored
fix: DataFusion benchmark panicked: failed to cast '2013-07-01' to UInt16 (#21498)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #21497. ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
1 parent 0626ca3 commit 5e60df6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

datafusion/core/benches/sql_planner.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ fn register_clickbench_hits_table(rt: &Runtime) -> SessionContext {
130130
format!("{BENCHMARKS_PATH_2}{CLICKBENCH_DATA_PATH}")
131131
};
132132

133-
let sql = format!("CREATE EXTERNAL TABLE hits STORED AS PARQUET LOCATION '{path}'");
133+
let sql =
134+
format!("CREATE EXTERNAL TABLE hits_raw STORED AS PARQUET LOCATION '{path}'");
134135

135136
// ClickBench partitioned dataset was written by an ancient version of pyarrow that
136137
// 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 {
139140
.unwrap();
140141
rt.block_on(ctx.sql(&sql)).unwrap();
141142

143+
// ClickBench stores EventDate as UInt16 (days since 1970-01-01). Create a view
144+
// that exposes it as SQL DATE so that queries comparing it with date literals
145+
// (e.g. "EventDate >= '2013-07-01'") work correctly during planning.
146+
rt.block_on(ctx.sql(
147+
"CREATE VIEW hits AS \
148+
SELECT * EXCEPT (\"EventDate\"), \
149+
CAST(CAST(\"EventDate\" AS INTEGER) AS DATE) AS \"EventDate\" \
150+
FROM hits_raw",
151+
))
152+
.unwrap();
153+
142154
let count =
143155
rt.block_on(async { ctx.table("hits").await.unwrap().count().await.unwrap() });
144156
assert!(count > 0);

0 commit comments

Comments
 (0)