Skip to content

[BUG] bin with stats command throw exception #4322

Closed

Description

@penghuo

What is the bug?
A clear and concise description of the bug.

How can one reproduce the bug?

###
POST {{baseUrl}}/_plugins/_ppl
Content-Type: application/x-ndjson

{
  "query": "search source=log* | bin @timestamp span=5m | stats count by @timestamp"
}

{
  "error": {
    "reason": "Error occurred in OpenSearch engine: all shards failed",
    "details": "Shard[0]: org.opensearch.sql.exception.ExpressionEvaluationException: invalid to get doubleValue from value of type STRING\n\nFor more details, please send request for Json format to see the raw response from OpenSearch engine.",
    "type": "SearchPhaseExecutionException"
  },
  "status": 500
}

What is the expected behavior?
no exception, results is same as

###
POST {{baseUrl}}/_plugins/_ppl
Content-Type: application/x-ndjson

{
  "query": "search source=log* | stats count by span(@timestamp, 5m)"
}

{
...
  "datarows": [
    [
      1,
      "2025-09-04 16:15:00"
    ]
  ],
...
}

Do you have any additional context?

### 1 create index template
POST {{baseUrl}}/_index_template/log-template
Content-Type: application/x-ndjson

{
  "index_patterns": ["logs-*"],
  "priority": 100,
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 1
    },
    "mappings": {
      "dynamic_templates": [
        {
          "resource_attributes": {
            "path_match": "resource.attributes.*",
            "mapping": { "type": "keyword" },
            "match_mapping_type": "string"
          }
        },
        {
          "attributes": {
            "path_match": "attributes.*",
            "mapping": { "type": "keyword" },
            "match_mapping_type": "string"
          }
        }
      ],
      "properties": {
        "traceId": { "type": "keyword" },
        "flags": { "type": "byte" },
        "severityNumber": { "type": "integer" },
        "body": {"norms": false, "type": "text"},
        "serviceName": { "type": "keyword" },
        "schemaUrl": { "type": "keyword" },
        "spanId": { "type": "keyword" },
        "@timestamp": { "type": "date" },
        "severityText": { "type": "keyword" },
        "@version": { "type": "keyword" },
        "attributes": {
          "type": "object",
          "properties": {
            "time": { "enabled": false, "type": "object" }
          }
        },
        "time": { "type": "date" },
        "observedTimestamp": { "type": "date" }
      }
    }
  }
}

### create index
PUT {{baseUrl}}/log-00001

### index doc
POST {{baseUrl}}/log-00001/_doc
Content-Type: application/x-ndjson

{
    "traceId": "",
    "instrumentationScope": {
        "droppedAttributesCount": 0
    },
    "resource": {
        "droppedAttributesCount": 0,
        "attributes": {
            "log_type": "EKS_node",
            "k8s_label.productid": "pr123456",
            "k8s_label.sourcetype": "unknown",
            "productid": "pr123456",
            "k8s.platform": "EKS",
            "k8s_label.criticality_code": "99",
            "k8s.cluster.business.unit": "bu",
            "criticality_code": "5",
            "sourcetype": "unknown",
            "log_tier": "standard",
            "applicationid": "ap123456",
            "obs_namespace": "defaultv1"
        },
        "schemaUrl": ""
    },
    "flags": 0,
    "severityNumber": 0,
    "schemaUrl": "",
    "spanId": "",
    "severityText": "",
    "attributes": {
        "cluster.name": "xyz-cluster1-ci-prod-us-east-1",
        "cluster.region": "us-east-1",
        "log.file.path": "/var/log/xyz/abc.log",
        "cluster.env": "prod",
        "obs_body_length": 146
    },
    "time": "2025-09-04T16:17:36.046227585Z",
    "droppedAttributesCount": 0,
    "observedTimestamp": "2025-09-04T16:17:36.046227585Z",
    "@timestamp": "2025-09-04T16:17:39.133Z",
    "body": "{\"msg\":\"Error finding unassigned IPs for ENI xyz\",\"caller\":\"xyz/abc.go:702\",\"level\":\"error\",\"ts\":\"2025-09-04T16:17:35.976Z\"}"
}

