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
The following commit(s) were added to refs/heads/main by this push:
new c7e03983e5a Fix: check and ereport error in external table
c7e03983e5a is described below
commit c7e03983e5a356ded3ec32bf6257a8e99e57fb02
Author: liushengsong <[email protected]>
AuthorDate: Mon Oct 13 17:15:57 2025 +0800
Fix: check and ereport error in external table
In external table with CFTYPE_EXEC. We check and ereport
error when external_getnext return null.
---
gpcontrib/gp_exttable_fdw/extaccess.c | 23 ++++++++++++++++++++++
src/test/regress/input/external_table.source | 3 +++
src/test/regress/output/external_table.source | 4 ++++
.../regress/output/external_table_optimizer.source | 4 ++++
4 files changed, 34 insertions(+)
diff --git a/gpcontrib/gp_exttable_fdw/extaccess.c
b/gpcontrib/gp_exttable_fdw/extaccess.c
index 08f6a431c66..f52e4c50052 100644
--- a/gpcontrib/gp_exttable_fdw/extaccess.c
+++ b/gpcontrib/gp_exttable_fdw/extaccess.c
@@ -491,6 +491,27 @@ external_getnext_init(PlanState *state)
return desc;
}
+static void
+check_error(FileScanDesc scan)
+{
+ char *relname = RelationGetRelationName(scan->fs_rd);
+ int ebuflen = 512;
+ char ebuf[512];
+
+ ebuf[0] = '\0';
+ /* current only CFTYPE_EXEC will read stderr to ebuf */
+ if (url_ferror(scan->fs_file, -1, ebuf, ebuflen))
+ {
+ if (*ebuf && strlen(ebuf) > 0)
+ ereport(ERROR,
+
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
+ errmsg("external table %s command
ended with error. %s",
+ (relname ? relname :
""), ebuf),
+ errdetail("Command: %s",
scan->fs_file->url)));
+ }
+
+}
+
/* ----------------------------------------------------------------
* external_getnext
*
@@ -530,6 +551,8 @@ external_getnext(FileScanDesc scan, ScanDirection
direction, ExternalSelectDesc
{
FILEDEBUG_2; /* external_getnext returning
EOS */
+ check_error(scan);
+
return NULL;
}
diff --git a/src/test/regress/input/external_table.source
b/src/test/regress/input/external_table.source
index a6c9871215e..662b490fc8d 100644
--- a/src/test/regress/input/external_table.source
+++ b/src/test/regress/input/external_table.source
@@ -3700,3 +3700,6 @@ SELECT logerrors, options from pg_exttable a, pg_class b
where a.reloid = b.oid
DROP EXTERNAL TABLE ext_false;
DROP EXTERNAL TABLE ext_true;
DROP EXTERNAL TABLE ext_persistently;
+
+CREATE EXTERNAL WEB TEMP TABLE test_program_not_exist(content text) EXECUTE
'/xx/seq 1 5' ON MASTER FORMAT 'TEXT';
+SELECT * FROM test_program_not_exist;
\ No newline at end of file
diff --git a/src/test/regress/output/external_table.source
b/src/test/regress/output/external_table.source
index 014c50f55d3..5ef3d1fa5de 100644
--- a/src/test/regress/output/external_table.source
+++ b/src/test/regress/output/external_table.source
@@ -5052,3 +5052,7 @@ SELECT logerrors, options from pg_exttable a, pg_class b
where a.reloid = b.oid
DROP EXTERNAL TABLE ext_false;
DROP EXTERNAL TABLE ext_true;
DROP EXTERNAL TABLE ext_persistently;
+CREATE EXTERNAL WEB TEMP TABLE test_program_not_exist(content text) EXECUTE
'/xx/seq 1 5' ON MASTER FORMAT 'TEXT';
+SELECT * FROM test_program_not_exist;
+DETAIL: Command: execute:/xx/seq 1 5
+ERROR: external table test_program_not_exist command ended with error. sh:
line 1: /xx/seq: No such file or directory
diff --git a/src/test/regress/output/external_table_optimizer.source
b/src/test/regress/output/external_table_optimizer.source
index 4e853662fb3..912c9999c19 100644
--- a/src/test/regress/output/external_table_optimizer.source
+++ b/src/test/regress/output/external_table_optimizer.source
@@ -5054,3 +5054,7 @@ SELECT logerrors, options from pg_exttable a, pg_class b
where a.reloid = b.oid
DROP EXTERNAL TABLE ext_false;
DROP EXTERNAL TABLE ext_true;
DROP EXTERNAL TABLE ext_persistently;
+CREATE EXTERNAL WEB TEMP TABLE test_program_not_exist(content text) EXECUTE
'/xx/seq 1 5' ON MASTER FORMAT 'TEXT';
+SELECT * FROM test_program_not_exist;
+DETAIL: Command: execute:/xx/seq 1 5
+ERROR: external table test_program_not_exist command ended with error. sh:
line 1: /xx/seq: No such file or directory
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]