Skip to content

Commit

Permalink
Previously, Babelfish displays the mapped schema names in error messa…
Browse files Browse the repository at this point in the history
…ges. This commit imports a hook function remove_db_name_in_schema and uses it to restore thr unmapped name. Original unmapped name will be displayed with this commit.

Signed-off-by: Chenxiao Wang <[email protected]>
  • Loading branch information
Chenxiao Wang committed Dec 24, 2024
1 parent f424e4d commit 1bca96b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/backend/catalog/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ char *SYS_NAMESPACE_NAME = "sys";

relname_lookup_hook_type relname_lookup_hook = NULL;
match_pltsql_func_call_hook_type match_pltsql_func_call_hook = NULL;
remove_db_name_in_schema_hook_type remove_db_name_in_schema_hook = NULL;


/* Local functions */
Expand Down Expand Up @@ -3633,10 +3634,16 @@ get_namespace_oid(const char *nspname, bool missing_ok)
oid = GetSysCacheOid1(NAMESPACENAME, Anum_pg_namespace_oid,
CStringGetDatum(nspname));
if (!OidIsValid(oid) && !missing_ok)
{
if (sql_dialect == SQL_DIALECT_TSQL && remove_db_name_in_schema_hook)
{
nspname = (*remove_db_name_in_schema_hook)(nspname);
}
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", nspname)));

}
return oid;
}

Expand Down
4 changes: 4 additions & 0 deletions src/backend/parser/parse_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,10 @@ funcname_signature_string(const char *funcname, int nargs,

initStringInfo(&argbuf);

if (sql_dialect == SQL_DIALECT_TSQL && remove_db_name_in_schema_hook) {
funcname = (*remove_db_name_in_schema_hook)(funcname);
}

appendStringInfo(&argbuf, "%s(", funcname);

numposargs = nargs - list_length(argnames);
Expand Down
9 changes: 9 additions & 0 deletions src/backend/parser/parse_relation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1453,10 +1453,19 @@ parserOpenTable(ParseState *pstate, const RangeVar *relation, int lockmode)
if (rel == NULL)
{
if (relation->schemaname)
{
if (sql_dialect == SQL_DIALECT_TSQL && remove_db_name_in_schema_hook){
const char *schema_name = (*remove_db_name_in_schema_hook)(relation->schemaname);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation \"%s.%s\" does not exist",
schema_name, relation->relname)));
} else
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("relation \"%s.%s\" does not exist",
relation->schemaname, relation->relname)));
}
else
{
/*
Expand Down
2 changes: 2 additions & 0 deletions src/include/catalog/namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ typedef bool (*match_pltsql_func_call_hook_type) (HeapTuple proctup, int nargs,
bool *use_defaults, bool *any_special,
bool *variadic, Oid *va_elem_type);
extern PGDLLEXPORT match_pltsql_func_call_hook_type match_pltsql_func_call_hook;
typedef const char * (*remove_db_name_in_schema_hook_type) (const char *schema_name);
extern PGDLLEXPORT remove_db_name_in_schema_hook_type remove_db_name_in_schema_hook;

#define RangeVarGetRelid(relation, lockmode, missing_ok) \
RangeVarGetRelidExtended(relation, lockmode, \
Expand Down
2 changes: 2 additions & 0 deletions src/include/parser/parse_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,7 @@ typedef void (*make_fn_arguments_from_stored_proc_probin_hook_type)(ParseState *
extern PGDLLEXPORT make_fn_arguments_from_stored_proc_probin_hook_type make_fn_arguments_from_stored_proc_probin_hook;
typedef void (*report_proc_not_found_error_hook_type) (List *names, List *fargs, List *argnames, Oid *input_typeids, int nargs, ParseState *pstate, int location, bool proc_call);
extern PGDLLEXPORT report_proc_not_found_error_hook_type report_proc_not_found_error_hook;
typedef const char * (*remove_db_name_in_schema_hook_type) (const char *schema_name);
extern PGDLLEXPORT remove_db_name_in_schema_hook_type remove_db_name_in_schema_hook;

#endif /* PARSE_FUNC_H */

0 comments on commit 1bca96b

Please sign in to comment.