Repository navigation
Description
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:
- Create an index with date fields stored as text
- Use
STR_TO_DATEto parse the date field - Apply
bincommand withspan=1monthon the parsed date - Use
topcommand to aggregate the binned results - 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
binwith complex date expressions and aggregation commands liketop - 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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
[-]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[/+]qianheng-aws commentedon Oct 9, 2025
@ahkcs I think we should enhance the implementation of
binby wrapping these expressions it invokes into one expression(i.e. function), and then the size of generated script should be greatly reduced.songkant-aws commentedon Oct 20, 2025
I can lead this issue
songkant-aws commentedon Jan 13, 2026
I have verified this issue is already mitigated in latest commit. We can close it @LantaoJin
LantaoJin commentedon Jan 13, 2026
Thanks, feel free to reopen if you see similar issue again.