opensearch-project / opensearch-project/sql

[BUG] Make return type inferrable for TRANSFORM and other lambda functions

Open
#4,972 2 comments 1 reaction 1 assignee View on GitHub

@yuancu is already working on this.

Since Dec 22, 2025.

enhancement PPL
Dominant language
Java
Stars
176
Forks
229
Avg merge
2d 21h
Merged PRs (30d)
43

Description

Query Information

PPL Command/Query:

source=people | eval array = array(1, -2, 3), result = transform(array, x -> x + 2) | fields result

Expected Result:
[3,0,5] of type INTEGER ARRAY

Actual Result:
[3,0,5] of type ANY ARRAY

Dataset Information

Dataset/Schema Type

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

Index Mapping
Mapping not relevant

Bug Description

Before #4892, the types are injected at runtime:

https://github.com/opensearch-project/sql/blob/d19ba53249f32ca8429f8404ca8ef74ab7a1d935/core/src/main/java/org/opensearch/sql/expression/function/CollectionUDF/TransformFunctionImpl.java#L183

https://github.com/opensearch-project/sql/blob/d19ba53249f32ca8429f8404ca8ef74ab7a1d935/core/src/main/java/org/opensearch/sql/expression/function/CollectionUDF/TransformFunctionImpl.java#L190-L191

However, the standard SQL requires the return type to be inferrable before executing the query. Currently, the argument is of type ANY, making the result also typed ANY. Therefore, the result array is an ANY array. For this case, it is indeed inferrable -- the array is an INTEGER ARRAY, meaning that x should be of type INTEGER instead of ANY.

Impact:
doctest in collections.md

Environment Information

OpenSearch Version: 3.4 (with PR #4892 )

Screenshots

File "/Users/yuanchu/src/sql/doctest/../docs/user/ppl/functions/collection.md", line 167, in /Users/yuanchu/src/sql/doctest/../docs/user/ppl/functions/collection.md
Failed example:
    ppl_cmd.process('source=people | eval array = array(1, -2, 3), result = transform(array, x -> x + 2) | fields result | head 1')
Expected:
    fetched rows / total rows = 1/1
    +---------+
    | result  |
    |---------|
    | [3,0,5] |
    +---------+
Got:
    fetched rows / total rows = 1/1
    +---------------+
    | result        |
    |---------------|
    | [3.0,0.0,5.0] |
    +---------------+

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.