mirror of https://github.com/citusdata/citus.git
Refactor deparse comment statements
parent
09a93f3cdb
commit
3e8658aff4
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue