Skip to content

[BUG] COALESCE(null, 42) returns wrong type string instead of int due to leastRestrictive type inference #5175

Description

@penghuo

Query Information

PPL Command/Query:

source=bounty-types | eval x=COALESCE(null, 42) | fields x | head 1
source=bounty-types | eval x=COALESCE(42, null) | fields x | head 1

Expected Result:
Result value should be numeric 42 (integer type), not string.

Actual Result:
Both queries return "42" with schema type string.

Dataset Information

Dataset/Schema Type

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

Index Mapping

{
  "mappings": {
    "properties": {
      "dummy": { "type": "keyword" }
    }
  }
}

Sample Data

{ "dummy": "row" }

Bug Description

Issue Summary:
COALESCE resolves to wrong output type for integer/null expressions.

Steps to Reproduce:

  1. Ensure bounty-types contains at least one row.
  2. Run both queries above.
  3. Observe schema type string and value "42".

Impact:
Type correctness is broken and can cascade into later expression errors.

Activity

  1. added
    bug
    PPL
    on Feb 24, 2026
  2. self-assigned this
    on Apr 15, 2026
  3. songkant-aws commented on Apr 15, 2026

    @songkant-aws
    Collaborator
    1. Short-term fix: Replace this line(https://github.com/opensearch-project/sql/blob/main/core/src/main/java/org/opensearch/sql/calcite/QualifiedNameResolver.java#L322) with creating SqlTypeName.NULL type instead of VARCHAR. It will fix the confusion of coercionToType in EnhancedCoalesceFunction.
    2. Long-term fix: Appropriate type system introduction for validation.
  4. moved this from Not Started to Done in PPL Trackeron Apr 24, 2026
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