Activity

  1. added
    bug
    PPL
    on Sep 17, 2025
  2. ahkcs commented on Sep 17, 2025

    @ahkcs
    Collaborator

    Related issue: #4063 and pending PR: #4245

  3. yuancu commented on Sep 18, 2025

    @yuancu
    Collaborator

    Even with #4245, the given PPL fails.

    Both source=time_test | bin @timestamp span=1day and source=time_test | stats count by @timestamp works. However, it does not work with them combined: source=time_test | bin @timestamp span=1day | stats count by @timestamp

    Error
     {
      "error": {
        "reason": "Error occurred in OpenSearch engine: all shards failed",
        "details": "Shard[0]: AggregationExecutionException[Unsupported script value [2025-07-28 00:00:00], expected a number, date, or boolean]\n\nFor more details, please send request for Json format to see the raw response from OpenSearch engine.",
        "type": "SearchPhaseExecutionException"
      },
      "status": 500
    }
    Stacktrace
    Caused by: org.opensearch.search.aggregations.AggregationExecutionException: Unsupported script value [2025-07-28 00:00:00], expected a number, date, or boolean
            at org.opensearch.search.aggregations.support.values.ScriptLongValues.toLongValue(ScriptLongValues.java:119) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.aggregations.support.values.ScriptLongValues.advanceExact(ScriptLongValues.java:97) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.aggregations.bucket.composite.LongValuesSource$1.collect(LongValuesSource.java:193) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.aggregations.LeafBucketCollector.collect(LeafBucketCollector.java:123) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.aggregations.bucket.composite.CompositeAggregator$3.collect(CompositeAggregator.java:637) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.aggregations.LeafBucketCollector.collect(LeafBucketCollector.java:123) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.apache.lucene.search.Weight$DefaultBulkScorer.scoreIterator(Weight.java:298) ~[lucene-core-10.2.2.jar:10.2.2 279eb7aaafe985e5d0552b7f2a10b63185a3f893 - 2025-06-17 09:30:59]
            at org.apache.lucene.search.Weight$DefaultBulkScorer.score(Weight.java:280) ~[lucene-core-10.2.2.jar:10.2.2 279eb7aaafe985e5d0552b7f2a10b63185a3f893 - 2025-06-17 09:30:59]
            at org.opensearch.search.internal.CancellableBulkScorer.score(CancellableBulkScorer.java:71) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.internal.ContextIndexSearcher.searchLeaf(ContextIndexSearcher.java:366) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:315) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.apache.lucene.search.IndexSearcher.lambda$search$1(IndexSearcher.java:779) ~[lucene-core-10.2.2.jar:10.2.2 279eb7aaafe985e5d0552b7f2a10b63185a3f893 - 2025-06-17 09:30:59]
            at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317) ~[?:?]
            at org.apache.lucene.search.TaskExecutor$Task.run(TaskExecutor.java:173) ~[lucene-core-10.2.2.jar:10.2.2 279eb7aaafe985e5d0552b7f2a10b63185a3f893 - 2025-06-17 09:30:59]
            at org.apache.lucene.search.TaskExecutor.invokeAll(TaskExecutor.java:111) ~[lucene-core-10.2.2.jar:10.2.2 279eb7aaafe985e5d0552b7f2a10b63185a3f893 - 2025-06-17 09:30:59]
            at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:783) ~[lucene-core-10.2.2.jar:10.2.2 279eb7aaafe985e5d0552b7f2a10b63185a3f893 - 2025-06-17 09:30:59]
            at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:750) ~[lucene-core-10.2.2.jar:10.2.2 279eb7aaafe985e5d0552b7f2a10b63185a3f893 - 2025-06-17 09:30:59]
            at org.opensearch.search.query.ConcurrentQueryPhaseSearcher.searchWithCollectorManager(ConcurrentQueryPhaseSearcher.java:89) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.query.ConcurrentQueryPhaseSearcher.searchWithCollector(ConcurrentQueryPhaseSearcher.java:52) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.query.QueryPhase$DefaultQueryPhaseSearcher.searchWithCollector(QueryPhase.java:450) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.query.QueryPhase$DefaultQueryPhaseSearcher.searchWith(QueryPhase.java:433) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.query.QueryPhaseSearcherWrapper.searchWith(QueryPhaseSearcherWrapper.java:58) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.query.QueryPhase.executeInternal(QueryPhase.java:283) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.query.QueryPhase.execute(QueryPhase.java:156) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.indices.IndicesService.lambda$loadIntoContext$0(IndicesService.java:1956) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.indices.IndicesService.lambda$cacheShardLevelResult$0(IndicesService.java:2017) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.indices.IndicesRequestCache$Loader.load(IndicesRequestCache.java:379) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.indices.IndicesRequestCache$Loader.load(IndicesRequestCache.java:362) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.common.cache.store.OpenSearchOnHeapCache.lambda$computeIfAbsent$0(OpenSearchOnHeapCache.java:108) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.common.cache.Cache.compute(Cache.java:492) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.common.cache.Cache.computeIfAbsent(Cache.java:443) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.common.cache.store.OpenSearchOnHeapCache.computeIfAbsent(OpenSearchOnHeapCache.java:108) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.indices.IndicesRequestCache.getOrCompute(IndicesRequestCache.java:323) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.indices.IndicesService.cacheShardLevelResult(IndicesService.java:2023) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.indices.IndicesService.loadIntoContext(IndicesService.java:1954) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.SearchService.loadOrExecuteQueryPhase(SearchService.java:680) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.SearchService.executeQueryPhase(SearchService.java:780) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.search.SearchService$2.lambda$onResponse$0(SearchService.java:738) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.action.ActionRunnable.lambda$supply$0(ActionRunnable.java:74) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.action.ActionRunnable$2.doRun(ActionRunnable.java:89) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.threadpool.TaskAwareRunnable.doRun(TaskAwareRunnable.java:78) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:59) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:975) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52) ~[opensearch-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
            ... 3 more
    
    Generated script
    CalciteEnumerableIndexScan(table=[[OpenSearch, time_test]], PushDownContext=[[AGGREGATION->rel#2174:LogicalAggregate.NONE.[](input=RelSubset#2173,group={0},count=COUNT()), PROJECT->[count, @timestamp], LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":0,"timeout":"1m","aggregations":{"composite_buckets":{"composite":{"size":1000,"sources":[{"@timestamp":{"terms":{"script":{"source":"{"langType":"calcite","script":"{
      "op": {
        "name": "TIMESTAMP",
        "kind": "OTHER_FUNCTION",
        "syntax": "FUNCTION"
      },
      "operands": [
        {
          "op": {
            "name": "ADDDATE",
            "kind": "OTHER_FUNCTION",
            "syntax": "FUNCTION"
          },
          "operands": [
            {
              "literal": "1970-01-01",
              "type": {
                "type": "CHAR",
                "nullable": false,
                "precision": 10
              }
            },
            {
              "op": {
                "name": "-",
                "kind": "MINUS",
                "syntax": "BINARY"
              },
              "operands": [
                {
                  "op": {
                    "name": "DATEDIFF",
                    "kind": "OTHER_FUNCTION",
                    "syntax": "FUNCTION"
                  },
                  "operands": [
                    {
                      "op": {
                        "name": "DATE",
                        "kind": "OTHER_FUNCTION",
                        "syntax": "FUNCTION"
                      },
                      "operands": [
                        {
                          "input": 0,
                          "name": "$0"
                        }
                      ],
                      "class": "org.opensearch.sql.expression.function.UserDefinedFunctionBuilder$1",
                      "type": {
                        "type": "VARCHAR",
                        "nullable": true,
                        "precision": -1
                      },
                      "deterministic": true,
                      "dynamic": false
                    },
                    {
                      "literal": "1970-01-01",
                      "type": {
                        "type": "CHAR",
                        "nullable": false,
                        "precision": 10
                      }
                    }
                  ],
                  "class": "org.opensearch.sql.expression.function.UserDefinedFunctionBuilder$1",
                  "type": {
                    "type": "BIGINT",
                    "nullable": true
                  },
                  "deterministic": true,
                  "dynamic": false
                },
                {
                  "op": {
                    "name": "MOD",
                    "kind": "MOD",
                    "syntax": "FUNCTION"
                  },
                  "operands": [
                    {
                      "op": {
                        "name": "DATEDIFF",
                        "kind": "OTHER_FUNCTION",
                        "syntax": "FUNCTION"
                      },
                      "operands": [
                        {
                          "op": {
                            "name": "DATE",
                            "kind": "OTHER_FUNCTION",
                            "syntax": "FUNCTION"
                          },
                          "operands": [
                            {
                              "input": 0,
                              "name": "$0"
                            }
                          ],
                          "class": "org.opensearch.sql.expression.function.UserDefinedFunctionBuilder$1",
                          "type": {
                            "type": "VARCHAR",
                            "nullable": true,
                            "precision": -1
                          },
                          "deterministic": true,
                          "dynamic": false
                        },
                        {
                          "literal": "1970-01-01",
                          "type": {
                            "type": "CHAR",
                            "nullable": false,
                            "precision": 10
                          }
                        }
                      ],
                      "class": "org.opensearch.sql.expression.function.UserDefinedFunctionBuilder$1",
                      "type": {
                        "type": "BIGINT",
                        "nullable": true
                      },
                      "deterministic": true,
                      "dynamic": false
                    },
                    {
                      "literal": 1,
                      "type": {
                        "type": "INTEGER",
                        "nullable": false
                      }
                    }
                  ]
                }
              ],
              "type": {
                "type": "BIGINT",
                "nullable": true
              }
            }
          ],
          "class": "org.opensearch.sql.expression.function.UserDefinedFunctionBuilder$1",
          "type": {
            "type": "VARCHAR",
            "nullable": true,
            "precision": -1
          },
          "deterministic": true,
          "dynamic": false
        }
      ],
      "class": "org.opensearch.sql.expression.function.UserDefinedFunctionBuilder$1",
      "type": {
        "type": "VARCHAR",
        "nullable": true,
        "precision": -1
      },
      "deterministic": true,
      "dynamic": false
    }"}","lang":"opensearch_compounded_script","params":{"utcTimestamp":1758186764879184000}},"missing_bucket":true,"value_type":"long","missing_order":"first","order":"asc"}}}]},"aggregations":{"count":{"value_count":{"field":"_index"}}}}}}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])

    It seems that it regards the script result as a long: "value_type":"long", but it got a timestamp string.

  4. self-assigned this
    on Sep 22, 2025
  5. moved this from Not Started to Done in PPL Trackeron Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

PPLbug

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions