Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions gpcontrib/gp_exttable_fdw/extaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,24 @@ external_getnext_init(PlanState *state)
return desc;
}

static void
check_error(FileScanDesc scan)
{
char *relname = pstrdup(RelationGetRelationName(scan->fs_rd));
int ebuflen = 512;
char *ebuf = palloc0(ebuflen);

/* current only CFTYPE_EXEC will read stderr to ebuf */
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
*
Expand Down Expand Up @@ -530,6 +548,8 @@ external_getnext(FileScanDesc scan, ScanDirection direction, ExternalSelectDesc
{
FILEDEBUG_2; /* external_getnext returning EOS */

check_error(scan);

return NULL;
}

Expand Down
3 changes: 3 additions & 0 deletions src/test/regress/input/external_table.source
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 4 additions & 0 deletions src/test/regress/output/external_table.source
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/test/regress/output/external_table_optimizer.source
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading