Skip to content

[BUG] Aggregation Push-Down Script Generation Exceeds OpenSearch Script Size Limit #3999

Closed

Description

@ahkcs

Bug Description

Commit b0c07008f8 ("Support aggregation push down with scripts (#3916)") introduced a change that causes queries with complex expressions in aggregation context to fail due to OpenSearch's 65KB inline script size limit. The aggregation push-down feature now serializes large script payloads, often exceeding 1.2MB, resulting in runtime failures.

Related: PR #3878 triggers this issue (check CI for details)

Error Message

java.lang.IllegalArgumentException: exceeded max allowed inline script size in bytes [65535] with size [1224050] for script

Root Cause Analysis

The issue originates from AggregateBuilderHelper.build() in AggregateAnalyzer.java:

<T> T build(RexNode node, Function<String, T> fieldBuilder, Function<Script, T> scriptBuilder) {
  if (node instanceof RexCall || node instanceof RexLiteral) {
    // Problem: complex expressions generate huge serialized script objects
    return scriptBuilder.apply(
      new PredicateAnalyzer.ScriptQueryExpression(node, rowType, fieldTypes, cluster).getScript());
  }
}

Technical Context

The original bin command implementation for bins, minspan and start/end used window functions (MIN() OVER() and MAX() OVER()) to calculate data range. This produced a massive RexCall expression tree with deeply nested operations.

When aggregation push-down was introduced, any RexCall in the grouping expression got serialized into an inline script for OpenSearch.

The serialized script ballooned to over 1.2MB, far exceeding OpenSearch's 65KB inline script limit.


CC: @qianheng-aws

Activity

  1. added
    bug
    PPL
    on Aug 6, 2025
  2. changed the title [-][BUG] Brief description of the issue[/-] [+][BUG] Aggregation Push-Down Script Generation Exceeds OpenSearch Script Size Limit[/+] on Aug 6, 2025
  3. self-assigned this
    on Aug 11, 2025
  4. moved this from Not Started to In progress in PPL Trackeron Aug 11, 2025
  5. moved this from In progress to In review in PPL Trackeron Aug 11, 2025
  6. moved this from In review to Done in PPL Trackeron Aug 15, 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