提交 f425e97c 编写于 作者: H Heikki Linnakangas

Add function for throwing ereport-like errors from gpopt code.

This allows us to have the exact same error message and hint for errors,
as what the traditional planner produces. That makes testing easier, as
you don't need to have a different expected output file for ORCA and
non-ORCA. And allows for more structured errors anyway.

Use the new function for the case of trying to read from a WRITABLE
external table. There was no test for that in the main test suite
previously. There was one in the gpfdist suite, but that's not really the
right place, as that error is caught the same way regardless of the
protocol. While we're at it, re-word the error message and change the error
code to follow the Postgres error message style guide.
上级 994f5418
......@@ -1873,6 +1873,35 @@ gpdb::SzMemoryContextStrdup
return NULL;
}
// Helper function to throw an error with errcode, message and hint, like you
// would with ereport(...) in the backend. This could be extended for other
// fields, but this is all we need at the moment.
void
gpdb::RaiseGpdbErrorImpl
(
int xerrcode,
const char *xerrmsg,
const char *xerrhint,
const char *filename,
int lineno,
const char *funcname
)
{
GP_WRAP_START;
{
// We cannot use the ereport() macro here, because we want to pass on
// the caller's filename and line number. This is essentially an
// expanded version of ereport(). It will be caught by the
// GP_WRAP_END, and propagated up as a C++ exception, to be
// re-thrown as a Postgres error once we leave the C++ land.
if (errstart(ERROR, filename, lineno, funcname, TEXTDOMAIN))
errfinish (errcode(xerrcode),
errmsg("%s", xerrmsg),
xerrhint ? errhint("%s", xerrhint) : 0);
}
GP_WRAP_END;
}
char *
gpdb::SzNodeToString
(
......
......@@ -969,8 +969,10 @@ CTranslatorDXLToPlStmt::PlExternalScanUriList
if (extentry->iswritable)
{
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiDXL2PlStmtExternalScanError,
GPOS_WSZ_LIT("It is not possible to read from a WRITABLE external table. Create the table as READABLE instead."));
// This should match the same error in createplan.c
RaiseGpdbError(ERRCODE_WRONG_OBJECT_TYPE, // errcode
"cannot read from a WRITABLE external table", // errmsg
"Create the table as READABLE instead."); // errhint
}
//get the total valid primary segdb count
......@@ -997,8 +999,10 @@ CTranslatorDXLToPlStmt::PlExternalScanUriList
{
if (!gp_external_enable_exec)
{
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiDXL2PlStmtExternalScanError,
GPOS_WSZ_LIT("Using external tables with OS level commands is disabled. Use (set gp_external_enable_exec = on) to enable"));
// This should match the same error in createplan.c
RaiseGpdbError(ERRCODE_GP_FEATURE_NOT_CONFIGURED, // errcode
"Using external tables with OS level commands (EXECUTE clause) is disabled", // errmsg
"To enable set gp_external_enable_exec=on"); // errhint
}
fUsingExecute = true;
}
......
......@@ -1247,9 +1247,9 @@ create_externalscan_plan(PlannerInfo *root, Path *best_path,
if (rel->writable)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("it is not possible to read from a WRITABLE external table."),
errhint("Create the table as READABLE instead")));
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot read from a WRITABLE external table"),
errhint("Create the table as READABLE instead.")));
if (rel->rejectlimit != -1)
......
......@@ -445,11 +445,6 @@ create readable external table ret_region(like wet_region) location('gpfdist://@
create writable external table wet_neg1(a text, b text) location('file://@hostname@@abs_srcdir@/badt1.tbl') format 'text';
create writable external web table wet_pos5(a text, b text) execute 'some command' on segment 0 format 'text';
--
-- SELECT from WET (negative)
--
select * from wet_pos1;
--
-- WET: export some data with INSERT SELECT, INSERT and COPY.
--
......
......@@ -708,12 +708,6 @@ HINT: Writable external tables may use 'gpfdist', 'gpfdists' or 'gphdfs' URIs o
create writable external web table wet_pos5(a text, b text) execute 'some command' on segment 0 format 'text';
ERROR: ON clause may not be used with a writable external table
--
-- SELECT from WET (negative)
--
select * from wet_pos1;
ERROR: it is not possible to read from a WRITABLE external table.
HINT: Create the table as READABLE instead
--
-- WET: export some data with INSERT SELECT, INSERT and COPY.
--
COPY reg_region FROM STDIN DELIMITER '|';
......
......@@ -417,6 +417,11 @@ namespace gpdb {
// create a duplicate of the given string in the given memory context
char *SzMemoryContextStrdup(MemoryContext context, const char *string);
// ereport() an error
void RaiseGpdbErrorImpl(int xerrcode, const char *xerrmsg, const char *xerrhint, const char *filename, int lineno, const char *funcname);
#define RaiseGpdbError(xerrcode, xerrmsg, xerrhint) \
gpdb::RaiseGpdbErrorImpl(xerrcode, xerrmsg, xerrhint , __FILE__, __LINE__, PG_FUNCNAME_MACRO)
// string representation of a node
char *SzNodeToString(void *obj);
......
......@@ -196,6 +196,10 @@ create writable external web table wet_pos4(a text, b text) execute 'some comman
create writable external table wet_neg1(a text, b text) location('file://@hostname@@abs_srcdir@/badt1.tbl') format 'text';
create writable external table wet_neg1(a text, b text) location('gpfdist://foo:7070/wet.out', 'gpfdist://foo:7070/wet.out') format 'text';
create writable external web table wet_pos5(a text, b text) execute 'some command' on segment 0 format 'text';
-- cannot read from a WRITABLE external table.
select * from wet_pos4;
--
-- test CREATE EXTERNAL TABLE privileges
--
......
......@@ -296,6 +296,10 @@ LINE 1: ...t, b text) location('gpfdist://foo:7070/wet.out', 'gpfdist:/...
^
create writable external web table wet_pos5(a text, b text) execute 'some command' on segment 0 format 'text';
ERROR: ON clause may not be used with a writable external table
-- cannot read from a WRITABLE external table.
select * from wet_pos4;
ERROR: cannot read from a WRITABLE external table
HINT: Create the table as READABLE instead.
--
-- test CREATE EXTERNAL TABLE privileges
--
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册