Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YSQL] Cleanup PgStatement* casts #24754

Open
1 task done
d-uspenskiy opened this issue Nov 1, 2024 · 0 comments
Open
1 task done

[YSQL] Cleanup PgStatement* casts #24754

d-uspenskiy opened this issue Nov 1, 2024 · 0 comments
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue status/awaiting-triage Issue awaiting triage

Comments

@d-uspenskiy
Copy link
Contributor

d-uspenskiy commented Nov 1, 2024

Jira Link: DB-13845

Description

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 seem 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);
}

Issue Type

kind/enhancement

Warning: Please confirm that this issue does not contain any sensitive information

  • I confirm this issue does not contain any sensitive information.
@d-uspenskiy d-uspenskiy added kind/enhancement This is an enhancement of an existing feature area/ysql Yugabyte SQL (YSQL) status/awaiting-triage Issue awaiting triage labels Nov 1, 2024
@d-uspenskiy d-uspenskiy self-assigned this Nov 1, 2024
@yugabyte-ci yugabyte-ci added the priority/medium Medium priority issue label Nov 1, 2024
@d-uspenskiy d-uspenskiy changed the title [YSQL] Cleanup PgStatement casts [YSQL] Cleanup PgStatement* casts Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue status/awaiting-triage Issue awaiting triage
Projects
None yet
Development

No branches or pull requests

2 participants