Skip to content

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

fix(hive): typo and dump (#11462)

Azusaina46822bb56fe
diff --git a/backend/plugin/db/hive/dump.go b/backend/plugin/db/hive/dump.go
index 42c8e31a8b..07ac07ea64 100644
--- a/backend/plugin/db/hive/dump.go
+++ b/backend/plugin/db/hive/dump.go
@@ -52,13 +52,12 @@ type MaterializedViewDDLOptions struct {
as string
}
-func (d *Driver) Dump(ctx context.Context, _ io.Writer, _ bool) (string, error) {
+func (d *Driver) Dump(ctx context.Context, out io.Writer, _ bool) (string, error) {
instanceMetadata, err := d.SyncInstance(ctx)
if err != nil {
return "", errors.Wrapf(err, "failed to sync instance")
}
-
- var dumpStrBuilder strings.Builder
+ var builder strings.Builder
for _, database := range instanceMetadata.Databases {
schema := database.Schemas[0]
@@ -68,7 +67,7 @@ func (d *Driver) Dump(ctx context.Context, _ io.Writer, _ bool) (string, error)
if err != nil {
return "", errors.Wrapf(err, "failed to dump database %s", schema.Name)
}
- _, _ = dumpStrBuilder.WriteString(databaseDDL)
+ _, _ = builder.WriteString(databaseDDL)
// dump managed tables.
for _, table := range schema.Tables {
@@ -79,7 +78,6 @@ func (d *Driver) Dump(ctx context.Context, _ io.Writer, _ bool) (string, error)
// dump indexes.
for _, index := range table.Indexes {
- // TODO(tommy): get more index size from SyncInstance.
indexDDL, err := genIndexDDL(&IndexDDLOptions{
databaseName: schema.Name,
indexName: index.Name,
@@ -100,9 +98,9 @@ func (d *Driver) Dump(ctx context.Context, _ io.Writer, _ bool) (string, error)
return "", errors.Wrapf(err, "failed to generate DDL for index %s", index.Name)
}
- _, _ = dumpStrBuilder.WriteString(fmt.Sprintf(schemaStmtFmt, "INDEX", fmt.Sprintf("`%s`", index.Name), indexDDL))
+ _, _ = builder.WriteString(fmt.Sprintf(schemaStmtFmt, "INDEX", fmt.Sprintf("`%s`", index.Name), indexDDL))
}
- _, _ = dumpStrBuilder.WriteString(tabDDL)
+ _, _ = builder.WriteString(tabDDL)
}
// dump external tables.
@@ -111,7 +109,7 @@ func (d *Driver) Dump(ctx context.Context, _ io.Writer, _ bool) (string, error)
if err != nil {
return "", errors.Wrapf(err, "failed to dump table %s", extTable.Name)
}
- _, _ = dumpStrBuilder.WriteString(tabDDL)
+ _, _ = builder.WriteString(tabDDL)
}
// dump views.
@@ -120,7 +118,7 @@ func (d *Driver) Dump(ctx context.Context, _ io.Writer, _ bool) (string, error)
if err != nil {
return "", errors.Wrapf(err, "failed to dump view %s", view.Name)
}
- _, _ = dumpStrBuilder.WriteString(viewDDL)
+ _, _ = builder.WriteString(viewDDL)
}
// dump materialized views.
@@ -146,11 +144,12 @@ func (d *Driver) Dump(ctx context.Context, _ io.Writer, _ bool) (string, error)
return "", errors.Wrapf(err, "failed to generate DDL for materialized view %s", mtView.Name)
}
- _, _ = dumpStrBuilder.WriteString(fmt.Sprintf(schemaStmtFmt, "MATERIALIZED VIEW", fmt.Sprintf("`%s`.`%s`", schema.Name, mtView.Name), mtViewDDL))
+ _, _ = builder.WriteString(fmt.Sprintf(schemaStmtFmt, "MATERIALIZED VIEW", fmt.Sprintf("`%s`.`%s`", schema.Name, mtView.Name), mtViewDDL))
}
}
- return dumpStrBuilder.String(), nil
+ _, _ = io.WriteString(out, builder.String())
+ return builder.String(), nil
}
// Restore the database from src, which is a full backup.
diff --git a/backend/plugin/db/hive/hive.go b/backend/plugin/db/hive/hive.go
index d235b31ca9..566654e9a0 100644
--- a/backend/plugin/db/hive/hive.go
+++ b/backend/plugin/db/hive/hive.go
@@ -3,7 +3,6 @@ package hive
import (
"context"
"database/sql"
- "fmt"
"strconv"
"strings"
"time"
@@ -285,9 +284,6 @@ func (*Driver) QueryWithConn(ctx context.Context, conn *gohive.Connection, state
for _, statement := range statements {
statementStr := strings.TrimRight(statement.Text, ";")
- if queryCtx != nil && queryCtx.Limit > 0 {
- statementStr = fmt.Sprintf("%s LIMIT %d", statementStr, queryCtx.Limit)
- }
result, err := runSingleStatement(ctx, conn, statementStr)
if err != nil {
@@ -297,6 +293,5 @@ func (*Driver) QueryWithConn(ctx context.Context, conn *gohive.Connection, state
results = append(results, result)
}
-
return results, nil
}
diff --git a/backend/plugin/db/hive/sync.go b/backend/plugin/db/hive/sync.go
index c5c220d01e..a400552735 100644
--- a/backend/plugin/db/hive/sync.go
+++ b/backend/plugin/db/hive/sync.go
@@ -15,6 +15,10 @@ import (
)
func (d *Driver) SyncInstance(ctx context.Context) (*db.InstanceMetadata, error) {
+ if connPool == nil {
+ return nil, errors.New("connection pool not created")
+ }
+
var instanceMetadata db.InstanceMetadata
// version.
@@ -88,7 +92,9 @@ func (d *Driver) getVersion(ctx context.Context) (string, error) {
if err != nil || len(results) == 0 {
return "", errors.Wrap(err, "failed to get version from instance")
}
- return results[0].Rows[0].Values[0].GetStringValue(), nil
+ versionRawStr := results[0].Rows[0].Values[0].GetStringValue()
+ version := strings.Split(versionRawStr, " ")[0]
+ return version, nil
}
func (d *Driver) getDatabaseNames(ctx context.Context) ([]string, error) {
@@ -194,6 +200,7 @@ func (d *Driver) getTables(ctx context.Context, databaseName string) (
}
tableMetadata.Comment = tabInfo.comment
+ tableMetadata.Columns = tabInfo.colMetadatas
tableMetadata.DataSize = int64(tabInfo.totalSize)
tableMetadata.RowCount = int64(tabInfo.numRows)
tableMetadata.Name = tabName
diff --git a/frontend/src/utils/v1/instance.ts b/frontend/src/utils/v1/instance.ts
index f6ca325107..371c80b49d 100644
--- a/frontend/src/utils/v1/instance.ts
+++ b/frontend/src/utils/v1/instance.ts
@@ -274,7 +274,7 @@ export const engineNameV1 = (type: Engine): string => {
case Engine.DORIS:
return "Doris";
case Engine.HIVE:
- return "Apache Hive";
+ return "Hive";
}
return "";
};