OceanBase
English日本語简体中文
ドキュメントホーム
製品
エコシステム
リリース

データベース

OceanBase CloudOceanBaseデータベース

データベース

OceanBase CloudOceanBaseデータベース
OceanBase CloudOceanBaseデータベース

OceanBaseデータベース

KV - V4.4.2
  • OBKVの概要
  • OBKVのアーキテクチャ
  • OBKV-Table
    • OBKV-Table概要
      • OBKV-Tableの概要
      • OBKV-Tableのコア機能
      • OBKV-Tableデプロイの概要
    • シンプルなKey-Valueストレージのクイックスタート(Java)
    • OBKV-Table Javaクライアントを使ったアプリケーション開発
      • OBKV-Table Java開発ガイド
      • OBKV-Table開発の準備
      • OBKV-Table Javaクライアントを使用してクラスタに接続する
      • OBKV-Table操作例
        • OBKV-Tableへのデータ書き込み
        • OBKV-Tableによるデータのクエリ
        • OBKV-Tableでのデータ更新
        • OBKV-Tableによるデータの削除
      • OBKV-Table Javaクライアントのパラメータ設定
    • OBKV-Table管理
      • OBKV-Table管理の概要
      • OBKV-Tableの高可用性
      • OBKV-Tableのセキュリティ権限
      • OBKV-Tableモニタリングメトリクス
    • OBKV-Tableリファレンス
      • OBKV-Tableのデータモデル
      • OBKV-Tableの操作タイプ
      • OBKV-Tableがサポートするデータ型
      • OBKV-Table全文インデックス
      • OBKV-Tableのグローバルインデックスの使用範囲と例
      • OBKV-Tableの期限切れデータ削除
      • OBKV-Tableのグループコミット
      • OBKV-Tableの弱い整合性読み取りと最寄りデータセンターからの読み取り
      • OBKV-Table関連ビュー
    • OBKV-Table よくある質問
  • OBKV-HBase
    • OBKV-HBaseの概要
    • OBKV-HBaseのコア機能
    • OBKV-HBaseのデプロイ
    • OBKV-HBaseによるアプリケーション開発
      • OBKV-HBase アプリケーション開発の概要
      • OBKV-HBase Javaクライアントを使用したクラスタへの接続
      • HBaseの業務コードをOBKV-HBaseに移行する
      • OBKV-HBase データ操作の例
    • OBKV-HBase 移行ガイド
    • OBKV-HBase管理
      • OBKV-HBase管理の概要
      • OBKV-HBaseの高可用性
      • OBKV-HBaseのセキュリティ権限
      • OBKV-HBaseモニタリングメトリクス
    • OBKV-HBaseクエリの最適化
    • OBKV-HBaseの性能テスト
    • OBKV-HBaseリファレンス
      • OBKV-HBaseデータモデル
      • OBKV-HBaseのデータスキーマ
      • HBaseとの互換インターフェース
      • HBaseと互換性のあるフィルター
      • OBKV-HBaseの自動パーティション分割
      • OBKV-HBaseにおける期限切れデータの削除
      • OBKV-HBaseの弱い整合性読み取りと最寄りデータセンターからの読み取り
      • OBKV-HBase関連ビュー
    • OBKV-HBaseエコシステム統合
      • Flink連携
        • Flinkコネクタを使用してOBKV-HBaseにデータを同期する
        • ネイティブFlinkによるOBKV-HBaseへのアクセス
      • HiveによるOBKV-HBaseへのアクセス
      • SparkによるOBKV-HBaseへのアクセス
  • OBKVリリースノート
    • OBKV Enterprise版

PDF をダウンロード

このページには現在中国語/日本語版がなく、英語版を表示しています。
ドキュメントフィードバック
  1. ドキュメントセンター
  2. OceanBaseデータベース
  3. KV
  4. V4.4.2

Batch operations

最終更新: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.

次のトピック

OBKVの概要
次へ
このページの内容
Create a batch executor
BatchExecutor API
Example