Skip to content

Commit c7e0398

Browse files
lss602726449my-ship-it
authored andcommitted
Fix: check and ereport error in external table
In external table with CFTYPE_EXEC. We check and ereport error when external_getnext return null.
1 parent c3be6e5 commit c7e0398

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

gpcontrib/gp_exttable_fdw/extaccess.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,27 @@ external_getnext_init(PlanState *state)
491491
return desc;
492492
}
493493

494+
static void
495+
check_error(FileScanDesc scan)
496+
{
497+
char *relname = RelationGetRelationName(scan->fs_rd);
498+
int ebuflen = 512;
499+
char ebuf[512];
500+
501+
ebuf[0] = '\0';
502+
/* current only CFTYPE_EXEC will read stderr to ebuf */
503+
if (url_ferror(scan->fs_file, -1, ebuf, ebuflen))
504+
{
505+
if (*ebuf && strlen(ebuf) > 0)
506+
ereport(ERROR,
507+
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
508+
errmsg("external table %s command ended with error. %s",
509+
(relname ? relname : ""), ebuf),
510+
errdetail("Command: %s", scan->fs_file->url)));
511+
}
512+
513+
}
514+
494515
/* ----------------------------------------------------------------
495516
* external_getnext
496517
*
@@ -530,6 +551,8 @@ external_getnext(FileScanDesc scan, ScanDirection direction, ExternalSelectDesc
530551
{
531552
FILEDEBUG_2; /* external_getnext returning EOS */
532553

554+
check_error(scan);
555+
533556
return NULL;
534557
}
535558

src/test/regress/input/external_table.source

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,3 +3700,6 @@ SELECT logerrors, options from pg_exttable a, pg_class b where a.reloid = b.oid
37003700
DROP EXTERNAL TABLE ext_false;
37013701
DROP EXTERNAL TABLE ext_true;
37023702
DROP EXTERNAL TABLE ext_persistently;
3703+
3704+
CREATE EXTERNAL WEB TEMP TABLE test_program_not_exist(content text) EXECUTE '/xx/seq 1 5' ON MASTER FORMAT 'TEXT';
3705+
SELECT * FROM test_program_not_exist;

src/test/regress/output/external_table.source

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5052,3 +5052,7 @@ SELECT logerrors, options from pg_exttable a, pg_class b where a.reloid = b.oid
50525052
DROP EXTERNAL TABLE ext_false;
50535053
DROP EXTERNAL TABLE ext_true;
50545054
DROP EXTERNAL TABLE ext_persistently;
5055+
CREATE EXTERNAL WEB TEMP TABLE test_program_not_exist(content text) EXECUTE '/xx/seq 1 5' ON MASTER FORMAT 'TEXT';
5056+
SELECT * FROM test_program_not_exist;
5057+
DETAIL: Command: execute:/xx/seq 1 5
5058+
ERROR: external table test_program_not_exist command ended with error. sh: line 1: /xx/seq: No such file or directory

src/test/regress/output/external_table_optimizer.source

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5054,3 +5054,7 @@ SELECT logerrors, options from pg_exttable a, pg_class b where a.reloid = b.oid
50545054
DROP EXTERNAL TABLE ext_false;
50555055
DROP EXTERNAL TABLE ext_true;
50565056
DROP EXTERNAL TABLE ext_persistently;
5057+
CREATE EXTERNAL WEB TEMP TABLE test_program_not_exist(content text) EXECUTE '/xx/seq 1 5' ON MASTER FORMAT 'TEXT';
5058+
SELECT * FROM test_program_not_exist;
5059+
DETAIL: Command: execute:/xx/seq 1 5
5060+
ERROR: external table test_program_not_exist command ended with error. sh: line 1: /xx/seq: No such file or directory

0 commit comments

Comments
 (0)