Skip to content
Merged
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
8 changes: 7 additions & 1 deletion src/backend/optimizer/plan/createplan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ create_external_scan_uri_list(ExtTableEntry *ext, bool *ismasteronly)
* protocols only */
on_clause = (char *) strVal(linitial(ext->execlocations));
if ((strcmp(on_clause, "MASTER_ONLY") == 0)
&& using_location && (uri->protocol != URI_CUSTOM)) {
&& using_location && (uri->protocol != URI_CUSTOM && uri->protocol != URI_FILE)) {
ereport(ERROR, (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
errmsg("\'ON MASTER\' is not supported by this protocol yet")));
}
Expand Down Expand Up @@ -1670,6 +1670,12 @@ create_external_scan_uri_list(ExtTableEntry *ext, bool *ismasteronly)
found_candidate = false;
found_match = false;

if ((strcmp(on_clause, "MASTER_ONLY") == 0) && uri->protocol == URI_FILE)
{
found_match = true;
segdb_file_map[0] = pstrdup(uri_str);
*ismasteronly = true;
}
/*
* look through our segment database list and try to find a
* database that can handle this uri.
Expand Down
14 changes: 13 additions & 1 deletion src/test/regress/input/external_table.source
Original file line number Diff line number Diff line change
Expand Up @@ -1385,10 +1385,22 @@ SELECT COUNT(*) FROM gp_read_error_log('exttab_heap_join_1');
\! rm @abs_srcdir@/data/tableless.csv

-- start_ignore
DROP EXTERNAL TABLE IF EXISTS ext_nation_on_master;
DROP EXTERNAL TABLE IF EXISTS exttab_with_on_master;
-- end_ignore

-- Create external table with on clause
-- Create external table on master
-- good, should fetch data from master
CREATE EXTERNAL TABLE ext_nation_on_master ( N_NATIONKEY INTEGER ,
N_NAME CHAR(25) ,
N_REGIONKEY INTEGER ,
N_COMMENT VARCHAR(152))
location ('file://@hostname@@abs_srcdir@/data/nation.tbl' ) ON MASTER
FORMAT 'text' (delimiter '|');
SELECT gp_segment_id, * FROM ext_nation_on_master ORDER BY N_NATIONKEY DESC LIMIT 5;
DROP EXTERNAL TABLE IF EXISTS ext_nation_on_master;

-- bad, should error
CREATE EXTERNAL TABLE exttab_with_on_master( i int, j text )
LOCATION ('file://@hostname@@abs_srcdir@/data/exttab_few_errors.data') ON MASTER FORMAT 'TEXT' (DELIMITER '|');

Expand Down
26 changes: 24 additions & 2 deletions src/test/regress/output/external_table.source
Original file line number Diff line number Diff line change
Expand Up @@ -2680,14 +2680,36 @@ SELECT COUNT(*) FROM gp_read_error_log('exttab_heap_join_1');

\! rm @abs_srcdir@/data/tableless.csv
-- start_ignore
DROP EXTERNAL TABLE IF EXISTS ext_nation_on_master;
NOTICE: table "ext_nation_on_master" does not exist, skipping
DROP EXTERNAL TABLE IF EXISTS exttab_with_on_master;
NOTICE: table "exttab_with_on_master" does not exist, skipping
-- end_ignore
-- Create external table with on clause
-- Create external table on master
-- good, should fetch data from master
CREATE EXTERNAL TABLE ext_nation_on_master ( N_NATIONKEY INTEGER ,
N_NAME CHAR(25) ,
N_REGIONKEY INTEGER ,
N_COMMENT VARCHAR(152))
location ('file://@hostname@@abs_srcdir@/data/nation.tbl' ) ON MASTER
FORMAT 'text' (delimiter '|');
SELECT gp_segment_id, * FROM ext_nation_on_master ORDER BY N_NATIONKEY DESC LIMIT 5;
gp_segment_id | n_nationkey | n_name | n_regionkey | n_comment
---------------+-------------+---------------------------+-------------+----------------------------------------------------------------------------------------------------------------
-1 | 24 | UNITED STATES | 1 | y final packages. slow foxes cajole quickly. quickly silent platelets breach ironic accounts. unusual pinto be
-1 | 23 | UNITED KINGDOM | 3 | eans boost carefully special requests. accounts are. carefull
-1 | 22 | RUSSIA | 3 | requests against the platelets use never according to the quickly regular pint
-1 | 21 | VIETNAM | 2 | hely enticingly express accounts. even, final
-1 | 20 | SAUDI ARABIA | 4 | ts. silent requests haggle. closely express packages sleep across the blithely
(5 rows)

DROP EXTERNAL TABLE IF EXISTS ext_nation_on_master;
-- bad, should error
CREATE EXTERNAL TABLE exttab_with_on_master( i int, j text )
LOCATION ('file://@hostname@@abs_srcdir@/data/exttab_few_errors.data') ON MASTER FORMAT 'TEXT' (DELIMITER '|');
SELECT * FROM exttab_with_on_master;
ERROR: 'ON MASTER' is not supported by this protocol yet
ERROR: invalid input syntax for integer: "error_0"
CONTEXT: External table exttab_with_on_master, line 3 of file://@hostname@@abs_srcdir@/data/exttab_few_errors.data, column i
DROP EXTERNAL TABLE IF EXISTS exttab_with_on_master;
-- start_ignore
DROP EXTERNAL TABLE IF EXISTS exttab_with_option_empty;
Expand Down
Loading