Skip to content

Commit 3326c75

Browse files
zenusyoungsofun
andauthored
fix:schema mismatch not detected while executing copy into (#13010)
* fix:schema mismatch not detected while executing copy into * recover fix * add fix t.* case * Update 03_0028_copy_into_stage * Update tests/sqllogictests/suites/base/03_common/03_0028_copy_into_stage * Update tests/sqllogictests/suites/base/03_common/03_0028_copy_into_stage --------- Co-authored-by: Yang Xiufeng <[email protected]>
1 parent 92262cc commit 3326c75

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/query/sql/src/planner/binder/copy.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ impl<'a> Binder {
213213
}
214214
.into(),
215215
);
216-
217216
let plan = CopyIntoTablePlan {
218217
catalog_info,
219218
database_name,
@@ -482,6 +481,15 @@ impl<'a> Binder {
482481
.await?;
483482
let (scalar_items, projections) =
484483
self.analyze_projection(&from_context.aggregate_info, &select_list)?;
484+
485+
if projections.len() != plan.required_source_schema.num_fields() {
486+
return Err(ErrorCode::BadArguments(format!(
487+
"Number of columns in select list ({}) does not match that of the corresponding table ({})",
488+
projections.len(),
489+
plan.required_source_schema.num_fields(),
490+
)));
491+
}
492+
485493
let s_expr =
486494
self.bind_projection(&mut from_context, &projections, &scalar_items, s_expr)?;
487495
let mut output_context = BindContext::new();

tests/sqllogictests/suites/base/03_common/03_0028_copy_into_stage

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,26 @@ statement ok
3737
drop stage test
3838

3939
statement ok
40-
DROP DATABASE db1
40+
DROP STAGE IF EXISTS hello
41+
42+
statement ok
43+
CREATE STAGE IF NOT EXISTS hello
44+
45+
statement ok
46+
COPY INTO @hello from (select number from numbers(1)) FILE_FORMAT = (type = parquet)
47+
48+
statement ok
49+
CREATE TABLE world(c1 int , c2 int);
50+
51+
statement error (?s)1006.*Number of columns in select list \(1\) does not match that of the corresponding table \(2\)
52+
COPY INTO world FROM (select number from @hello ) file_format = (type = PARQUET);
53+
54+
statement ok
55+
DROP STAGE IF EXISTS hello
56+
57+
statement ok
58+
drop table world
59+
60+
statement ok
61+
DROP DATABASE db1
62+

0 commit comments

Comments
 (0)