Skip to content

ClassCastException: ArrayList cannot be cast to Long on multi-valued long fields #5232

Closed as duplicate

Description

@ahkcs

Bug Report

PPL queries that perform expressions (eval, arithmetic, comparisons) on multi-valued long fields throw ClassCastException when the Calcite engine is enabled.

Error

{
  "error": {
    "reason": "There was internal problem at backend",
    "details": "class java.util.ArrayList cannot be cast to class java.lang.Long",
    "type": "ClassCastException"
  },
  "status": 500
}

Reproduction

Index with a long field containing array data:

PUT /test_index/_doc/1
{"response_times": [120, 350, 90], "message": "ok"}

Queries that fail:

source=test_index | eval doubled = response_times * 2
source=test_index | where response_times > 100 | eval total = response_times + 1

Queries that succeed (no expression on the array field):

source=test_index
source=test_index | fields response_times
source=test_index | stats count()

Activity

  1. added
    bug
    and removed on Mar 13, 2026
  2. assigned and unassigned on Mar 25, 2026
  3. sunil9977 commented on Mar 26, 2026

    @sunil9977
    Contributor

    Hi @ahkcs , Could you please assign it to me?

  4. LantaoJin commented on Mar 31, 2026

    @LantaoJin
    Member

    @ahkcs what behavior do you expected?

  5. LantaoJin commented on Mar 31, 2026

    @LantaoJin
    Member

    IMO, we can permanently fix it as long as we could identify a field is multivalued, I found there is an issue open in Lucene apache/lucene#15794.

  6. sunil9977 commented on Apr 1, 2026

    @sunil9977
    Contributor

    Hi @LantaoJin @ahkcs The issue is that Calcite maps long fields as scalar BIGINT since OpenSearch mappings don't distinguish single vs multi-valued fields. At runtime, multi-valued fields come back as ArrayList but generated code expects Long, causing the ClassCastException.
    For now, I've caught the ClassCastException and converted it to a 400 ExpressionEvaluationException with a clear error message, matching v2 engine behaviour.
    Please let me know your thoughts.

  7. songkant-aws commented on Apr 9, 2026

    @songkant-aws
    Collaborator

    In the long-term solution, it could be resolved by dynamic type inference/resolution at runtime. Maybe it belongs to that meta issue instead of a bug. Related to: #4984

  8. added
    enhancement
    and removed
    bug
    on Apr 10, 2026
  9. qianheng-aws commented on Apr 10, 2026

    @qianheng-aws
    Collaborator

    Closing as duplicate of #5333 — consolidated umbrella issue for array values not treated as atomic values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions