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

About queries

Last Updated: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.

Previous topic

Batch operations
Last

Next topic

Aggregation API
Next
on this page
Get a query iterator
ObQueryOption
QueryResultIterator
QueryResult
Example