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

feat: preliminary adaptation of gaussdb #12061

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Update gauss.go
replace Postgres comments to GaussDB
  • Loading branch information
shanzhuer committed May 21, 2024
commit 47b6baeefe1b352b93301c705d5a6d6553515c64
12 changes: 4 additions & 8 deletions backend/plugin/db/gauss/gauss.go
shanzhuer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
"fmt"
"log/slog"
"net"
"regexp"

Check failure on line 9 in backend/plugin/db/gauss/gauss.go

View workflow job for this annotation

GitHub Actions / go-tests

File is not `goimports`-ed with -local github.com/bytebase/bytebase (goimports)
"strings"
"time"
"strconv"

//opengauss driver

Check failure on line 14 in backend/plugin/db/gauss/gauss.go

View workflow job for this annotation

GitHub Actions / go-tests

commentFormatting: put a space between `//` and comment text (gocritic)
_ "gitee.com/opengauss/openGauss-connector-go-pq"
//"github.com/jackc/pgx/v5"

Check failure on line 16 in backend/plugin/db/gauss/gauss.go

View workflow job for this annotation

GitHub Actions / go-tests

commentFormatting: put a space between `//` and comment text (gocritic)
//"github.com/jackc/pgx/v5/stdlib"

Check warning on line 17 in backend/plugin/db/gauss/gauss.go

View workflow job for this annotation

GitHub Actions / go-tests

comment-spacings: no space between comment delimiter and comment text (revive)

"github.com/pkg/errors"
//"go.uber.org/multierr"

Check failure on line 20 in backend/plugin/db/gauss/gauss.go

View workflow job for this annotation

GitHub Actions / go-tests

commentFormatting: put a space between `//` and comment text (gocritic)
"golang.org/x/crypto/ssh"
"google.golang.org/protobuf/types/known/durationpb"

Expand Down Expand Up @@ -50,12 +50,12 @@
db.Register(storepb.Engine_GAUSSDB, newDriver)
}

// Driver is the Postgres driver.
// Driver is the GaussDB driver.
type Driver struct {
config db.ConnectionConfig

Check failure on line 55 in backend/plugin/db/gauss/gauss.go

View workflow job for this annotation

GitHub Actions / go-tests

field `config` is unused (unused)

db *sql.DB
sshClient *ssh.Client

Check failure on line 58 in backend/plugin/db/gauss/gauss.go

View workflow job for this annotation

GitHub Actions / go-tests

field `sshClient` is unused (unused)
// connectionString is the connection string registered by pgx.
// Unregister connectionString if we don't need it.
connectionString string
Expand All @@ -66,9 +66,9 @@
return &Driver{}
}

// Open opens a Postgres driver.
// Open opens a GaussDB driver.
func (driver *Driver) Open(_ context.Context, _ storepb.Engine, config db.ConnectionConfig) (db.Driver, error) {

Check warning on line 70 in backend/plugin/db/gauss/gauss.go

View workflow job for this annotation

GitHub Actions / go-tests

empty-lines: extra empty line at the end of a block (revive)
// Require username for Postgres, as the guessDSN 1st guess is to use the username as the connecting database
// Require username for GaussDB, as the guessDSN 1st guess is to use the username as the connecting database
// if database name is not explicitly specified.
if config.Username == "" {
return nil, errors.Errorf("user must be set")
Expand Down Expand Up @@ -119,7 +119,7 @@
return driver.db
}

// Execute will execute the statement. For CREATE DATABASE statement, some types of databases such as Postgres
// Execute will execute the statement. For CREATE DATABASE statement, some types of databases such as GaussDB
// will not use transactions to execute the statement but will still use transactions to execute the rest of statements.
func (driver *Driver) Execute(ctx context.Context, statement string, opts db.ExecuteOptions) (int64, error) {
if opts.CreateDatabase {
Expand Down Expand Up @@ -151,10 +151,6 @@
}

if isSuperuserStatement(singleSQL.Text) {
// CREATE EVENT TRIGGER statement only supports EXECUTE PROCEDURE in version 10 and before, while newer version supports both EXECUTE { FUNCTION | PROCEDURE }.
// Since we use pg_dump version 14, the dump uses a new style even for an old version of PostgreSQL.
// We should convert EXECUTE FUNCTION to EXECUTE PROCEDURE to make the restoration work on old versions.
// https://www.postgresql.org/docs/14/sql-createeventtrigger.html
if strings.Contains(strings.ToUpper(singleSQL.Text), "CREATE EVENT TRIGGER") {
singleSQL.Text = strings.ReplaceAll(singleSQL.Text, "EXECUTE FUNCTION", "EXECUTE PROCEDURE")
}
Expand Down Expand Up @@ -188,7 +184,7 @@
}
defer tx.Rollback()
// Set the current transaction role to the database owner so that the owner of created objects will be the same as the database owner.
//if _, err := tx.ExecContext(ctx, fmt.Sprintf("SET SESSION AUTHORIZATION '%s';", owner)); err != nil {

Check failure on line 187 in backend/plugin/db/gauss/gauss.go

View workflow job for this annotation

GitHub Actions / go-tests

commentFormatting: put a space between `//` and comment text (gocritic)
if _, err := tx.ExecContext(ctx, "SET SESSION AUTHORIZATION DEFAULT;"); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems no need to run this statement.

return 0, err
}
Expand Down Expand Up @@ -349,7 +345,7 @@
}

// QueryConn queries a SQL statement in a given connection.
func (driver *Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement string, queryContext *db.QueryContext) ([]*v1pb.QueryResult, error) {

Check warning on line 348 in backend/plugin/db/gauss/gauss.go

View workflow job for this annotation

GitHub Actions / go-tests

empty-lines: extra empty line at the start of a block (revive)

singleSQLs, err := pgparser.SplitSQL(statement)
if err != nil {
Expand Down
Loading