diff --git a/tea/gpext/tea_fdw.c b/tea/gpext/tea_fdw.c index 30e65ee..21b971e 100644 --- a/tea/gpext/tea_fdw.c +++ b/tea/gpext/tea_fdw.c @@ -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" @@ -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) { diff --git a/tea/gpext/tea_fdw_options.c b/tea/gpext/tea_fdw_options.c index 6353de1..ad3fc6a 100644 --- a/tea/gpext/tea_fdw_options.c +++ b/tea/gpext/tea_fdw_options.c @@ -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; @@ -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 '...')."))); }