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

Aggregation API

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

Get an AggExecutor
AggExecutor
Example

Get an AggExecutor

The syntax is as follows:

type Client interface {
    // NewAggExecutor create an aggregate executor.
    NewAggExecutor(tableName string, rangePairs []*table.RangePair, opts ...option.ObQueryOption) AggExecutor
}

Input parameters:

  • tableName: the name of the table.
  • rangePairs: the aggregation range.
  • opts: the optional parameters, some of which are supported. You can specify these parameters as needed.

Response parameters:

AggExecutor: the aggregation executor.

AggExecutor

The syntax is as follows:

type AggExecutor interface {
    // Min add a min operation to the agg executor.
    Min(columnName string) AggExecutor
    // Max add a max operation to the agg executor.
    Max(columnName string) AggExecutor
    // Count add a count operation to the agg executor.
    Count() AggExecutor
    // Sum add a sum operation to the agg executor.
    Sum(columnName string) AggExecutor
    // Avg add an avg operation to the agg executor.
    Avg(columnName string) AggExecutor
    // Execute an agg operation.
    // AggregateResult contains the results of all operations.
    Execute(ctx context.Context) (AggregateResult, error)
}

Input parameters:

  • Min(columnName string): calculates the minimum value of the column specified by columnName.
  • Max(columnName string): calculates the maximum value of the column specified by columnName.
  • Count(columnName string): calculates the number of rows within the range.
  • Sum(columnName string): calculates the sum of the column specified by columnName.
  • Avg(columnName string): calculates the average value of the column specified by columnName.
  • Execute(ctx context.Context): executes the aggregation operation.

Example

Get the sum of column c3, the minimum value of column c2, and the maximum value of column c1 for the rows whose c1 value is in the range of 0 to 100, as well as the total number of columns within the range.

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

    // create agg executor
    aggExecutor := cli.NewAggExecutor(tableName, keyRanges).Sum("c3").Min("c2").Max("c1").Count()

    // get agg result
    res, err := aggExecutor.Execute(context.TODO())

    if err != nil {
        panic(err)
    }

    // get agg result value
    println(res.Value("sum(c3)").(int64))
    println(res.Value("min(c2)").(int64))
    println(res.Value("max(c1)").(int64))
    println(res.Value("count(*)").(int64))
}

Previous topic

About queries
Last

Next topic

Filters
Next
on this page
Get an AggExecutor
AggExecutor
Example