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/06 08:19:56 UTC

(cloudberry) 06/12: Set the default value for option execute_on of gp_exttable_fdw (#14797)

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 934f513db4391a51b47947287107acfb77558b01
Author: Jingwen Yang <ji...@outlook.com>
AuthorDate: Thu Feb 9 11:00:20 2023 +0800

    Set the default value for option execute_on of gp_exttable_fdw (#14797)
    
    * This commit is to fix issue #14528.
    
    Now we usually use CREATE EXTERNAL TABLE syntax to create an external table in gpdb, which can set default value while missing some options, such as option `execute_on`.
    
    But if we use CREATE FOREIGN TABLE syntax to create an external table, it won't set the default value while missing option `execute_on`.
    In this case, missing option `execute_on` will cause gpdb crashing. (Issue #14528)
    
    In this commit, when using CREATE FOREIGN TABLE syntax to create an external table and missing option `execute_on` , we will set default value for option `execute_on`.
---
 gpcontrib/Makefile                                  |  1 +
 gpcontrib/gp_exttable_fdw/Makefile                  |  2 +-
 gpcontrib/gp_exttable_fdw/data/tableless.csv        |  3 +++
 .../gp_exttable_fdw/input/gp_exttable_fdw.source    | 17 +++++++++++++++++
 .../gp_exttable_fdw/output/gp_exttable_fdw.source   | 21 +++++++++++++++++++++
 src/backend/access/external/external.c              |  7 +++++++
 6 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/gpcontrib/Makefile b/gpcontrib/Makefile
index 4750a8ce8a..5360083164 100644
--- a/gpcontrib/Makefile
+++ b/gpcontrib/Makefile
@@ -98,3 +98,4 @@ installcheck:
 	if [ "$(with_quicklz)" = "yes" ]; then $(MAKE) -C quicklz installcheck; fi
 	$(MAKE) -C gp_sparse_vector installcheck
 	$(MAKE) -C gp_toolkit installcheck
+	$(MAKE) -C gp_exttable_fdw installcheck
diff --git a/gpcontrib/gp_exttable_fdw/Makefile b/gpcontrib/gp_exttable_fdw/Makefile
index c38c05278d..2d31fbe597 100644
--- a/gpcontrib/gp_exttable_fdw/Makefile
+++ b/gpcontrib/gp_exttable_fdw/Makefile
@@ -8,7 +8,7 @@ OBJS = gp_exttable_fdw.o extaccess.o
 EXTENSION = gp_exttable_fdw
 DATA = gp_exttable_fdw--1.0.sql
 
-REGRESS =
+REGRESS = gp_exttable_fdw
 
 HEADERS = extaccess.h
 
diff --git a/gpcontrib/gp_exttable_fdw/data/tableless.csv b/gpcontrib/gp_exttable_fdw/data/tableless.csv
new file mode 100644
index 0000000000..2fc500fd9f
--- /dev/null
+++ b/gpcontrib/gp_exttable_fdw/data/tableless.csv
@@ -0,0 +1,3 @@
+1,12
+2,22
+3,32
diff --git a/gpcontrib/gp_exttable_fdw/input/gp_exttable_fdw.source b/gpcontrib/gp_exttable_fdw/input/gp_exttable_fdw.source
new file mode 100644
index 0000000000..089de06ba1
--- /dev/null
+++ b/gpcontrib/gp_exttable_fdw/input/gp_exttable_fdw.source
@@ -0,0 +1,17 @@
+--
+-- Test foreign-data wrapper gp_exttable_fdw.
+--
+
+CREATE EXTENSION IF NOT EXISTS gp_exttable_fdw;
+
+CREATE SERVER IF NOT EXISTS gp_exttable_server FOREIGN DATA WRAPPER gp_exttable_fdw;
+
+-- create table without execute_on option
+CREATE FOREIGN TABLE tableless_ext_fdw(a int, b int)
+SERVER gp_exttable_server
+OPTIONS (format 'csv', delimiter ',', format_type 'c',
+         location_uris 'file://@hostname@@abs_srcdir@/data/tableless.csv',
+         log_errors 'f', encoding '6', is_writable 'false');
+
+SELECT * FROM tableless_ext_fdw;
+
diff --git a/gpcontrib/gp_exttable_fdw/output/gp_exttable_fdw.source b/gpcontrib/gp_exttable_fdw/output/gp_exttable_fdw.source
new file mode 100644
index 0000000000..d25e622dd4
--- /dev/null
+++ b/gpcontrib/gp_exttable_fdw/output/gp_exttable_fdw.source
@@ -0,0 +1,21 @@
+--
+-- Test foreign-data wrapper gp_exttable_fdw.
+--
+CREATE EXTENSION IF NOT EXISTS gp_exttable_fdw;
+NOTICE:  extension "gp_exttable_fdw" already exists, skipping
+CREATE SERVER IF NOT EXISTS gp_exttable_server FOREIGN DATA WRAPPER gp_exttable_fdw;
+NOTICE:  server "gp_exttable_server" already exists, skipping
+-- create table without execute_on option
+CREATE FOREIGN TABLE tableless_ext_fdw(a int, b int)
+SERVER gp_exttable_server
+OPTIONS (format 'csv', delimiter ',', format_type 'c',
+         location_uris 'file://@hostname@@abs_srcdir@/data/tableless.csv',
+         log_errors 'f', encoding '6', is_writable 'false');
+SELECT * FROM tableless_ext_fdw;
+ a | b  
+---+----
+ 1 | 12
+ 2 | 22
+ 3 | 32
+(3 rows)
+
diff --git a/src/backend/access/external/external.c b/src/backend/access/external/external.c
index 3909194062..549d74c7cd 100644
--- a/src/backend/access/external/external.c
+++ b/src/backend/access/external/external.c
@@ -179,6 +179,7 @@ GetExtFromForeignTableOptions(List *ftoptons, Oid relid)
 	bool				iswritable_found = false;
 	bool				locationuris_found = false;
 	bool				command_found = false;
+	bool				executeon_found = false;
 
 	extentry = (ExtTableEntry *) palloc0(sizeof(ExtTableEntry));
 
@@ -196,6 +197,7 @@ GetExtFromForeignTableOptions(List *ftoptons, Oid relid)
 		if (pg_strcasecmp(def->defname, "execute_on") == 0)
 		{
 			extentry->execlocations = list_make1(makeString(defGetString(def)));
+			executeon_found = true;
 			continue;
 		}
 
@@ -298,6 +300,11 @@ GetExtFromForeignTableOptions(List *ftoptons, Oid relid)
 	else
 		extentry->rejectlimittype = -1;
 
+	if (!executeon_found)
+	{
+		extentry->execlocations = list_make1(makeString("ALL_SEGMENTS"));
+	}
+
 	if (!PG_VALID_ENCODING(extentry->encoding))
 		elog(ERROR, "invalid encoding found for external table");
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org