MCPcopy Create free account
hub / github.com/bytebase/bytebase / Execute

Method Execute

backend/plugin/db/hive/hive.go:147–179  ·  view source on GitHub ↗

Transaction statements [BEGIN, COMMIT, ROLLBACK] are not supported in Hive 4.0 temporarily. Even in Hive's bucketed transaction table, all the statements are committed automatically by the Hive server.

(ctx context.Context, statementsStr string, _ db.ExecuteOptions)

Source from the content-addressed store, hash-verified

145// Even in Hive's bucketed transaction table, all the statements are committed automatically by
146// the Hive server.
147func (d *Driver) Execute(ctx context.Context, statementsStr string, _ db.ExecuteOptions) (int64, error) {
148 // Hive has limited transaction support:
149 // - Only ACID tables support transactions, and even then it's limited
150 // - Transaction statements (BEGIN, COMMIT, ROLLBACK) are not supported in Hive 4.0
151 // - All statements are auto-committed by the Hive server
152 // Due to these limitations, we execute statements individually regardless of transaction mode
153 // but we still parse and respect the transaction mode directive for consistency
154
155 if d.db == nil {
156 return 0, errors.New("connection not initialized")
157 }
158
159 statements, err := base.SplitMultiSQL(storepb.Engine_HIVE, statementsStr)
160 if err != nil {
161 return 0, errors.Wrapf(err, "failed to split statements")
162 }
163
164 var totalAffected int64
165 for _, statement := range statements {
166 query := strings.TrimRight(statement.Text, ";")
167
168 result, err := d.db.ExecContext(ctx, query)
169 if err != nil {
170 return totalAffected, errors.Wrapf(err, "failed to execute statement: %s", query)
171 }
172
173 // Hive may not always return accurate row counts
174 affected, _ := result.RowsAffected()
175 totalAffected += affected
176 }
177
178 return totalAffected, nil
179}
180
181func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement string, queryCtx db.QueryContext) ([]*v1pb.QueryResult, error) {
182 if d.db == nil {

Callers

nothing calls this directly

Implementers 15

MockDriverbackend/plugin/advisor/utils_for_tests
Driverbackend/plugin/db/bigquery/bigquery.go
Driverbackend/plugin/db/mongodb/mongodb.go
Driverbackend/plugin/db/trino/trino.go
Driverbackend/plugin/db/redshift/redshift.go
Driverbackend/plugin/db/oracle/oracle.go
Driverbackend/plugin/db/dynamodb/dynamodb.go
Driverbackend/plugin/db/cosmosdb/cosmosdb.go
Driverbackend/plugin/db/spanner/spanner.go
Driverbackend/plugin/db/mssql/mssql.go
Driverbackend/plugin/db/mysql/mysql.go
Driverbackend/plugin/db/pg/pg.go

Calls 1

SplitMultiSQLFunction · 0.92

Tested by

no test coverage detected