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

About queries

最終更新:2026-09-04 10:25:15

Get a query iterator
ObQueryOption
QueryResultIterator
QueryResult
Example

Get a query iterator

The syntax is as follows:

type Client interface {
    // Query records by rangePairs.
    Query(ctx context.Context, tableName string, rangePairs []*table.RangePair, opts ...option.ObQueryOption) (QueryResultIterator, error)
}

Input parameters:

  • ctx: the API timeout period.
  • tableName: the name of the table.
  • rangePairs: the primary key.
  • opts: the additional options. This parameter is optional.

Response parameters:

  • QueryResultIterator: the query iterator to obtain the result.
  • error: the error code and error message.

ObQueryOption

The syntax is as follows:

type ObQueryOptions struct {
    QueryFilter   filter.ObTableFilter
    HTableFilter  hfilter.ObHTableFilter
    SelectColumns []string
    IndexName     string
    BatchSize     int32
    MaxResultSize int64
    Limit         int32
    Offset        int32
    ScanOrder     table.ScanOrder
    IsHbaseQuery  bool
    KeyValueMode  table.ObKeyValueMode
}

Note

You can set most available parameters in the format of option.WithQuery+corresponding parameter(). You can set the Limit parameter in the format of option.WithQueryLimit().

Input parameters:

  • WithQueryFilter: the query filter.
  • WithQuerySelectColumns: the names of the columns whose values need to be returned. The names of the columns that use filters and the columns whose values need to be returned must be included.
  • WithQueryIndexName: the index name. The default value is the primary key.
  • WithQueryBatchSize: the maximum number of results carried in a packet during network communication.
  • WithQueryMaxResultSize: the maximum number of packets to be returned.
  • WithQueryLimit: the maximum number of results for a partition.
  • WithQueryOffset: the result sequence number starting from which results are returned.
  • WithQueryScanOrder: the scan order.

QueryResultIterator

The syntax is as follows:

type QueryResultIterator interface {
    IsClosed() bool
    Close()
    Next() (QueryResult, error)
    NextBatch() ([]QueryResult, error)
}

Input parameters:

  • IsClosed(): specifies whether to disable the iterator.
  • Close(): specifies to disable the iterator.
  • Next(): specifies to obtain the next output. The result is of the QueryResult type. This parameter cannot be used with NextBatch().
  • NextBatch(): specifies to obtain the next batch of output. The result type is a QueryResult array. This parameter cannot be used with Next().

QueryResult

The syntax is as follows:

type QueryResult interface {
    Value(columnName string) interface{}
    Values() []interface{}
}

Input parameters:

  • Value(columnName string): obtains the values of the column specified by columnName. If the column does not exist, nil is returned.
  • Values(): obtains the values of a row.

Example

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)
    }

    startRowKey := []*table.Column{table.NewColumn("c1", int64(0)), table.NewColumn("c2", table.Min)}
    endRowKey := []*table.Column{table.NewColumn("c1", int64(100)), table.NewColumn("c2", table.Max)}
    keyRanges := []*table.RangePair{table.NewRangePair(startRowKey, endRowKey)}

    lt30 := filter.CompareVal(filter.LessThan, "c2", int64(30))
    gt10 := filter.CompareVal(filter.GreaterThan, "c2", int64(10))
    filterList := filter.AndList(lt30, gt10)

    resSet, err := cli.Query(
        context.TODO(),
        tableName,
        keyRanges,
        option.WithQuerySelectColumns([]string{"c1", "c2", "c3"}),
        option.WithQueryBatchSize(batchSize),
        option.WithQueryFilter(filterList),
    )
    assert.Equal(t, nil, err)
    i := 0
    res, err := resSet.Next()
    for ; res != nil && err == nil; res, err = resSet.Next() {
        assert.EqualValues(t, res.Value("c1"), res.Value("c2"))
        assert.EqualValues(t, "hello", res.Value("c3"))
        i++
    }
    assert.Equal(t, nil, err)
    assert.EqualValues(t, 19, i)

Note

All rows whose c1 values are within the range of 0 to 100 are scanned, and then the values of the c1, c2, and c3 columns of the rows that meet the following conditions are returned: c2 > 10 and c2 < 30.

次のトピック

OBKVの概要
次へ
このページの内容
Get a query iterator
ObQueryOption
QueryResultIterator
QueryResult
Example