Skip to content

ANSI mode array access error messages don't match Spark format #3375

@andygrove

Description

@andygrove

Describe the bug

When ANSI mode is enabled (spark.sql.ansi.enabled=true), Comet throws exceptions for out-of-bounds array access, but the error message format differs from Spark's format.

Spark Error Messages

For array[index] (GetArrayItem):
[INVALID_ARRAY_INDEX] The index X is out of bounds. The array has Y elements. Use the SQL function get() to tolerate accessing element at invalid index and return NULL instead.

For element_at(array, index) with out-of-bounds:
[INVALID_ARRAY_INDEX_IN_ELEMENT_AT] The index X is out of bounds. The array has Y elements. Use try_element_at to tolerate accessing element at invalid index and return NULL instead.

For element_at(array, 0):
[INVALID_INDEX_OF_ZERO] The index 0 is invalid. An index shall be either < 0 or > 0 (the first element has index 1).

Comet Error Messages

Comet currently throws:
org.apache.comet.CometNativeException: Index out of bounds for array

Steps to reproduce

No response

Expected behavior

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions