OceanBase
English日本語简体中文
Docs Home
Products
Integrations
Release Notes

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service
OceanBase DatabaseOceanBase Cloud ToolsConnectors and MiddlewareLifecycle Support Policy

OceanBase Database

KV - V4.3.5
  • OBKV overview
  • Architecture
  • OBKV-Table
    • Introduction to OBKV-Table
      • Overview
      • OBKV-Table operation types
      • Core features of OBKV-Table
      • Differences between replace and insert_or_update
      • Supported value types
      • OBKV-Table data models
    • Use the OBKV-Table Java client
      • Java development guide for OBKV-Table
      • Prepare for development with OBKV-Table
      • Use the OBKV-Table Java client to connect to a cluster
      • Set client parameters
      • Supported client interfaces
      • Use the OBKV-Table Java client
    • Use the OBKV-Table GO client
      • Use the OBKV-Table Go client to connect to a cluster
      • Overview of the Go client
      • Individual API operations
      • Batch operations
      • About queries
      • Aggregation API
      • Filters
    • FAQ
  • OBKV-HBase
    • Overview
    • OBKV-HBase core features
    • Compatibility with HBase
    • Deployment
    • Application development with OBKV-HBase
      • Overview of OBKV-HBase application development
      • Data model
      • Data model design
      • Connect to a cluster using the OBKV-HBase client
      • Migrate HBase business code to OBKV-HBase
      • Data operation examples
      • Delete expired data
    • OBKV-HBase migration guide
    • OBKV-HBase management
      • Overview
      • High availability
      • Security and permissions
      • Monitoring metrics
    • Performance test
    • OBKV-HBase integrations
      • Flink
        • Synchronize data to OBKV-HBase by using Flink
    • Views
    • FAQ

Download PDF

Document Feedback
  1. Documentation Center
  2. OceanBase Database
  3. KV
  4. V4.3.5

Batch operations

Last Updated:2026-09-04 10:25:15

Create a batch executor
BatchExecutor API
Example

Create a batch executor

The syntax is as follows:

// NewBatchExecutor create a batch executor.
NewBatchExecutor(tableName string) BatchExecutor

Input parameters:

  • tableName: the name of the table.

Response parameters:

  • BatchExecutor: the batch executor.

BatchExecutor API

The syntax is as follows:

type BatchExecutor interface {
    // AddInsertOp add an insert operation to the batch executor.
    AddInsertOp(rowKey []*table.Column, mutateValues []*table.Column, opts ...ObkvOption) error
    // AddUpdateOp add an update operation to the batch executor.
    AddUpdateOp(rowKey []*table.Column, mutateValues []*table.Column, opts ...ObkvOption) error
    // AddInsertOrUpdateOp add an insertOrUpdate operation to the batch executor
    AddInsertOrUpdateOp(rowKey []*table.Column, mutateValues []*table.Column, opts ...ObkvOption) error
    // AddReplaceOp add a replace operation to the batch executor
    AddReplaceOp(rowKey []*table.Column, mutateValues []*table.Column, opts ...ObkvOption) error
    // AddIncrementOp add an increment operation to the batch executor
    AddIncrementOp(rowKey []*table.Column, mutateValues []*table.Column, opts ...ObkvOption) error
    // AddAppendOp add an append operation to the batch executor
    AddAppendOp(rowKey []*table.Column, mutateValues []*table.Column, opts ...ObkvOption) error
    // AddDeleteOp add a delete operation to the batch executor
    AddDeleteOp(rowKey []*table.Column, opts ...ObkvOption) error
    // AddGetOp add a get operation to the batch executor.
    AddGetOp(rowKey []*table.Column, getColumns []string, opts ...ObkvOption) error
    // Execute a batch operation.
    // batch operation only ensures atomicity of a single partition.
    // BatchOperationResult contains the results of all operations.
    Execute(ctx context.Context) (BatchOperationResult, error)
}

Input parameters:

  • AddInsertOp: adds the Insert operation.
  • AddUpdateOp: adds the Update operation.
  • AddInsertOrUpdateOp: adds the InsertOrUpdate operation.
  • AddReplaceOp: adds the Replace operation.
  • AddIncrementOp: adds the Increment operation.
  • AddAppendOp: adds the Append operation.
  • AddDeleteOp: adds the Delete operation.
  • AddGetOp: adds the Get operation.
  • Execute: executes multiple operations at a time. The execution result is returned in BatchOperationResult.

The syntax of BatchOperationResult is as follows:

type BatchOperationResult interface {
    // IsEmptySet result is empty or not.
    IsEmptySet() bool
    // GetResults get all results.
    GetResults() []SingleResult
    // Size batch operation size.
    Size() int
    // SuccessIdx indexes of successful operation.
    SuccessIdx() []int
    // ErrorIdx indexes of unsuccessful operation.
    ErrorIdx() []int
}

Input parameters:

  • IsEmptySet: indicates whether the result is empty.
  • GetResults: the result array.
  • Size: the number of results.
  • SuccessIdx: the sequence number of a successful operation.
  • ErrorIdx: the sequence number of a failed operation.

Example

// CREATE TABLE test(c1 bigint, c2 bigint, PRIMARY KEY(c1)) PARTITION BY hash(c1) partitions 2;
func main() {
    const (
        configUrl    = "xxx"
        fullUserName = "user@tenant#cluster"
        passWord     = ""
        sysUserName  = "sysUser"
        sysPassWord  = ""
        tableName    = "test"
    )
    cfg := config.NewDefaultClientConfig()
    cli, err := client.NewClient(configUrl, fullUserName, passWord, sysUserName, sysPassWord, cfg)
    if err != nil {
        panic(err)
    }

    batchExecutor := cli.NewBatchExecutor(tableName)

    rowKey1 := []*table.Column{table.NewColumn("c1", int64(1))}
    rowKey2 := []*table.Column{table.NewColumn("c1", int64(2))}
    selectColumns1 := []string{"c1"}
    selectColumns2 := []string{"c2"}
    err = batchExecutor.AddGetOp(rowKey1, selectColumns1)
    if err != nil {
        panic(err)
    }
    err = batchExecutor.AddGetOp(rowKey2, selectColumns2)
    if err != nil {
        panic(err)
    }

    ctx, _ := context.WithTimeout(context.Background(), time.Duration(1000)*time.Millisecond) // 1000ms
    res, err := batchExecutor.Execute(ctx)
    if err != nil {
        panic(err)
    }

    if res.Size() != 2 {
        panic(err)
    }
    println(res.GetResults()[0].Entity().GetProperty("c1"))
    println(res.GetResults()[1].Entity().GetProperty("c2"))
}
  • In this example, two Get operations are executed at a time.
  • Two results are returned. Result 0 contains the value of c1, and Result 1 contains the value of c2.

Previous topic

Individual API operations
Last

Next topic

About queries
Next
on this page
Create a batch executor
BatchExecutor API
Example