Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: redshift refactor (#12806)

Danny Xu6214a544f0f3
diff --git a/backend/plugin/advisor/utils_for_tests.go b/backend/plugin/advisor/utils_for_tests.go
index b0b04efdae..18ba8afa80 100644
--- a/backend/plugin/advisor/utils_for_tests.go
+++ b/backend/plugin/advisor/utils_for_tests.go
@@ -275,11 +275,6 @@ func (*MockDriver) Ping(_ context.Context) error {
return nil
}
-// GetType implements the Driver interface.
-func (*MockDriver) GetType() storepb.Engine {
- return storepb.Engine_ENGINE_UNSPECIFIED
-}
-
// GetDB gets the database.
func (*MockDriver) GetDB() *sql.DB {
return nil
diff --git a/backend/plugin/db/bigquery/bigquery.go b/backend/plugin/db/bigquery/bigquery.go
index 21499d4d62..133289dc56 100644
--- a/backend/plugin/db/bigquery/bigquery.go
+++ b/backend/plugin/db/bigquery/bigquery.go
@@ -81,11 +81,6 @@ func (d *Driver) Ping(ctx context.Context) error {
return nil
}
-// GetType returns the database type.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_BIGQUERY
-}
-
// GetDB gets the database.
func (*Driver) GetDB() *sql.DB {
return nil
diff --git a/backend/plugin/db/clickhouse/clickhouse.go b/backend/plugin/db/clickhouse/clickhouse.go
index 98a84a3e13..db4a9f8d6e 100644
--- a/backend/plugin/db/clickhouse/clickhouse.go
+++ b/backend/plugin/db/clickhouse/clickhouse.go
@@ -4,23 +4,13 @@ package clickhouse
import (
"context"
"database/sql"
- "encoding/json"
"fmt"
"log/slog"
- "math/big"
- "reflect"
"strings"
"time"
clickhouse "github.com/ClickHouse/clickhouse-go/v2"
- "github.com/google/uuid"
- "github.com/paulmach/orb"
- "github.com/paulmach/orb/encoding/wkt"
"github.com/pkg/errors"
- "github.com/shopspring/decimal"
- "google.golang.org/protobuf/proto"
- "google.golang.org/protobuf/types/known/durationpb"
- "google.golang.org/protobuf/types/known/structpb"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -30,7 +20,6 @@ import (
"github.com/bytebase/bytebase/backend/plugin/db/util"
"github.com/bytebase/bytebase/backend/plugin/parser/base"
"github.com/bytebase/bytebase/backend/plugin/parser/standard"
- v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
)
var (
@@ -116,11 +105,6 @@ func (driver *Driver) Ping(ctx context.Context) error {
return driver.db.PingContext(ctx)
}
-// GetType returns the database type.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_CLICKHOUSE
-}
-
// GetDB gets the database.
func (driver *Driver) GetDB() *sql.DB {
return driver.db
@@ -177,344 +161,3 @@ func (driver *Driver) Execute(ctx context.Context, statement string, _ db.Execut
return totalRowsAffected, err
}
-
-// RunStatement runs a SQL statement.
-func (*Driver) RunStatement(ctx context.Context, conn *sql.Conn, statement string) ([]*v1pb.QueryResult, error) {
- singleSQLs, err := standard.SplitSQL(statement)
- if err != nil {
- return nil, err
- }
- singleSQLs = base.FilterEmptySQL(singleSQLs)
- if len(singleSQLs) == 0 {
- return nil, nil
- }
-
- var results []*v1pb.QueryResult
- for _, singleSQL := range singleSQLs {
- startTime := time.Now()
- result, err := func() (*v1pb.QueryResult, error) {
- rows, err := conn.QueryContext(ctx, singleSQL.Text)
- if err != nil {
- // ClickHouse will return "driver: bad connection" if we use non-SELECT statement for Query(). We need to ignore the error.
- // nolint
- return nil, nil
- }
- defer rows.Close()
-
- result, err := convertRowsToQueryResult(rows)
- if err != nil {
- result = &v1pb.QueryResult{
- Error: err.Error(),
- }
- }
- result.Latency = durationpb.New(time.Since(startTime))
- result.Statement = singleSQL.Text
- return result, nil
- }()
- if err != nil {
- return nil, err
- }
-
- results = append(results, result)
- }
-
- return results, nil
-}
-
-// 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) {
- // TODO(rebelice): implement multi-statement query
- var results []*v1pb.QueryResult
-
- result, err := driver.querySingleSQL(ctx, conn, statement, queryContext)
- if err != nil {
- results = append(results, &v1pb.QueryResult{
- Error: err.Error(),
- })
- } else {
- results = append(results, result)
- }
-
- return results, nil
-}
-
-func getStatementWithResultLimit(statement string, limit int) string {
- statement = strings.TrimRight(statement, " \n\t;")
- return fmt.Sprintf("WITH result AS (%s) SELECT * FROM result LIMIT %d;", statement, limit)
-}
-
-func (*Driver) querySingleSQL(ctx context.Context, conn *sql.Conn, statement string, queryContext *db.QueryContext) (*v1pb.QueryResult, error) {
- startTime := time.Now()
-
- if queryContext != nil && queryContext.Explain {
- statement = fmt.Sprintf("EXPLAIN %s", statement)
- } else if queryContext != nil && queryContext.Limit > 0 {
- statement = getStatementWithResultLimit(statement, queryContext.Limit)
- }
-
- // Clickhouse doesn't support READ ONLY transactions (Error: sql: driver does not support read-only transactions).
- tx, err := conn.BeginTx(ctx, &sql.TxOptions{})
- if err != nil {
- return nil, err
- }
- defer tx.Rollback()
-
- rows, err := tx.QueryContext(ctx, statement)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- result, err := convertRowsToQueryResult(rows)
- if err != nil {
- return nil, err
- }
- result.Latency = durationpb.New(time.Since(startTime))
- result.Statement = statement
-
- return result, err
-}
-
-func convertRowsToQueryResult(rows *sql.Rows) (*v1pb.QueryResult, error) {
- columnNames, err := rows.Columns()
- if err != nil {
- return nil, err
- }
-
- columnTypes, err := rows.ColumnTypes()
- if err != nil {
- return nil, err
- }
-
- var columnTypeNames []string
- for _, v := range columnTypes {
- // DatabaseTypeName returns the database system name of the column type.
- // refer: https://pkg.go.dev/database/sql#ColumnType.DatabaseTypeName
- columnTypeNames = append(columnTypeNames, strings.ToUpper(v.DatabaseTypeName()))
- }
-
- result := &v1pb.QueryResult{
- ColumnNames: columnNames,
- ColumnTypeNames: columnTypeNames,
- }
- if err := readRowsForClickhouse(result, rows, columnTypes, columnTypeNames); err != nil {
- return nil, err
- }
-
- if err := rows.Err(); err != nil {
- return nil, err
- }
-
- return result, nil
-}
-
-func readRowsForClickhouse(result *v1pb.QueryResult, rows *sql.Rows, columnTypes []*sql.ColumnType, columnTypeNames []string) error {
- for rows.Next() {
- cols := make([]any, len(columnTypes))
- for i, name := range columnTypeNames {
- // The ClickHouse driver uses *Type rather than sql.NullType to scan nullable fields
- // as described in https://github.com/ClickHouse/clickhouse-go/issues/754
- // TODO: remove this workaround once fixed.
- if strings.HasPrefix(name, "TUPLE") || strings.HasPrefix(name, "ARRAY") || strings.HasPrefix(name, "MAP") {
- // For TUPLE, ARRAY, MAP type in ClickHouse, we pass any and the driver will do the rest.
- var it any
- cols[i] = &it
- } else {
- // We use ScanType to get the correct *Type and then do type assertions
- // following https://github.com/ClickHouse/clickhouse-go/blob/main/TYPES.md
- cols[i] = reflect.New(columnTypes[i].ScanType()).Interface()
- }
- }
-
- if err := rows.Scan(cols...); err != nil {
- return err
- }
-
- var rowData v1pb.QueryRow
- for i := range cols {
- // handle TUPLE ARRAY MAP
- if v, ok := cols[i].(*any); ok && v != nil {
- value, err := json.Marshal(v)
- if err != nil {
- return errors.Wrapf(err, "failed to marshal value")
- }
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: string(value)}})
- continue
- }
-
- // not nullable
- if v, ok := cols[i].(*int); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int64Value{Int64Value: int64(*v)}})
- continue
- }
- if v, ok := cols[i].(*int8); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int32Value{Int32Value: int32(*v)}})
- continue
- }
- if v, ok := cols[i].(*int16); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int32Value{Int32Value: int32(*v)}})
- continue
- }
- if v, ok := cols[i].(*int32); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int32Value{Int32Value: *v}})
- continue
- }
- if v, ok := cols[i].(*int64); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int64Value{Int64Value: *v}})
- continue
- }
- if v, ok := cols[i].(*uint); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint64Value{Uint64Value: uint64(*v)}})
- continue
- }
- if v, ok := cols[i].(*uint8); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint32Value{Uint32Value: uint32(*v)}})
- continue
- }
- if v, ok := cols[i].(*uint16); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint32Value{Uint32Value: uint32(*v)}})
- continue
- }
- if v, ok := cols[i].(*uint32); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint32Value{Uint32Value: *v}})
- continue
- }
- if v, ok := cols[i].(*uint64); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint64Value{Uint64Value: *v}})
- continue
- }
- if v, ok := cols[i].(*float32); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_FloatValue{FloatValue: *v}})
- continue
- }
- if v, ok := cols[i].(*float64); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_DoubleValue{DoubleValue: *v}})
- continue
- }
- if v, ok := cols[i].(*string); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: *v}})
- continue
- }
- if v, ok := cols[i].(*bool); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_BoolValue{BoolValue: *v}})
- continue
- }
- if v, ok := cols[i].(*time.Time); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: v.Format(time.RFC3339Nano)}})
- continue
- }
- if v, ok := cols[i].(*big.Int); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: v.String()}})
- continue
- }
- if v, ok := cols[i].(*decimal.Decimal); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: v.String()}})
- continue
- }
- if v, ok := cols[i].(*uuid.UUID); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: v.String()}})
- continue
- }
- if v, ok := cols[i].(*orb.Point); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: wkt.MarshalString(*v)}})
- continue
- }
- if v, ok := cols[i].(*orb.Polygon); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: wkt.MarshalString(*v)}})
- continue
- }
- if v, ok := cols[i].(*orb.Ring); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: wkt.MarshalString(*v)}})
- continue
- }
- if v, ok := cols[i].(*orb.MultiPolygon); ok && v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: wkt.MarshalString(*v)}})
- continue
- }
-
- // nullable
- if v, ok := cols[i].(**int); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int64Value{Int64Value: int64(**v)}})
- continue
- }
- if v, ok := cols[i].(**int8); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int32Value{Int32Value: int32(**v)}})
- continue
- }
- if v, ok := cols[i].(**int16); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int32Value{Int32Value: int32(**v)}})
- continue
- }
- if v, ok := cols[i].(**int32); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int32Value{Int32Value: **v}})
- continue
- }
- if v, ok := cols[i].(**int64); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int64Value{Int64Value: **v}})
- continue
- }
- if v, ok := cols[i].(**uint); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint64Value{Uint64Value: uint64(**v)}})
- continue
- }
- if v, ok := cols[i].(**uint8); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint32Value{Uint32Value: uint32(**v)}})
- continue
- }
- if v, ok := cols[i].(**uint16); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint32Value{Uint32Value: uint32(**v)}})
- continue
- }
- if v, ok := cols[i].(**uint32); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint32Value{Uint32Value: **v}})
- continue
- }
- if v, ok := cols[i].(**uint64); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint64Value{Uint64Value: **v}})
- continue
- }
- if v, ok := cols[i].(**float32); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_FloatValue{FloatValue: **v}})
- continue
- }
- if v, ok := cols[i].(**float64); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_DoubleValue{DoubleValue: **v}})
- continue
- }
- if v, ok := cols[i].(**string); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: **v}})
- continue
- }
- if v, ok := cols[i].(**bool); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_BoolValue{BoolValue: **v}})
- continue
- }
- if v, ok := cols[i].(**time.Time); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: (*v).Format(time.RFC3339Nano)}})
- continue
- }
- if v, ok := cols[i].(**big.Int); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: (*v).String()}})
- continue
- }
- if v, ok := cols[i].(**decimal.Decimal); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: (*v).String()}})
- continue
- }
- if v, ok := cols[i].(**uuid.UUID); ok && *v != nil {
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: (*v).String()}})
- continue
- }
- rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_NullValue{NullValue: structpb.NullValue_NULL_VALUE}})
- }
-
- result.Rows = append(result.Rows, &rowData)
- n := len(result.Rows)
- if (n&(n-1) == 0) && proto.Size(result) > common.MaximumSQLResultSize {
- result.Error = common.MaximumSQLResultSizeExceeded
- return nil
- }
- }
-
- return nil
-}
diff --git a/backend/plugin/db/clickhouse/query.go b/backend/plugin/db/clickhouse/query.go
new file mode 100644
index 0000000000..ea1e7b47a7
--- /dev/null
+++ b/backend/plugin/db/clickhouse/query.go
@@ -0,0 +1,368 @@
+package clickhouse
+
+import (
+ "context"
+ "database/sql"
+ "encoding/json"
+ "fmt"
+ "math/big"
+ "reflect"
+ "strings"
+ "time"
+
+ "github.com/paulmach/orb"
+ "github.com/paulmach/orb/encoding/wkt"
+ "github.com/pkg/errors"
+ "github.com/shopspring/decimal"
+ "github.com/xtgo/uuid"
+ "google.golang.org/protobuf/proto"
+ "google.golang.org/protobuf/types/known/durationpb"
+ "google.golang.org/protobuf/types/known/structpb"
+
+ "github.com/bytebase/bytebase/backend/common"
+ "github.com/bytebase/bytebase/backend/plugin/db"
+ "github.com/bytebase/bytebase/backend/plugin/parser/base"
+ "github.com/bytebase/bytebase/backend/plugin/parser/standard"
+ v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
+)
+
+// RunStatement runs a SQL statement.
+func (*Driver) RunStatement(ctx context.Context, conn *sql.Conn, statement string) ([]*v1pb.QueryResult, error) {
+ singleSQLs, err := standard.SplitSQL(statement)
+ if err != nil {
+ return nil, err
+ }
+ singleSQLs = base.FilterEmptySQL(singleSQLs)
+ if len(singleSQLs) == 0 {
+ return nil, nil
+ }
+
+ var results []*v1pb.QueryResult
+ for _, singleSQL := range singleSQLs {
+ startTime := time.Now()
+ result, err := func() (*v1pb.QueryResult, error) {
+ rows, err := conn.QueryContext(ctx, singleSQL.Text)
+ if err != nil {
+ // ClickHouse will return "driver: bad connection" if we use non-SELECT statement for Query(). We need to ignore the error.
+ // nolint
+ return nil, nil
+ }
+ defer rows.Close()
+
+ result, err := convertRowsToQueryResult(rows)
+ if err != nil {
+ result = &v1pb.QueryResult{
+ Error: err.Error(),
+ }
+ }
+ result.Latency = durationpb.New(time.Since(startTime))
+ result.Statement = singleSQL.Text
+ return result, nil
+ }()
+ if err != nil {
+ return nil, err
+ }
+
+ results = append(results, result)
+ }
+
+ return results, nil
+}
+
+// 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) {
+ // TODO(rebelice): implement multi-statement query
+ var results []*v1pb.QueryResult
+
+ result, err := driver.querySingleSQL(ctx, conn, statement, queryContext)
+ if err != nil {
+ results = append(results, &v1pb.QueryResult{
+ Error: err.Error(),
+ })
+ } else {
+ results = append(results, result)
+ }
+
+ return results, nil
+}
+
+func getStatementWithResultLimit(statement string, limit int) string {
+ statement = strings.TrimRight(statement, " \n\t;")
+ return fmt.Sprintf("WITH result AS (%s) SELECT * FROM result LIMIT %d;", statement, limit)
+}
+
+func (*Driver) querySingleSQL(ctx context.Context, conn *sql.Conn, statement string, queryContext *db.QueryContext) (*v1pb.QueryResult, error) {
+ startTime := time.Now()
+
+ if queryContext != nil && queryContext.Explain {
+ statement = fmt.Sprintf("EXPLAIN %s", statement)
+ } else if queryContext != nil && queryContext.Limit > 0 {
+ statement = getStatementWithResultLimit(statement, queryContext.Limit)
+ }
+
+ // Clickhouse doesn't support READ ONLY transactions (Error: sql: driver does not support read-only transactions).
+ tx, err := conn.BeginTx(ctx, &sql.TxOptions{})
+ if err != nil {
+ return nil, err
+ }
+ defer tx.Rollback()
+
+ rows, err := tx.QueryContext(ctx, statement)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+
+ result, err := convertRowsToQueryResult(rows)
+ if err != nil {
+ return nil, err
+ }
+ result.Latency = durationpb.New(time.Since(startTime))
+ result.Statement = statement
+
+ return result, err
+}
+
+func convertRowsToQueryResult(rows *sql.Rows) (*v1pb.QueryResult, error) {
+ columnNames, err := rows.Columns()
+ if err != nil {
+ return nil, err
+ }
+
+ columnTypes, err := rows.ColumnTypes()
+ if err != nil {
+ return nil, err
+ }
+
+ var columnTypeNames []string
+ for _, v := range columnTypes {
+ // DatabaseTypeName returns the database system name of the column type.
+ // refer: https://pkg.go.dev/database/sql#ColumnType.DatabaseTypeName
+ columnTypeNames = append(columnTypeNames, strings.ToUpper(v.DatabaseTypeName()))
+ }
+
+ result := &v1pb.QueryResult{
+ ColumnNames: columnNames,
+ ColumnTypeNames: columnTypeNames,
+ }
+ if err := readRows(result, rows, columnTypes, columnTypeNames); err != nil {
+ return nil, err
+ }
+
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+
+ return result, nil
+}
+
+func readRows(result *v1pb.QueryResult, rows *sql.Rows, columnTypes []*sql.ColumnType, columnTypeNames []string) error {
+ for rows.Next() {
+ cols := make([]any, len(columnTypes))
+ for i, name := range columnTypeNames {
+ // The ClickHouse driver uses *Type rather than sql.NullType to scan nullable fields
+ // as described in https://github.com/ClickHouse/clickhouse-go/issues/754
+ // TODO: remove this workaround once fixed.
+ if strings.HasPrefix(name, "TUPLE") || strings.HasPrefix(name, "ARRAY") || strings.HasPrefix(name, "MAP") {
+ // For TUPLE, ARRAY, MAP type in ClickHouse, we pass any and the driver will do the rest.
+ var it any
+ cols[i] = &it
+ } else {
+ // We use ScanType to get the correct *Type and then do type assertions
+ // following https://github.com/ClickHouse/clickhouse-go/blob/main/TYPES.md
+ cols[i] = reflect.New(columnTypes[i].ScanType()).Interface()
+ }
+ }
+
+ if err := rows.Scan(cols...); err != nil {
+ return err
+ }
+
+ var rowData v1pb.QueryRow
+ for i := range cols {
+ // handle TUPLE ARRAY MAP
+ if v, ok := cols[i].(*any); ok && v != nil {
+ value, err := json.Marshal(v)
+ if err != nil {
+ return errors.Wrapf(err, "failed to marshal value")
+ }
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: string(value)}})
+ continue
+ }
+
+ // not nullable
+ if v, ok := cols[i].(*int); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int64Value{Int64Value: int64(*v)}})
+ continue
+ }
+ if v, ok := cols[i].(*int8); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int32Value{Int32Value: int32(*v)}})
+ continue
+ }
+ if v, ok := cols[i].(*int16); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int32Value{Int32Value: int32(*v)}})
+ continue
+ }
+ if v, ok := cols[i].(*int32); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int32Value{Int32Value: *v}})
+ continue
+ }
+ if v, ok := cols[i].(*int64); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int64Value{Int64Value: *v}})
+ continue
+ }
+ if v, ok := cols[i].(*uint); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint64Value{Uint64Value: uint64(*v)}})
+ continue
+ }
+ if v, ok := cols[i].(*uint8); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint32Value{Uint32Value: uint32(*v)}})
+ continue
+ }
+ if v, ok := cols[i].(*uint16); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint32Value{Uint32Value: uint32(*v)}})
+ continue
+ }
+ if v, ok := cols[i].(*uint32); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint32Value{Uint32Value: *v}})
+ continue
+ }
+ if v, ok := cols[i].(*uint64); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint64Value{Uint64Value: *v}})
+ continue
+ }
+ if v, ok := cols[i].(*float32); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_FloatValue{FloatValue: *v}})
+ continue
+ }
+ if v, ok := cols[i].(*float64); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_DoubleValue{DoubleValue: *v}})
+ continue
+ }
+ if v, ok := cols[i].(*string); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: *v}})
+ continue
+ }
+ if v, ok := cols[i].(*bool); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_BoolValue{BoolValue: *v}})
+ continue
+ }
+ if v, ok := cols[i].(*time.Time); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: v.Format(time.RFC3339Nano)}})
+ continue
+ }
+ if v, ok := cols[i].(*big.Int); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: v.String()}})
+ continue
+ }
+ if v, ok := cols[i].(*decimal.Decimal); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: v.String()}})
+ continue
+ }
+ if v, ok := cols[i].(*uuid.UUID); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: v.String()}})
+ continue
+ }
+ if v, ok := cols[i].(*orb.Point); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: wkt.MarshalString(*v)}})
+ continue
+ }
+ if v, ok := cols[i].(*orb.Polygon); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: wkt.MarshalString(*v)}})
+ continue
+ }
+ if v, ok := cols[i].(*orb.Ring); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: wkt.MarshalString(*v)}})
+ continue
+ }
+ if v, ok := cols[i].(*orb.MultiPolygon); ok && v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: wkt.MarshalString(*v)}})
+ continue
+ }
+
+ // nullable
+ if v, ok := cols[i].(**int); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int64Value{Int64Value: int64(**v)}})
+ continue
+ }
+ if v, ok := cols[i].(**int8); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int32Value{Int32Value: int32(**v)}})
+ continue
+ }
+ if v, ok := cols[i].(**int16); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int32Value{Int32Value: int32(**v)}})
+ continue
+ }
+ if v, ok := cols[i].(**int32); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int32Value{Int32Value: **v}})
+ continue
+ }
+ if v, ok := cols[i].(**int64); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Int64Value{Int64Value: **v}})
+ continue
+ }
+ if v, ok := cols[i].(**uint); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint64Value{Uint64Value: uint64(**v)}})
+ continue
+ }
+ if v, ok := cols[i].(**uint8); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint32Value{Uint32Value: uint32(**v)}})
+ continue
+ }
+ if v, ok := cols[i].(**uint16); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint32Value{Uint32Value: uint32(**v)}})
+ continue
+ }
+ if v, ok := cols[i].(**uint32); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint32Value{Uint32Value: **v}})
+ continue
+ }
+ if v, ok := cols[i].(**uint64); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_Uint64Value{Uint64Value: **v}})
+ continue
+ }
+ if v, ok := cols[i].(**float32); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_FloatValue{FloatValue: **v}})
+ continue
+ }
+ if v, ok := cols[i].(**float64); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_DoubleValue{DoubleValue: **v}})
+ continue
+ }
+ if v, ok := cols[i].(**string); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: **v}})
+ continue
+ }
+ if v, ok := cols[i].(**bool); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_BoolValue{BoolValue: **v}})
+ continue
+ }
+ if v, ok := cols[i].(**time.Time); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: (*v).Format(time.RFC3339Nano)}})
+ continue
+ }
+ if v, ok := cols[i].(**big.Int); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: (*v).String()}})
+ continue
+ }
+ if v, ok := cols[i].(**decimal.Decimal); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: (*v).String()}})
+ continue
+ }
+ if v, ok := cols[i].(**uuid.UUID); ok && *v != nil {
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_StringValue{StringValue: (*v).String()}})
+ continue
+ }
+ rowData.Values = append(rowData.Values, &v1pb.RowValue{Kind: &v1pb.RowValue_NullValue{NullValue: structpb.NullValue_NULL_VALUE}})
+ }
+
+ result.Rows = append(result.Rows, &rowData)
+ n := len(result.Rows)
+ if (n&(n-1) == 0) && proto.Size(result) > common.MaximumSQLResultSize {
+ result.Error = common.MaximumSQLResultSizeExceeded
+ return nil
+ }
+ }
+
+ return nil
+}
diff --git a/backend/plugin/db/databricks/databricks.go b/backend/plugin/db/databricks/databricks.go
index c14bc5b701..b5d07bebe4 100644
--- a/backend/plugin/db/databricks/databricks.go
+++ b/backend/plugin/db/databricks/databricks.go
@@ -85,10 +85,6 @@ func (*Driver) GetDB() *sql.DB {
return nil
}
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_DATABRICKS
-}
-
func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, stmt string, _ *db.QueryContext) ([]*v1pb.QueryResult, error) {
return d.RunStatement(ctx, nil, stmt)
}
diff --git a/backend/plugin/db/dm/dm.go b/backend/plugin/db/dm/dm.go
index cecd67bd58..52f9b86392 100644
--- a/backend/plugin/db/dm/dm.go
+++ b/backend/plugin/db/dm/dm.go
@@ -73,11 +73,6 @@ func (driver *Driver) Ping(ctx context.Context) error {
return driver.db.PingContext(ctx)
}
-// GetType returns the database type.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_DM
-}
-
// GetDB gets the database.
func (driver *Driver) GetDB() *sql.DB {
return driver.db
diff --git a/backend/plugin/db/driver.go b/backend/plugin/db/driver.go
index 24b8791383..7bb4f80a72 100644
--- a/backend/plugin/db/driver.go
+++ b/backend/plugin/db/driver.go
@@ -282,7 +282,6 @@ type Driver interface {
// Remember to call Close to avoid connection leak
Close(ctx context.Context) error
Ping(ctx context.Context) error
- GetType() storepb.Engine
GetDB() *sql.DB
// Execute will execute the statement.
Execute(ctx context.Context, statement string, opts ExecuteOptions) (int64, error)
diff --git a/backend/plugin/db/dynamodb/dynamodb.go b/backend/plugin/db/dynamodb/dynamodb.go
index a0516f8ca5..4f0bd33fe8 100644
--- a/backend/plugin/db/dynamodb/dynamodb.go
+++ b/backend/plugin/db/dynamodb/dynamodb.go
@@ -77,11 +77,6 @@ func (d *Driver) Ping(ctx context.Context) error {
return nil
}
-// GetType returns the database type.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_DYNAMODB
-}
-
// GetDB gets the database.
func (*Driver) GetDB() *sql.DB {
return nil
@@ -102,7 +97,7 @@ func (*Driver) GetDB() *sql.DB {
// NOTE: Each api contains some constraints which do not be described in api docs. For example, in ExecuteTransaction, cannot include multiple operations on one item.
// So we use a simple solution here, use parser to split the statement and execute them one by one, unfortunately, we lose the transaction feature.
func (d *Driver) Execute(ctx context.Context, statement string, opts db.ExecuteOptions) (int64, error) {
- statements, err := base.SplitMultiSQL(d.GetType(), statement)
+ statements, err := base.SplitMultiSQL(storepb.Engine_DYNAMODB, statement)
if err != nil {
return 0, errors.Wrapf(err, "failed to split multi statement")
}
@@ -158,7 +153,7 @@ func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement string, q
return nil, errors.New("DynamoDB does not support EXPLAIN")
}
- statements, err := base.SplitMultiSQL(d.GetType(), statement)
+ statements, err := base.SplitMultiSQL(storepb.Engine_DYNAMODB, statement)
if err != nil {
return nil, errors.Wrapf(err, "failed to split multi statement")
}
@@ -410,7 +405,7 @@ func convertAttributeValueToRowValue(attributeValue types.AttributeValue) (*v1pb
// RunStatement executes a SQL statement.
func (d *Driver) RunStatement(ctx context.Context, _ *sql.Conn, statement string) ([]*v1pb.QueryResult, error) {
- statements, err := base.SplitMultiSQL(d.GetType(), statement)
+ statements, err := base.SplitMultiSQL(storepb.Engine_DYNAMODB, statement)
if err != nil {
return nil, errors.Wrapf(err, "failed to split multi statement")
}
diff --git a/backend/plugin/db/elasticsearch/elasticsearch.go b/backend/plugin/db/elasticsearch/elasticsearch.go
index f2111b24e0..9847fa3f0d 100644
--- a/backend/plugin/db/elasticsearch/elasticsearch.go
+++ b/backend/plugin/db/elasticsearch/elasticsearch.go
@@ -237,7 +237,3 @@ func (d *Driver) RunStatement(ctx context.Context, _ *sql.Conn, statement string
func (*Driver) GetDB() *sql.DB {
return nil
}
-
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_ELASTICSEARCH
-}
diff --git a/backend/plugin/db/hive/hive.go b/backend/plugin/db/hive/hive.go
index e0d86510ed..e2a9fc6f68 100644
--- a/backend/plugin/db/hive/hive.go
+++ b/backend/plugin/db/hive/hive.go
@@ -114,10 +114,6 @@ func (d *Driver) Ping(ctx context.Context) error {
return nil
}
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_HIVE
-}
-
func (*Driver) GetDB() *sql.DB {
return nil
}
diff --git a/backend/plugin/db/mongodb/mongodb.go b/backend/plugin/db/mongodb/mongodb.go
index e829691927..c93bdde29c 100644
--- a/backend/plugin/db/mongodb/mongodb.go
+++ b/backend/plugin/db/mongodb/mongodb.go
@@ -87,11 +87,6 @@ func (driver *Driver) Ping(ctx context.Context) error {
return nil
}
-// GetType returns the database type.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_MONGODB
-}
-
// GetDB gets the database.
func (*Driver) GetDB() *sql.DB {
return nil
diff --git a/backend/plugin/db/mssql/mssql.go b/backend/plugin/db/mssql/mssql.go
index 0de7144578..6d36bed035 100644
--- a/backend/plugin/db/mssql/mssql.go
+++ b/backend/plugin/db/mssql/mssql.go
@@ -128,11 +128,6 @@ func (driver *Driver) Ping(ctx context.Context) error {
return driver.db.PingContext(ctx)
}
-// GetType returns the database type.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_MSSQL
-}
-
// GetDB gets the database.
func (driver *Driver) GetDB() *sql.DB {
return driver.db
diff --git a/backend/plugin/db/mysql/mysql.go b/backend/plugin/db/mysql/mysql.go
index 24c5aa9be7..15a552ad2b 100644
--- a/backend/plugin/db/mysql/mysql.go
+++ b/backend/plugin/db/mysql/mysql.go
@@ -242,11 +242,6 @@ func (d *Driver) Ping(ctx context.Context) error {
return d.db.PingContext(ctx)
}
-// GetType returns the database type.
-func (d *Driver) GetType() storepb.Engine {
- return d.dbType
-}
-
// GetDB gets the database.
func (d *Driver) GetDB() *sql.DB {
return d.db
diff --git a/backend/plugin/db/mysql/sync.go b/backend/plugin/db/mysql/sync.go
index 4f2ee3cf6d..43704f6d75 100644
--- a/backend/plugin/db/mysql/sync.go
+++ b/backend/plugin/db/mysql/sync.go
@@ -434,7 +434,7 @@ func (driver *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchema
partitionTables := make(map[db.TableKey][]*storepb.TablePartitionMetadata)
// Query partition info.
- if driver.GetType() == storepb.Engine_MYSQL {
+ if driver.dbType == storepb.Engine_MYSQL {
partitionTables, err = driver.listPartitionTables(ctx, driver.databaseName)
if err != nil {
return nil, err
diff --git a/backend/plugin/db/obo/obo.go b/backend/plugin/db/obo/obo.go
index cf5d572587..8c2a963d3c 100644
--- a/backend/plugin/db/obo/obo.go
+++ b/backend/plugin/db/obo/obo.go
@@ -74,10 +74,6 @@ func (driver *Driver) Ping(ctx context.Context) error {
return driver.db.PingContext(ctx)
}
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_OCEANBASE_ORACLE
-}
-
func (driver *Driver) GetDB() *sql.DB {
return driver.db
}
diff --git a/backend/plugin/db/oracle/oracle.go b/backend/plugin/db/oracle/oracle.go
index 7a8bf346a8..b435f24572 100644
--- a/backend/plugin/db/oracle/oracle.go
+++ b/backend/plugin/db/oracle/oracle.go
@@ -92,11 +92,6 @@ func (driver *Driver) Ping(ctx context.Context) error {
return driver.db.PingContext(ctx)
}
-// GetType returns the database type.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_ORACLE
-}
-
// GetDB gets the database.
func (driver *Driver) GetDB() *sql.DB {
return driver.db
diff --git a/backend/plugin/db/pg/pg.go b/backend/plugin/db/pg/pg.go
index 9248b881fb..a5f21db0e6 100644
--- a/backend/plugin/db/pg/pg.go
+++ b/backend/plugin/db/pg/pg.go
@@ -281,11 +281,6 @@ func (driver *Driver) Ping(ctx context.Context) error {
return driver.db.PingContext(ctx)
}
-// GetType returns the database type.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_POSTGRES
-}
-
// GetDB gets the database.
func (driver *Driver) GetDB() *sql.DB {
return driver.db
diff --git a/backend/plugin/db/redis/redis.go b/backend/plugin/db/redis/redis.go
index cf34bde754..9675abd073 100644
--- a/backend/plugin/db/redis/redis.go
+++ b/backend/plugin/db/redis/redis.go
@@ -178,11 +178,6 @@ func (d *Driver) Ping(ctx context.Context) error {
return d.rdb.Ping(ctx).Err()
}
-// GetType returns redis.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_REDIS
-}
-
// GetDB gets the database.
func (*Driver) GetDB() *sql.DB {
return nil
diff --git a/backend/plugin/db/redshift/redshift.go b/backend/plugin/db/redshift/redshift.go
index 8e1fff0f5e..fb9170bb5d 100644
--- a/backend/plugin/db/redshift/redshift.go
+++ b/backend/plugin/db/redshift/redshift.go
@@ -151,11 +151,6 @@ func (driver *Driver) Ping(ctx context.Context) error {
return driver.db.PingContext(ctx)
}
-// GetType returns the database type.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_REDSHIFT
-}
-
// GetDB gets the database.
func (driver *Driver) GetDB() *sql.DB {
return driver.db
@@ -382,6 +377,11 @@ func (*Driver) querySingleSQL(ctx context.Context, conn *sql.Conn, singleSQL bas
}
}
+ // TODO(d): use a Redshift extraction for shared database.
+ if queryContext != nil && queryContext.ShareDB {
+ statement = strings.ReplaceAll(statement, fmt.Sprintf("%s.", queryContext.CurrentDatabase), "")
+ }
+
startTime := time.Now()
result, err := util.Query(ctx, storepb.Engine_REDSHIFT, conn, statement, queryContext)
if err != nil {
diff --git a/backend/plugin/db/risingwave/risingwave.go b/backend/plugin/db/risingwave/risingwave.go
index b53b6827d0..11ff7db8ed 100644
--- a/backend/plugin/db/risingwave/risingwave.go
+++ b/backend/plugin/db/risingwave/risingwave.go
@@ -182,11 +182,6 @@ func (driver *Driver) Ping(ctx context.Context) error {
return driver.db.PingContext(ctx)
}
-// GetType returns the database type.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_RISINGWAVE
-}
-
// GetDB gets the database.
func (driver *Driver) GetDB() *sql.DB {
return driver.db
diff --git a/backend/plugin/db/snowflake/snowflake.go b/backend/plugin/db/snowflake/snowflake.go
index ecbb20652f..2b155f6f7c 100644
--- a/backend/plugin/db/snowflake/snowflake.go
+++ b/backend/plugin/db/snowflake/snowflake.go
@@ -126,11 +126,6 @@ func (driver *Driver) Ping(ctx context.Context) error {
return driver.db.PingContext(ctx)
}
-// GetType returns the database type.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_SNOWFLAKE
-}
-
// GetDB gets the database.
func (driver *Driver) GetDB() *sql.DB {
return driver.db
diff --git a/backend/plugin/db/spanner/spanner.go b/backend/plugin/db/spanner/spanner.go
index a8157f16a4..007604fc0a 100644
--- a/backend/plugin/db/spanner/spanner.go
+++ b/backend/plugin/db/spanner/spanner.go
@@ -108,11 +108,6 @@ func (d *Driver) Ping(ctx context.Context) error {
return nil
}
-// GetType returns the database type.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_SPANNER
-}
-
// GetDB gets the database.
func (*Driver) GetDB() *sql.DB {
return nil
diff --git a/backend/plugin/db/sqlite/sqlite.go b/backend/plugin/db/sqlite/sqlite.go
index 420298f65a..4200e99973 100644
--- a/backend/plugin/db/sqlite/sqlite.go
+++ b/backend/plugin/db/sqlite/sqlite.go
@@ -72,11 +72,6 @@ func (driver *Driver) Ping(ctx context.Context) error {
return driver.db.PingContext(ctx)
}
-// GetType returns the database type.
-func (*Driver) GetType() storepb.Engine {
- return storepb.Engine_SQLITE
-}
-
// GetDB gets the database.
func (driver *Driver) GetDB() *sql.DB {
return driver.db
diff --git a/backend/plugin/db/starrocks/starrocks.go b/backend/plugin/db/starrocks/starrocks.go
index 0a09119a0f..99e7492c42 100644
--- a/backend/plugin/db/starrocks/starrocks.go
+++ b/backend/plugin/db/starrocks/starrocks.go
@@ -134,11 +134,6 @@ func (driver *Driver) Ping(ctx context.Context) error {
return driver.db.PingContext(ctx)
}
-// GetType returns the database type.
-func (driver *Driver) GetType() storepb.Engine {
- return driver.dbType
-}
-
// GetDB gets the database.
func (driver *Driver) GetDB() *sql.DB {
return driver.db
diff --git a/backend/plugin/db/tidb/tidb.go b/backend/plugin/db/tidb/tidb.go
index 20d999cc96..8b7d88360e 100644
--- a/backend/plugin/db/tidb/tidb.go
+++ b/backend/plugin/db/tidb/tidb.go
@@ -140,11 +140,6 @@ func (d *Driver) Ping(ctx context.Context) error {
return d.db.PingContext(ctx)
}
-// GetType returns the database type.
-func (d *Driver) GetType() storepb.Engine {
- return d.dbType
-}
-
// GetDB gets the database.
func (d *Driver) GetDB() *sql.DB {
return d.db
diff --git a/backend/plugin/db/util/driverutil.go b/backend/plugin/db/util/driverutil.go
index 66584325d1..a71f86572a 100644
--- a/backend/plugin/db/util/driverutil.go
+++ b/backend/plugin/db/util/driverutil.go
@@ -34,11 +34,6 @@ func FormatErrorWithQuery(err error, query string) error {
// Query will execute a readonly / SELECT query.
func Query(ctx context.Context, dbType storepb.Engine, conn *sql.Conn, statement string, queryContext *db.QueryContext) (*v1pb.QueryResult, error) {
- // TODO(d): use a Redshift extraction for shared database.
- if dbType == storepb.Engine_REDSHIFT && queryContext != nil && queryContext.ShareDB {
- statement = strings.ReplaceAll(statement, fmt.Sprintf("%s.", queryContext.CurrentDatabase), "")
- }
-
startTime := time.Now()
readOnly := false
if queryContext != nil {
diff --git a/go.mod b/go.mod
index 8d61888542..44187640ef 100644
--- a/go.mod
+++ b/go.mod
@@ -296,7 +296,7 @@ require (
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
- github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
+ github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c
github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opencensus.io v0.24.0 // indirect