Skip to content

[BUG] cast(<boolean> as double) returns 500 #5987

Done

Description

@Swiddis

What is the bug?
Casting a boolean field to double or float fails in codegen with a 500. Casting it to int or long works.

How can one reproduce the bug?

  1. Create the index and doc:
curl -s -X PUT localhost:9200/hdemo -H 'Content-Type: application/json' \
  -d '{"mappings":{"properties":{"s":{"type":"keyword"},"n":{"type":"integer"},"d":{"type":"double"},"b":{"type":"boolean"},"ts":{"type":"date"}}}}' | jq .acknowledged
curl -s -X POST 'localhost:9200/hdemo/_doc?refresh=true' -H 'Content-Type: application/json' \
  -d '{"s":"abc","n":7,"d":1.5,"b":true,"ts":"2026-01-02T03:04:05Z"}' | jq .result
  1. Cast to int/long. This works:
curl -s -X POST localhost:9200/_plugins/_ppl -H 'Content-Type: application/json' \
  -d '{"query":"source=hdemo | eval x = cast(b as int), y = cast(b as long) | fields x, y"}' | jq -c .datarows
# [[1,1]]
  1. Cast to double. This fails, and float fails the same way:
curl -s -X POST localhost:9200/_plugins/_ppl -H 'Content-Type: application/json' \
  -d '{"query":"source=hdemo | eval x = cast(b as double) | fields x"}' | jq -c '{status, error: .error.details[0:160]}'
# {"status":500,"error":"Line 25, Column 97: No applicable constructor/method found for actual parameters \"boolean\"; candidates are: \"public java.lang.Object org.apache.calcite.linq4j.t"}

What is the expected behavior?
[[1.0]], matching the integer casts. A 400 would also be acceptable if boolean → floating point is meant to be unsupported, but not a 500.

What is your host/environment?

  • mainline (3.10.0-SNAPSHOT, c7e2cea), single node

Do you have any screenshots?
N/A

Do you have any additional context?

  • The generated code seems to call Primitive.numberValueRoundDown(Number) on a boolean. The int/long path presumably converts boolean → number first, and the double/float path doesn't.
  • Found by a property-based type checker (hegel).

Activity

  1. added
    bug
    PPL
    dynamic-test
    on Nov 25, 2026
  2. shuseng8 commented on Nov 26, 2026

    @shuseng8
    Contributor

    Hi @Swiddis, I'd like to take this one. Calcite rewrites boolean→int/long casts into CASE(b, 1, 0) but has no equivalent for double/float, so codegen ends up calling numberValueRoundDown on a boolean. I have a fix that maps true/false/null to 1.0/0.0/null (matching the int casts and the v2 engine), with unit, IT and YAML tests, and can open a PR if that sounds good.

  3. moved this from Not Started to Done in PPL Trackeron Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

PPLbugdynamic-test

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions