Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#24754] YSQL: Cleanup PgStatement* casts
Summary: There are lot of boiler plate code in `pggate.cc` related to `PgStatement*` cast. ``` Status PgApiImpl::AlterTableAddColumn(PgStatement *handle, const char *name, int order, const YBCPgTypeEntity *attr_type, YBCPgExpr missing_value) { if (!PgStatement::IsValidStmt(handle, StmtOp::STMT_ALTER_TABLE)) { // Invalid handle. return STATUS(InvalidArgument, "Invalid statement handle"); } PgAlterTable *pg_stmt = down_cast<PgAlterTable*>(handle); return pg_stmt->AddColumn(name, attr_type, order, missing_value); } Status PgApiImpl::AlterTableRenameColumn(PgStatement *handle, const char *oldname, const char *newname) { if (!PgStatement::IsValidStmt(handle, StmtOp::STMT_ALTER_TABLE)) { // Invalid handle. return STATUS(InvalidArgument, "Invalid statement handle"); } PgAlterTable *pg_stmt = down_cast<PgAlterTable*>(handle); return pg_stmt->RenameColumn(oldname, newname); } ``` It is reasonable to introduce template helper function `GetStatementAs<...>` to make the code above look like ``` Status PgApiImpl::AlterTableAddColumn( PgStatement *handle, const char *name, int order, const YBCPgTypeEntity *attr_type, YBCPgExpr missing_value) { return VERIFY_RESULT_REF(GetStatementAs<PgAlterTable>(handle)).AddColumn( name, attr_type, order, missing_value); } Status PgApiImpl::AlterTableRenameColumn( PgStatement *handle, const char *oldname, const char *newname) { return VERIFY_RESULT_REF(GetStatementAs<PgAlterTable>(handle)).RenameColumn(oldname, newname); } ``` Test Plan: Jenkins Reviewers: pjain, sergei, kramanathan, jason, tnayak Reviewed By: tnayak Subscribers: ybase, yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D39460
- Loading branch information