Skip to content

[BUG] timechart command does not support groupping by non-string fields #4581

@yuancu

Description

@yuancu

Query Information

PPL Command/Query:

source=opensearch-sql_test_index_otel_logs | timechart avg(severityNumber) by flags

Expected Result:

{
  "schema": [
    {
      "name": "avg(severityNumber)",
      "type": "double"
    },
    {
      "name": "flags",
      "type": "bigint"
    }
  ],
  "datarows": [
    [
      12.310344827586206,
      0
    ],
    [
      9,
      1
    ]
  ],
  "total": 2,
  "size": 2
}

Actual Result:

It reports that it cannot reconcile between string type and bigint type (that of field flags). This indicates that it expects only string type for this field.

{
  "error": {
    "reason": "There was internal problem at backend",
    "details": "Error in visitTimechart: Can't find leastRestrictive type for [BIGINT, CHAR(5)]",
    "type": "RuntimeException"
  },
  "status": 500
}

Dataset Information

Dataset/Schema Type

  • OpenTelemetry (OTEL)
  • Simple Schema for Observability (SS4O)
  • Open Cybersecurity Schema Framework (OCSF)
  • Custom (details below)

Bug Description

Issue Summary:

Timechart command does not support groupping by non-string fields

Environment Information

OpenSearch Version:
3.3.0

Additional Details:

Full stacktrace:

 Incoming request source=table | timechart span=span(identifier, *** m) limit=10 useother=true avg(identifier) by identifier
[2025-10-16T14:24:42,417][ERROR][o.o.s.p.r.RestPPLQueryAction] [7cf34de73b85] Error happened during query handling
java.lang.RuntimeException: Error in visitTimechart: Can't find leastRestrictive type for [BIGINT, CHAR(5)]
        at org.opensearch.sql.calcite.CalciteRelNodeVisitor.visitTimechart(CalciteRelNodeVisitor.java:2150) ~[?:?]
        at org.opensearch.sql.calcite.CalciteRelNodeVisitor.visitTimechart(CalciteRelNodeVisitor.java:154) ~[?:?]
        at org.opensearch.sql.ast.tree.Timechart.accept(Timechart.java:63) ~[?:?]
        at org.opensearch.sql.ast.AbstractNodeVisitor.visitChildren(AbstractNodeVisitor.java:107) ~[?:?]
        at org.opensearch.sql.calcite.CalciteRelNodeVisitor.visitProject(CalciteRelNodeVisitor.java:344) ~[?:?]
        at org.opensearch.sql.calcite.CalciteRelNodeVisitor.visitProject(CalciteRelNodeVisitor.java:154) ~[?:?]
        at org.opensearch.sql.ast.tree.Project.accept(Project.java:65) ~[?:?]
        at org.opensearch.sql.calcite.CalciteRelNodeVisitor.analyze(CalciteRelNodeVisitor.java:167) ~[?:?]
        at org.opensearch.sql.executor.QueryService.analyze(QueryService.java:253) ~[?:?]
        at org.opensearch.sql.executor.QueryService.lambda$executeWithCalcite$0(QueryService.java:102) ~[?:?]
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:319) ~[?:?]
        at org.opensearch.sql.executor.QueryService.lambda$executeWithCalcite$1(QueryService.java:96) ~[?:?]
        at org.opensearch.sql.calcite.CalcitePlanContext.run(CalcitePlanContext.java:121) ~[?:?]
        at org.opensearch.sql.executor.QueryService.executeWithCalcite(QueryService.java:93) ~[?:?]
        at org.opensearch.sql.executor.QueryService.execute(QueryService.java:70) ~[?:?]
        at org.opensearch.sql.executor.execution.QueryPlan.execute(QueryPlan.java:66) ~[?:?]
        at org.opensearch.sql.opensearch.executor.OpenSearchQueryManager.lambda$submit$0(OpenSearchQueryManager.java:28) ~[?:?]
        at org.opensearch.sql.opensearch.executor.OpenSearchQueryManager.lambda$withCurrentContext$1(OpenSearchQueryManager.java:42) ~[?:?]
        at org.opensearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:916) ~[opensearch-3.3.0-SNAPSHOT.jar:3.3.0-SNAPSHOT]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?]
        at java.base/java.lang.Thread.run(Thread.java:1575) [?:?]
Caused by: java.lang.NullPointerException: Can't find leastRestrictive type for [BIGINT, CHAR(5)]
        at java.base/java.util.Objects.requireNonNull(Objects.java:340) ~[?:?]
        at org.apache.calcite.sql.fun.SqlCaseOperator.inferTypeFromOperands(SqlCaseOperator.java:320) ~[?:?]
        at org.apache.calcite.sql.fun.SqlCaseOperator.inferReturnType(SqlCaseOperator.java:223) ~[?:?]
        at org.apache.calcite.rex.RexBuilder.deriveReturnType(RexBuilder.java:346) ~[?:?]
        at org.apache.calcite.tools.RelBuilder.call(RelBuilder.java:758) ~[?:?]
        at org.apache.calcite.tools.RelBuilder.call(RelBuilder.java:765) ~[?:?]
        at org.apache.calcite.tools.RelBuilder.call(RelBuilder.java:736) ~[?:?]
        at org.opensearch.sql.calcite.CalciteRelNodeVisitor.createOtherCaseExpression(CalciteRelNodeVisitor.java:2236) ~[?:?]
        at org.opensearch.sql.calcite.CalciteRelNodeVisitor.buildStandardResult(CalciteRelNodeVisitor.java:2217) ~[?:?]
        at org.opensearch.sql.calcite.CalciteRelNodeVisitor.buildFinalResultWithOther(CalciteRelNodeVisitor.java:2190) ~[?:?]
        at org.opensearch.sql.calcite.CalciteRelNodeVisitor.visitTimechart(CalciteRelNodeVisitor.java:2146) ~[?:?]
        ... 21 more

Metadata

Metadata

Assignees

Labels

PPLPiped processing languagebugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions