diff --git a/src/backend/distributed/commands/distribute_object_ops.c b/src/backend/distributed/commands/distribute_object_ops.c index 31891eae8..6e39f9d38 100644 --- a/src/backend/distributed/commands/distribute_object_ops.c +++ b/src/backend/distributed/commands/distribute_object_ops.c @@ -306,7 +306,7 @@ static DistributeObjectOps Any_DropRole = { }; static DistributeObjectOps Role_Comment = { - .deparse = DeparseRoleCommentStmt, + .deparse = DeparseCommentStmt, .qualify = NULL, .preprocess = PreprocessAlterDistributedObjectStmt, .postprocess = NULL, @@ -545,7 +545,7 @@ static DistributeObjectOps Database_Set = { }; static DistributeObjectOps Database_Comment = { - .deparse = DeparseDatabaseCommentStmt, + .deparse = DeparseCommentStmt, .qualify = NULL, .preprocess = PreprocessAlterDistributedObjectStmt, .postprocess = NULL, @@ -994,7 +994,7 @@ static DistributeObjectOps TextSearchConfig_AlterOwner = { .markDistributed = false, }; static DistributeObjectOps TextSearchConfig_Comment = { - .deparse = DeparseTextSearchConfigurationCommentStmt, + .deparse = DeparseCommentStmt, .qualify = QualifyTextSearchConfigurationCommentStmt, .preprocess = PreprocessAlterDistributedObjectStmt, .postprocess = NULL, @@ -1063,7 +1063,7 @@ static DistributeObjectOps TextSearchDict_AlterOwner = { .markDistributed = false, }; static DistributeObjectOps TextSearchDict_Comment = { - .deparse = DeparseTextSearchDictionaryCommentStmt, + .deparse = DeparseCommentStmt, .qualify = QualifyTextSearchDictionaryCommentStmt, .preprocess = PreprocessAlterDistributedObjectStmt, .postprocess = NULL, diff --git a/src/backend/distributed/deparser/deparse_comment_stmts.c b/src/backend/distributed/deparser/deparse_comment_stmts.c new file mode 100644 index 000000000..25be9eac8 --- /dev/null +++ b/src/backend/distributed/deparser/deparse_comment_stmts.c @@ -0,0 +1,55 @@ +/*------------------------------------------------------------------------- + * + * deparse_coment_stmts.c + * + * All routines to deparse comment statements. + * + * Copyright (c), Citus Data, Inc. + * + *------------------------------------------------------------------------- + */ + +#include "postgres.h" + +#include "catalog/namespace.h" +#include "commands/defrem.h" +#include "lib/stringinfo.h" +#include "nodes/parsenodes.h" +#include "parser/parse_type.h" +#include "utils/builtins.h" + +#include "pg_version_compat.h" + +#include "distributed/citus_ruleutils.h" +#include "distributed/commands.h" +#include "distributed/deparser.h" +#include "distributed/listutils.h" +#include "distributed/log_utils.h" + + +const char * const ObjectTypeNames[] = +{ + [OBJECT_DATABASE] = "DATABASE", + [OBJECT_ROLE] = "ROLE", + [OBJECT_TSCONFIGURATION] = "TEXT SEARCH CONFIGURATION", + [OBJECT_TSDICTIONARY] = "TEXT SEARCH DICTIONARY", + /* etc. */ +}; + +char * +DeparseCommentStmt(Node *node) +{ + CommentStmt *stmt = castNode(CommentStmt, node); + StringInfoData str = { 0 }; + initStringInfo(&str); + + const char *objectName = quote_identifier(strVal(stmt->object)); + const char *objectType = ObjectTypeNames[stmt->objtype]; + + char *comment = stmt->comment != NULL ? quote_literal_cstr(stmt->comment) : "NULL"; + + + appendStringInfo(&str, "COMMENT ON %s %s IS %s;",objectType, objectName, comment); + + return str.data; +} diff --git a/src/backend/distributed/deparser/deparse_database_stmts.c b/src/backend/distributed/deparser/deparse_database_stmts.c index c88a322fd..30ac3f32c 100644 --- a/src/backend/distributed/deparser/deparse_database_stmts.c +++ b/src/backend/distributed/deparser/deparse_database_stmts.c @@ -353,20 +353,3 @@ DeparseDropDatabaseStmt(Node *node) return str.data; } - - -char * -DeparseDatabaseCommentStmt(Node *node) -{ - CommentStmt *stmt = castNode(CommentStmt, node); - StringInfoData str = { 0 }; - initStringInfo(&str); - - char const *databaseName = quote_identifier(strVal(stmt->object)); - - char *comment = stmt->comment != NULL ? quote_literal_cstr(stmt->comment) : "NULL"; - - appendStringInfo(&str, "COMMENT ON DATABASE %s IS %s;", databaseName, comment); - - return str.data; -} diff --git a/src/backend/distributed/deparser/deparse_role_stmts.c b/src/backend/distributed/deparser/deparse_role_stmts.c index e6cb91977..b86841345 100644 --- a/src/backend/distributed/deparser/deparse_role_stmts.c +++ b/src/backend/distributed/deparser/deparse_role_stmts.c @@ -533,19 +533,3 @@ AppendAlterRoleSetStmt(StringInfo buf, AlterRoleSetStmt *stmt) VariableSetStmt *setStmt = castNode(VariableSetStmt, stmt->setstmt); AppendVariableSet(buf, setStmt); } - - -char * -DeparseRoleCommentStmt(Node *node) -{ - CommentStmt *stmt = castNode(CommentStmt, node); - StringInfoData str = { 0 }; - initStringInfo(&str); - - char const *roleName = quote_identifier(strVal(stmt->object)); - char *comment = stmt->comment != NULL ? quote_literal_cstr(stmt->comment) : "NULL"; - - appendStringInfo(&str, "COMMENT ON ROLE %s IS %s;", roleName, comment); - - return str.data; -} diff --git a/src/include/distributed/deparser.h b/src/include/distributed/deparser.h index ba34d11b8..af60de08f 100644 --- a/src/include/distributed/deparser.h +++ b/src/include/distributed/deparser.h @@ -143,6 +143,9 @@ extern void DefElemOptionToStatement(StringInfo buf, DefElem *option, const DefElemOptionFormat *opt_formats, int opt_formats_len); +/* forward declarations for deparse_comment_stmts.c */ +extern char * DeparseCommentStmt(Node *node); + /* forward declarations for deparse_statistics_stmts.c */ extern char * DeparseCreateStatisticsStmt(Node *node);