Fixes text search deparser

pull/7388/head
gurkanindibay 2023-12-26 20:04:37 +03:00
parent f6c94bd35e
commit d95a615907
2 changed files with 34 additions and 12 deletions

View File

@ -15,8 +15,8 @@
#include "pg_version_constants.h"
#include "distributed/commands.h"
#include "distributed/commands/utility_hook.h"
#include "distributed/comment.h"
#include "distributed/commands/utility_hook.h"
#include "distributed/deparser.h"
#include "distributed/version_compat.h"
@ -995,13 +995,13 @@ static DistributeObjectOps TextSearchConfig_AlterOwner = {
.markDistributed = false,
};
static DistributeObjectOps TextSearchConfig_Comment = {
.deparse = DeparseTextSearchConfigurationCommentStmt,
.deparse = DeparseCommentStmt,
.qualify = QualifyTextSearchConfigurationCommentStmt,
.preprocess = PreprocessAlterDistributedObjectStmt,
.postprocess = NULL,
.objectType = OBJECT_TSCONFIGURATION,
.operationType = DIST_OPS_ALTER,
.address = TextSearchConfigurationCommentObjectAddress,
.address = CommentObjectAddress,
.markDistributed = false,
};
static DistributeObjectOps TextSearchConfig_Define = {
@ -1064,13 +1064,13 @@ static DistributeObjectOps TextSearchDict_AlterOwner = {
.markDistributed = false,
};
static DistributeObjectOps TextSearchDict_Comment = {
.deparse = DeparseTextSearchDictionaryCommentStmt,
.deparse = DeparseCommentStmt,
.qualify = QualifyTextSearchDictionaryCommentStmt,
.preprocess = PreprocessAlterDistributedObjectStmt,
.postprocess = NULL,
.objectType = OBJECT_TSDICTIONARY,
.operationType = DIST_OPS_ALTER,
.address = TextSearchDictCommentObjectAddress,
.address = CommentObjectAddress,
.markDistributed = false,
};
static DistributeObjectOps TextSearchDict_Define = {

View File

@ -17,6 +17,7 @@
#include "nodes/parsenodes.h"
#include "parser/parse_type.h"
#include "utils/builtins.h"
#include "utils/elog.h"
#include "pg_version_compat.h"
@ -27,12 +28,18 @@
#include "distributed/log_utils.h"
const char *const ObjectTypeNames[] =
typedef struct
{
[OBJECT_DATABASE] = "DATABASE",
[OBJECT_ROLE] = "ROLE",
[OBJECT_TSCONFIGURATION] = "TEXT SEARCH CONFIGURATION",
[OBJECT_TSDICTIONARY] = "TEXT SEARCH DICTIONARY",
char *name;
int type;
} ObjectTypeInfo;
const ObjectTypeInfo ObjectTypeNames[] =
{
[OBJECT_DATABASE] = { "DATABASE", T_String },
[OBJECT_ROLE] = { "ROLE", T_String },
[OBJECT_TSCONFIGURATION] = { "TEXT SEARCH CONFIGURATION", T_List },
[OBJECT_TSDICTIONARY] = { "TEXT SEARCH DICTIONARY", T_List },
/* etc. */
};
@ -44,8 +51,23 @@ DeparseCommentStmt(Node *node)
StringInfoData str = { 0 };
initStringInfo(&str);
const char *objectName = quote_identifier(strVal(stmt->object));
const char *objectType = ObjectTypeNames[stmt->objtype];
const char *objectName = NULL;
if (ObjectTypeNames[stmt->objtype].type == T_String)
{
objectName = quote_identifier(strVal(stmt->object));
}
else if (ObjectTypeNames[stmt->objtype].type == T_List)
{
objectName = NameListToQuotedString(castNode(List, stmt->object));
}
else
{
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("unknown object type")));
}
const char *objectType = ObjectTypeNames[stmt->objtype].name;
char *comment = stmt->comment != NULL ? quote_literal_cstr(stmt->comment) : "NULL";