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

View File

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