davidradl opened a new pull request, #27431:
URL: https://github.com/apache/flink/pull/27431

   ## What is the purpose of the change
   
   The table planner gets an ArrayIndexOutOfBoundsException while unparsing a 
CAST. The error occurs 
[here](https://github.com/apache/flink/blob/0261d498cb4538aefc4bb2f14ef08d0dec6db812/flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/type/ExtendedSqlRowTypeNameSpec.java#L124)
 
   due to an empty comments list being passed 
[here](https://github.com/apache/flink/blob/a8544c44345282f6e1136beeeaa95f47d8ef93d6/flink-table/flink-table-planner/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java#L1103))
 )
   
   Normally this code would have null elements for each field as per the 
[grammar](https://github.com/apache/flink/blob/4def6efb47ebc2dff46f444a3319d3c2ae02c3a6/flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl#L2588)shows).
 
   
   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](https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#7-testing).
   
   
   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)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to