Skip to content

Add semantic ordering and deterministic Top-N queries #11

Description

@vara-bonthu

Description

The semantic request supports metrics, dimensions, filters, time grain, and limit, but it cannot order results by a requested metric.
For example, “Which account has the highest current ARR?” currently orders by the account dimension and may return the alphabetically first account instead of the account with the highest ARR.

Proposed solution

Add an orderBy field that:

  • References only requested certified metrics or dimensions.
  • Supports asc and desc.
  • Rejects raw SQL expressions.
  • Adds a stable dimension tie-breaker for deterministic Top-N results.
  • Applies ordering before LIMIT.
{
  "metrics": ["current_annual_recurring_revenue"],
  "dimensions": ["account.account_name"],
  "orderBy": [
    {
      "field": "current_annual_recurring_revenue",
      "direction": "desc"
    },
    {
      "field": "account.account_name",
      "direction": "asc"
    }
  ],
  "limit": 1
}

Implementation areas

  • internal/planner/plan.go
  • internal/planner/plan_sql.go
  • internal/serving/mcp/mcp.go

Planner, MCP, REST, StarRocks, and Trino tests

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions