From ca59c72183b45db3da56ec40db213b93980c5850 Mon Sep 17 00:00:00 2001 From: Dmitrii Blaginin Date: Wed, 6 Nov 2024 11:33:24 +0000 Subject: [PATCH] Ensure schema and data have the same size (#13264) --- datafusion/expr/src/logical_plan/builder.rs | 2 +- datafusion/sqllogictest/test_files/errors.slt | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/datafusion/expr/src/logical_plan/builder.rs b/datafusion/expr/src/logical_plan/builder.rs index b7839c4873af..790fc508d4ca 100644 --- a/datafusion/expr/src/logical_plan/builder.rs +++ b/datafusion/expr/src/logical_plan/builder.rs @@ -218,7 +218,7 @@ impl LogicalPlanBuilder { if values.is_empty() { return plan_err!("Values list cannot be empty"); } - let n_cols = values[0].len(); + let n_cols = schema.fields().len(); if n_cols == 0 { return plan_err!("Values list cannot be zero length"); } diff --git a/datafusion/sqllogictest/test_files/errors.slt b/datafusion/sqllogictest/test_files/errors.slt index da46a7e5e679..89104427554f 100644 --- a/datafusion/sqllogictest/test_files/errors.slt +++ b/datafusion/sqllogictest/test_files/errors.slt @@ -137,3 +137,10 @@ select 1 group by substr(''); # Error in filter should be reported query error Divide by zero SELECT c2 from aggregate_test_100 where CASE WHEN true THEN 1 / 0 ELSE 0 END = 1; + + +statement error DataFusion error: Error during planning: Inconsistent data length across values list: got 4 values in row 0 but expected 2 +create table records (timestamp timestamp, value float) as values ( + '2021-01-01 00:00:00', 1.0, + '2021-01-01 00:00:00', 2.0 +);