Skip to content

SQL: return more understandable error when not grouping by a histogram #37952

@eskibars

Description

@eskibars

Testing on 6.6.0.

Consider using SQL to query for a 1-minute histogram, e.g. across a default metricbeat index (and the default time field, @timestamp).

GET /_xpack/sql?format=txt
{
  "query": """
  SELECT HISTOGRAM("@timestamp", INTERVAL 1 MINUTE) AS h FROM "metricbeat-*" GROUP BY h
  """
}

This correctly returns. However, when omitting GROUP BY ... as in:

GET /_xpack/sql?format=txt
{
  "query": """
  SELECT HISTOGRAM("@timestamp", INTERVAL 1 MINUTE) FROM "metricbeat-*"
  """
}

We get:

{
  "error": {
    "root_cause": [
      {
        "type": "sql_illegal_argument_exception",
        "reason": "Unknown output attribute HISTOGRAM(@timestamp){g->2644358}#2644358"
      }
    ],
    "type": "sql_illegal_argument_exception",
    "reason": "Unknown output attribute HISTOGRAM(@timestamp){g->2644358}#2644358"
  },
  "status": 500
}

We should clean up the error here so it's easier for a user to understand what they've done wrong.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions