mirror of https://github.com/citusdata/citus.git
Refactors object address
parent
3e8658aff4
commit
dbc20c4f79
|
@ -123,3 +123,24 @@ GetCommentForObject(Oid oid)
|
||||||
|
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* CommentObjectAddress resolves the ObjectAddress for the object
|
||||||
|
* on which the comment is placed. Optionally errors if the object does not
|
||||||
|
* exist based on the missing_ok flag passed in by the caller.
|
||||||
|
*/
|
||||||
|
List *
|
||||||
|
CommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess)
|
||||||
|
{
|
||||||
|
CommentStmt *stmt = castNode(CommentStmt, node);
|
||||||
|
Relation relation;
|
||||||
|
|
||||||
|
ObjectAddress objectAddress = get_object_address(stmt->objtype, stmt->object,
|
||||||
|
&relation, AccessExclusiveLock,
|
||||||
|
missing_ok);
|
||||||
|
|
||||||
|
ObjectAddress *objectAddressCopy = palloc0(sizeof(ObjectAddress));
|
||||||
|
*objectAddressCopy = objectAddress;
|
||||||
|
return list_make1(objectAddressCopy);
|
||||||
|
}
|
||||||
|
|
|
@ -793,25 +793,3 @@ CreateDatabaseDDLCommand(Oid dbId)
|
||||||
|
|
||||||
return outerDbStmt->data;
|
return outerDbStmt->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* DatabaseCommentObjectAddress resolves the ObjectAddress for the DATABASE
|
|
||||||
* on which the comment is placed. Optionally errors if the database does not
|
|
||||||
* exist based on the missing_ok flag passed in by the caller.
|
|
||||||
*/
|
|
||||||
List *
|
|
||||||
DatabaseCommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess)
|
|
||||||
{
|
|
||||||
CommentStmt *stmt = castNode(CommentStmt, node);
|
|
||||||
Relation relation;
|
|
||||||
Assert(stmt->objtype == OBJECT_DATABASE);
|
|
||||||
|
|
||||||
ObjectAddress objectAddress = get_object_address(stmt->objtype, stmt->object,
|
|
||||||
&relation, AccessExclusiveLock,
|
|
||||||
missing_ok);
|
|
||||||
|
|
||||||
ObjectAddress *objectAddressCopy = palloc0(sizeof(ObjectAddress));
|
|
||||||
*objectAddressCopy = objectAddress;
|
|
||||||
return list_make1(objectAddressCopy);
|
|
||||||
}
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "pg_version_constants.h"
|
#include "pg_version_constants.h"
|
||||||
|
|
||||||
#include "distributed/commands.h"
|
#include "distributed/commands.h"
|
||||||
|
#include "distributed/comment.h"
|
||||||
#include "distributed/commands/utility_hook.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"
|
||||||
|
@ -312,7 +313,7 @@ static DistributeObjectOps Role_Comment = {
|
||||||
.postprocess = NULL,
|
.postprocess = NULL,
|
||||||
.objectType = OBJECT_DATABASE,
|
.objectType = OBJECT_DATABASE,
|
||||||
.operationType = DIST_OPS_ALTER,
|
.operationType = DIST_OPS_ALTER,
|
||||||
.address = RoleCommentObjectAddress,
|
.address = CommentObjectAddress,
|
||||||
.markDistributed = false,
|
.markDistributed = false,
|
||||||
};
|
};
|
||||||
static DistributeObjectOps Any_CreateForeignServer = {
|
static DistributeObjectOps Any_CreateForeignServer = {
|
||||||
|
@ -551,7 +552,7 @@ static DistributeObjectOps Database_Comment = {
|
||||||
.postprocess = NULL,
|
.postprocess = NULL,
|
||||||
.objectType = OBJECT_DATABASE,
|
.objectType = OBJECT_DATABASE,
|
||||||
.operationType = DIST_OPS_ALTER,
|
.operationType = DIST_OPS_ALTER,
|
||||||
.address = DatabaseCommentObjectAddress,
|
.address = CommentObjectAddress,
|
||||||
.markDistributed = false,
|
.markDistributed = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1000,7 +1001,7 @@ static DistributeObjectOps TextSearchConfig_Comment = {
|
||||||
.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 = {
|
||||||
|
@ -1069,7 +1070,7 @@ static DistributeObjectOps TextSearchDict_Comment = {
|
||||||
.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 = {
|
||||||
|
|
|
@ -1424,25 +1424,3 @@ RenameRoleStmtObjectAddress(Node *node, bool missing_ok, bool isPostprocess)
|
||||||
|
|
||||||
return list_make1(address);
|
return list_make1(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* RoleCommentObjectAddress resolves the ObjectAddress for the ROLE
|
|
||||||
* on which the comment is placed. Optionally errors if the role does not
|
|
||||||
* exist based on the missing_ok flag passed in by the caller.
|
|
||||||
*/
|
|
||||||
List *
|
|
||||||
RoleCommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess)
|
|
||||||
{
|
|
||||||
CommentStmt *stmt = castNode(CommentStmt, node);
|
|
||||||
Relation relation;
|
|
||||||
Assert(stmt->objtype == OBJECT_ROLE);
|
|
||||||
|
|
||||||
ObjectAddress objectAddress = get_object_address(stmt->objtype, stmt->object,
|
|
||||||
&relation, AccessExclusiveLock,
|
|
||||||
missing_ok);
|
|
||||||
|
|
||||||
ObjectAddress *objectAddressCopy = palloc0(sizeof(ObjectAddress));
|
|
||||||
*objectAddressCopy = objectAddress;
|
|
||||||
return list_make1(objectAddressCopy);
|
|
||||||
}
|
|
||||||
|
|
|
@ -27,13 +27,14 @@
|
||||||
#include "distributed/log_utils.h"
|
#include "distributed/log_utils.h"
|
||||||
|
|
||||||
|
|
||||||
const char * const ObjectTypeNames[] =
|
const char *const ObjectTypeNames[] =
|
||||||
{
|
{
|
||||||
[OBJECT_DATABASE] = "DATABASE",
|
[OBJECT_DATABASE] = "DATABASE",
|
||||||
[OBJECT_ROLE] = "ROLE",
|
[OBJECT_ROLE] = "ROLE",
|
||||||
[OBJECT_TSCONFIGURATION] = "TEXT SEARCH CONFIGURATION",
|
[OBJECT_TSCONFIGURATION] = "TEXT SEARCH CONFIGURATION",
|
||||||
[OBJECT_TSDICTIONARY] = "TEXT SEARCH DICTIONARY",
|
[OBJECT_TSDICTIONARY] = "TEXT SEARCH DICTIONARY",
|
||||||
/* etc. */
|
|
||||||
|
/* etc. */
|
||||||
};
|
};
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
@ -44,12 +45,12 @@ DeparseCommentStmt(Node *node)
|
||||||
initStringInfo(&str);
|
initStringInfo(&str);
|
||||||
|
|
||||||
const char *objectName = quote_identifier(strVal(stmt->object));
|
const char *objectName = quote_identifier(strVal(stmt->object));
|
||||||
const char *objectType = ObjectTypeNames[stmt->objtype];
|
const char *objectType = ObjectTypeNames[stmt->objtype];
|
||||||
|
|
||||||
char *comment = stmt->comment != NULL ? quote_literal_cstr(stmt->comment) : "NULL";
|
char *comment = stmt->comment != NULL ? quote_literal_cstr(stmt->comment) : "NULL";
|
||||||
|
|
||||||
|
|
||||||
appendStringInfo(&str, "COMMENT ON %s %s IS %s;",objectType, objectName, comment);
|
appendStringInfo(&str, "COMMENT ON %s %s IS %s;", objectType, objectName, comment);
|
||||||
|
|
||||||
return str.data;
|
return str.data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,8 +249,6 @@ extern List * GenerateGrantDatabaseCommandList(void);
|
||||||
extern List * PostprocessAlterDatabaseRenameStmt(Node *node, const char *queryString);
|
extern List * PostprocessAlterDatabaseRenameStmt(Node *node, const char *queryString);
|
||||||
extern void EnsureSupportedCreateDatabaseCommand(CreatedbStmt *stmt);
|
extern void EnsureSupportedCreateDatabaseCommand(CreatedbStmt *stmt);
|
||||||
extern char * CreateDatabaseDDLCommand(Oid dbId);
|
extern char * CreateDatabaseDDLCommand(Oid dbId);
|
||||||
extern List * DatabaseCommentObjectAddress(Node *node, bool missing_ok,
|
|
||||||
bool isPostprocess);
|
|
||||||
|
|
||||||
|
|
||||||
/* domain.c - forward declarations */
|
/* domain.c - forward declarations */
|
||||||
|
@ -523,7 +521,6 @@ extern List * RenameRoleStmtObjectAddress(Node *stmt, bool missing_ok, bool
|
||||||
|
|
||||||
extern void UnmarkRolesDistributed(List *roles);
|
extern void UnmarkRolesDistributed(List *roles);
|
||||||
extern List * FilterDistributedRoles(List *roles);
|
extern List * FilterDistributedRoles(List *roles);
|
||||||
List * RoleCommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess);
|
|
||||||
|
|
||||||
/* schema.c - forward declarations */
|
/* schema.c - forward declarations */
|
||||||
extern List * PostprocessCreateSchemaStmt(Node *node, const char *queryString);
|
extern List * PostprocessCreateSchemaStmt(Node *node, const char *queryString);
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef COMMENT_H
|
||||||
|
#define COMMENT_H
|
||||||
|
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
|
||||||
#include "nodes/parsenodes.h"
|
#include "nodes/parsenodes.h"
|
||||||
|
@ -21,3 +24,6 @@ typedef struct CommentStmtType
|
||||||
|
|
||||||
extern List * GetCommentPropagationCommands(Oid oid, char *objectName, ObjectType
|
extern List * GetCommentPropagationCommands(Oid oid, char *objectName, ObjectType
|
||||||
objectType);
|
objectType);
|
||||||
|
extern List * CommentObjectAddress(Node *node, bool missing_ok, bool isPostprocess);
|
||||||
|
|
||||||
|
# endif /* COMMENT_H */
|
||||||
|
|
Loading…
Reference in New Issue