You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by ma...@apache.org on 2025/01/02 06:17:32 UTC
(cloudberry) 01/03: FIX BUG: COPY FORM doesn't throw out ERROR: extra data after last expected column (7X) (#15612)
This is an automated email from the ASF dual-hosted git repository.
maxyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 99bd992a1c9cc87d0f878743572aa6860c52792a
Author: Yongtao Huang <99...@users.noreply.github.com>
AuthorDate: Thu Jun 8 15:42:04 2023 +0800
FIX BUG: COPY FORM doesn't throw out ERROR: extra data after last expected column (7X) (#15612)
This commit can fix bug reported in [issue 15625]
(https://github.com/greenplum-db/gpdb/issues/15625)
**Solution:**
In pg12.12, there is no function `InitCopyFromDispatchSplit()`,
so attr_count must be > 0. In GP7, we may get `[NULL]`
in QE when all fields are processed in the QD.
So the condition checking should change
from `attr_count > 0` to `attr_count >= 0`.
But before it, `attr_count = list_length(attnumlist);`,
we can ensure that `attr_count >= 0` consistently,
so delete this bug-related condition `attr_count > 0`.
Signed-off-by: Yongtao Huang <yo...@vmware.com>
Co-authored-by: Xiaoxiao He <hx...@vmware.com>
---
src/test/regress/data/copy.data | 1 +
src/test/regress/input/copy.source | 45 ++++++++++++++++++
src/test/regress/output/copy.source | 91 +++++++++++++++++++++++++++++++++++++
3 files changed, 137 insertions(+)
diff --git a/src/test/regress/data/copy.data b/src/test/regress/data/copy.data
new file mode 100644
index 0000000000..4a16c4207a
--- /dev/null
+++ b/src/test/regress/data/copy.data
@@ -0,0 +1 @@
+1,text1
diff --git a/src/test/regress/input/copy.source b/src/test/regress/input/copy.source
index 159cc1156d..c450395ebc 100644
--- a/src/test/regress/input/copy.source
+++ b/src/test/regress/input/copy.source
@@ -305,3 +305,48 @@ copy tab_progress_reporting from '@abs_srcdir@/data/emp.data'
drop trigger check_after_tab_progress_reporting on tab_progress_reporting;
drop function notice_after_tab_progress_reporting();
drop table tab_progress_reporting;
+-- check COPY behavior
+-- there are 2 fields in copy.data
+-- table_1_col_dist_c1: 1 col in table < 2 fields in file
+-- table_2_cols_dist_c1 and
+-- table_2_cols_dist_c2: 2 cols in table = 2 fields in file
+-- table_3_cols_dist_c1 and
+-- table_3_cols_dist_c2 and
+-- table_3_cols_dist_c3: 3 cols in table > 2 fields in file
+CREATE TABLE table_1_col_dist_c1(c1 text) distributed by (c1);
+CREATE TABLE table_2_cols_dist_c1(c1 text, c2 text) distributed by (c1);
+CREATE TABLE table_2_cols_dist_c2(c1 text, c2 text) distributed by (c2);
+CREATE TABLE table_3_cols_dist_c1(c1 text, c2 text, c3 text) distributed by (c1);
+CREATE TABLE table_3_cols_dist_c2(c1 text, c2 text, c3 text) distributed by (c2);
+CREATE TABLE table_3_cols_dist_c3(c1 text, c2 text, c3 text) distributed by (c3);
+
+COPY table_1_col_dist_c1 FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+COPY table_2_cols_dist_c1 FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+COPY table_2_cols_dist_c2 FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+COPY table_3_cols_dist_c1 FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+COPY table_3_cols_dist_c2 FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+COPY table_3_cols_dist_c3 FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+
+SELECT count(*) FROM table_1_col_dist_c1;
+SELECT count(*) FROM table_2_cols_dist_c1;
+SELECT count(*) FROM table_2_cols_dist_c2;
+SELECT count(*) FROM table_3_cols_dist_c1;
+SELECT count(*) FROM table_3_cols_dist_c2;
+SELECT count(*) FROM table_3_cols_dist_c3;
+
+DROP TABLE table_1_col_dist_c1;
+DROP TABLE table_2_cols_dist_c1;
+DROP TABLE table_2_cols_dist_c2;
+DROP TABLE table_3_cols_dist_c1;
+DROP TABLE table_3_cols_dist_c2;
+DROP TABLE table_3_cols_dist_c3;
+
+-- special case, tables without columns
+CREATE TABLE table_no_cols();
+INSERT INTO table_no_cols DEFAULT VALUES;
+SELECT count(*) FROM table_no_cols;
+COPY table_no_cols TO '@abs_srcdir@/data/copy_no_cols.data' DELIMITER ',';
+COPY table_no_cols FROM '@abs_srcdir@/data/copy_no_cols.data' DELIMITER ',';
+SELECT count(*) FROM table_no_cols;
+COPY table_no_cols FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+DROP TABLE table_no_cols;
diff --git a/src/test/regress/output/copy.source b/src/test/regress/output/copy.source
index 2eae9eca82..c5dcfeba3d 100644
--- a/src/test/regress/output/copy.source
+++ b/src/test/regress/output/copy.source
@@ -265,3 +265,94 @@ drop trigger check_after_tab_progress_reporting on tab_progress_reporting;
ERROR: trigger "check_after_tab_progress_reporting" for table "tab_progress_reporting" does not exist
drop function notice_after_tab_progress_reporting();
drop table tab_progress_reporting;
+-- check COPY behavior
+-- there are 2 fields in copy.data
+-- table_1_col_dist_c1: 1 col in table < 2 fields in file
+-- table_2_cols_dist_c1 and
+-- table_2_cols_dist_c2: 2 cols in table = 2 fields in file
+-- table_3_cols_dist_c1 and
+-- table_3_cols_dist_c2 and
+-- table_3_cols_dist_c3: 3 cols in table > 2 fields in file
+CREATE TABLE table_1_col_dist_c1(c1 text) distributed by (c1);
+CREATE TABLE table_2_cols_dist_c1(c1 text, c2 text) distributed by (c1);
+CREATE TABLE table_2_cols_dist_c2(c1 text, c2 text) distributed by (c2);
+CREATE TABLE table_3_cols_dist_c1(c1 text, c2 text, c3 text) distributed by (c1);
+CREATE TABLE table_3_cols_dist_c2(c1 text, c2 text, c3 text) distributed by (c2);
+CREATE TABLE table_3_cols_dist_c3(c1 text, c2 text, c3 text) distributed by (c3);
+COPY table_1_col_dist_c1 FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+ERROR: extra data after last expected column
+CONTEXT: COPY table_1_col_dist_c1, line 1: "1,text1"
+COPY table_2_cols_dist_c1 FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+COPY table_2_cols_dist_c2 FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+COPY table_3_cols_dist_c1 FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+ERROR: missing data for column "c3"
+CONTEXT: COPY table_3_cols_dist_c1, line 1: "1,text1"
+COPY table_3_cols_dist_c2 FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+ERROR: missing data for column "c3"
+CONTEXT: COPY table_3_cols_dist_c2, line 1: "1,text1"
+COPY table_3_cols_dist_c3 FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+ERROR: missing data for column "c3"
+CONTEXT: COPY table_3_cols_dist_c3, line 1: "1,text1"
+SELECT count(*) FROM table_1_col_dist_c1;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM table_2_cols_dist_c1;
+ count
+-------
+ 1
+(1 row)
+
+SELECT count(*) FROM table_2_cols_dist_c2;
+ count
+-------
+ 1
+(1 row)
+
+SELECT count(*) FROM table_3_cols_dist_c1;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM table_3_cols_dist_c2;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM table_3_cols_dist_c3;
+ count
+-------
+ 0
+(1 row)
+
+DROP TABLE table_1_col_dist_c1;
+DROP TABLE table_2_cols_dist_c1;
+DROP TABLE table_2_cols_dist_c2;
+DROP TABLE table_3_cols_dist_c1;
+DROP TABLE table_3_cols_dist_c2;
+DROP TABLE table_3_cols_dist_c3;
+-- special case, tables without columns
+CREATE TABLE table_no_cols();
+INSERT INTO table_no_cols DEFAULT VALUES;
+SELECT count(*) FROM table_no_cols;
+ count
+-------
+ 1
+(1 row)
+
+COPY table_no_cols TO '@abs_srcdir@/data/copy_no_cols.data' DELIMITER ',';
+COPY table_no_cols FROM '@abs_srcdir@/data/copy_no_cols.data' DELIMITER ',';
+SELECT count(*) FROM table_no_cols;
+ count
+-------
+ 2
+(1 row)
+
+COPY table_no_cols FROM '@abs_srcdir@/data/copy.data' DELIMITER ',';
+ERROR: extra data after last expected column
+CONTEXT: COPY table_no_cols, line 1: "1,text1"
+DROP TABLE table_no_cols;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org