Skip to content

[BUG] PPL bin command with top aggregation causes script size limit exceeded error #4458

Closed

Description

@alexey-temnikov

Query Information

PPL Command/Query:

source=product_info 
| where ISPRESENT(`details.Date First Available`) 
| fields product_id, `details.Date First Available` 
| eval ProductBirthday=STR_TO_DATE(`details.Date First Available`, "%M %e, %Y") 
| bin ProductBirthday span=1month 
| top 50 ProductBirthday

Expected Result:
The query should return the top 50 most frequent monthly bins of ProductBirthday values, showing the binned date values and their counts.

Actual Result:
Query fails with error:

"error": {
  "reason": "Error occurred in OpenSearch engine: all shards failed",
  "details": "Shard[0]: java.lang.IllegalArgumentException: exceeded max allowed inline script size in bytes [65535] with size [66222] for script [...]",
  "type": "SearchPhaseExecutionException"
},
"status": 400

Dataset Information

Dataset/Schema Type

  • Custom (details below)

Index Mapping

{
  "mappings": {
    "properties": {
      "product_id": { "type": "keyword" },
      "details": {
        "properties": {
          "Date First Available": { "type": "text" }
        }
      }
    }
  }
}

Sample Data

{
  "product_id": "PROD001",
  "details": {
    "Date First Available": "January 15, 2023"
  }
}

Bug Description

Issue Summary:
When using the bin command with date/time expressions followed by the top aggregation command, the generated inline script exceeds OpenSearch's maximum allowed script size limit (65,535 bytes), causing query execution to fail.

Steps to Reproduce:

  1. Create an index with date fields stored as text
  2. Use STR_TO_DATE to parse the date field
  3. Apply bin command with span=1month on the parsed date
  4. Use top command to aggregate the binned results
  5. Execute the query

Impact:
This bug prevents users from performing time-based binning analysis with aggregations on date fields, which is a common use case for time series analysis and reporting.

Environment Information

OpenSearch Version:
OpenSearch 3.3.0-SNAPSHOT

Additional Details:

  • SQL Plugin Version: 3.3.0.0-SNAPSHOT
  • The issue occurs specifically when combining bin with complex date expressions and aggregation commands like top
  • Simple queries without aggregation work fine
  • Aggregation on other fields (not the binned field) works fine

Root Cause Analysis

Preliminary Analysis:
The issue appears to be in the expression serialization process in /opensearch/src/main/java/org/opensearch/sql/opensearch/storage/serde/DefaultExpressionSerializer.java. When the bin command creates complex date/time calculation expressions (involving STR_TO_DATE, YEAR, MONTH, MAKEDATE, DATE_FORMAT, etc.), the serialized expression becomes extremely large.

The bin command with span=1month generates a complex Calcite expression tree that includes multiple nested function calls for date arithmetic. When this expression is serialized using Java's ObjectOutputStream and Base64 encoding in DefaultExpressionSerializer.serialize(), it produces a script that exceeds OpenSearch's 65,535-byte limit for inline scripts.

This is a preliminary analysis and the actual root cause and fix may differ upon deeper investigation.

Activity

  1. changed the title [-]PPL `bin` command with `top` aggregation causes script size limit exceeded error[/-] [+][BUG] PPL `bin` command with `top` aggregation causes script size limit exceeded error[/+] on Oct 8, 2025
  2. qianheng-aws commented on Oct 9, 2025

    @qianheng-aws
    Collaborator

    @ahkcs I think we should enhance the implementation of bin by wrapping these expressions it invokes into one expression(i.e. function), and then the size of generated script should be greatly reduced.

  3. added
    PPL
    calcite
    pushdown
    and removed on Oct 9, 2025
  4. added
    bug
    on Oct 9, 2025
  5. moved this from Not Started to Pending in PPL Trackeron Oct 20, 2025
  6. songkant-aws commented on Oct 20, 2025

    @songkant-aws
    Collaborator

    I can lead this issue

  7. songkant-aws commented on Jan 13, 2026

    @songkant-aws
    Collaborator

    I have verified this issue is already mitigated in latest commit. We can close it @LantaoJin

  8. LantaoJin commented on Jan 13, 2026

    @LantaoJin
    Member

    Thanks, feel free to reopen if you see similar issue again.

  9. moved this from Pending to Done in PPL Trackeron Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

PPLbugcalcitepushdown

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions