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
37 changes: 36 additions & 1 deletion tea/gpext/tea_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "access/reloptions.h"
#include "access/sysattr.h"
#include "catalog/namespace.h"
#include "catalog/pg_foreign_table.h"
#include "cdb/cdbsreh.h"
#include "cdb/cdbutil.h"
#include "cdb/cdbvars.h"
Expand Down Expand Up @@ -1041,7 +1042,41 @@ Datum tea_fdw_handler(PG_FUNCTION_ARGS) {
*
* Raise an ERROR if the option or its value is considered invalid.
*/
Datum tea_fdw_validator(PG_FUNCTION_ARGS) { PG_RETURN_VOID(); }
Datum tea_fdw_validator(PG_FUNCTION_ARGS) {
Oid catalog = PG_GETARG_OID(1);
List* options_list;
DefElem* def;
char* val;

if (catalog != ForeignTableRelationId) PG_RETURN_VOID();

options_list = untransformRelOptions(PG_GETARG_DATUM(0));

if (list_length(options_list) != 1) {
if (list_length(options_list) == 0)
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("missing required option \"location\""),
errdetail("The TEA foreign data wrapper requires exactly one option: \"location\".")));
else
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("too many options provided"),
errdetail("The TEA foreign data wrapper requires exactly one option: \"location\"."),
errhint("Remove extra options.")));
}

def = (DefElem*)linitial(options_list);

if (strcmp(def->defname, "location") != 0) {
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid option \"%s\"", def->defname),
errhint("The only valid option for TEA foreign tables is \"location\".")));
}

val = def->arg ? strVal(def->arg) : NULL;
if (!val || !*val) {
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("option \"location\" value cannot be empty")));
}

list_free(options_list);
PG_RETURN_VOID();
}

#ifdef FDW_GET_CREATE_QUERY
Datum tea_fdw_get_create_query(PG_FUNCTION_ARGS) {
Expand Down
8 changes: 7 additions & 1 deletion tea/gpext/tea_fdw_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "commands/defrem.h"
#include "foreign/foreign.h"
#include "utils/elog.h"
#include "utils/errcodes.h"

char* TeaGetLocation(Oid foreigntableid) {
ForeignTable* table;
Expand All @@ -16,5 +18,9 @@ char* TeaGetLocation(Oid foreigntableid) {
return defGetString(def);
}
}
return NULL;

ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("missing required option \"location\" for foreign table %u", foreigntableid),
errdetail("The TEA foreign data wrapper requires the \"location\" option to be specified."),
errhint("Recreate the foreign table with OPTIONS (location '...').")));
}
Loading