Skip to content

Conversation

@davidradl
Copy link
Contributor

What is the purpose of the change

The table planner gets an ArrayIndexOutOfBoundsException while unparsing a CAST. The error occurs here
due to an empty comments list being passed here) )

Normally this code would have null elements for each field as per the grammarshows).

The change is to bounds check to ensure that there is a comments element before addressing it.
The rejected alternative is to fill the list with nulls in the caller for the failing case.

Brief change log

  • add bounds check to comments if in unparse.

Verifying this change

Please make sure both new and modified tests in this PR follow the conventions for tests defined in our code quality guide.

This change added tests and can be verified as follows:

  • added a unit test, this had to be in the table planner, as the parser unit tests added the commnets as per the grammar, so were not testing the fix.

  • can be verified in the SQL client by issuing
    "CREATE TABLE orders (

    `const_requestBody_arrayOfObjectsOfObjects` AS ARRAY[ROW(ROW('I''m happy', CAST(NULL AS BOOLEAN))), ROW(CAST(NULL AS ROW<`string` STRING, `boolean` BOOLEAN>))]
    

) WITH (
'connector' = 'filesystem',
'path' = 'file:///Users/davidradley/bashscripts/sqlscripts/json/test_avro.json',
'format' = 'avro'
);"
Prior to the fix this get the ArrayIndexOutOfBoundsException

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (no)
  • The serializers: ( no )
  • The runtime per-record code paths (performance sensitive): ( no )
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no )
  • The S3 file system connector: (no )

Documentation

  • Does this pull request introduce a new feature? ( no)

…arsing CAST

Signed-off-by: davidradl <david_radley@uk.ibm.com>
@davidradl davidradl marked this pull request as ready for review January 16, 2026 13:25
@flinkbot
Copy link
Collaborator

flinkbot commented Jan 16, 2026

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

import static org.assertj.core.api.Assertions.assertThat;

/** Tests for {@link SqlTypeUtil}. */
class SqlTypeUtilTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the issue is fixed in parser, can we have tests in parser?

}
if (comments.get(i) != null) {
// With bounds check - prevents IndexOutOfBoundsException
if (i < comments.size() && comments.get(i) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the logic correctly working if some fields is the middle without comments and fields in the beginning and end are with comments?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably also need a test for that

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants