1fanwang opened a new pull request, #25953:
URL: https://github.com/apache/datafusion/pull/25953

   ## Which issue does this PR close?
   
   - Closes #25950.
   
   ## Rationale for this change
   
   Calling array_repeat on a list column whose element field is non-nullable, 
or not named item (element is common in external schemas), returns an Arrow 
error instead of a result. Plain List(Int64) works. LargeList fails the same 
way.
   
   ## What changes are included in this PR?
   
   When the first argument is a list, array_repeat rebuilt each repeated inner 
list with a fresh nullable item field. The outer list, and return_type, declare 
the inner type as the input type, so Arrow rejected the mismatch. The inner 
list now reuses the input's own element field, so the built array matches the 
planned return type, for example List(List(non-null Int64)).
   
   ## What is the testing strategy for this PR?
   
   New cases in array/array_repeat.slt cover non-null and element-named fields 
for List and LargeList, checking both values and arrow_typeof. They fail on 
main with the error below.
   
   End to end with datafusion-cli:
   
   ```sql
   CREATE TABLE t AS SELECT make_array(1, 2) AS a, arrow_cast(make_array(1, 2), 
'List(non-null Int64)') AS b, arrow_cast(make_array(1, 2), 'List(Int64, field: 
''element'')') AS c, arrow_cast(make_array(1, 2), 'LargeList(non-null Int64)') 
AS d;
   SELECT array_repeat(b, 2) FROM t;
   SELECT array_repeat(c, 2) FROM t;
   SELECT array_repeat(d, 2) FROM t;
   ```
   
   ```
   $ ./target/debug/datafusion-cli -f repro.sql
   ```
   
   Before (main):
   
   ```
   Arrow error: Invalid argument error: ListArray expected data type 
List(non-null Int64) got List(Int64) for "item"
   Arrow error: Invalid argument error: ListArray expected data type 
List(Int64, field: 'element') got List(Int64) for "item"
   Arrow error: Invalid argument error: LargeListArray expected data type 
LargeList(non-null Int64) got LargeList(Int64) for "item"
   ```
   
   After:
   
   ```
   +----------------------------+
   | array_repeat(t.b,Int64(2)) |
   +----------------------------+
   | [[1, 2], [1, 2]]           |
   +----------------------------+
   +----------------------------+
   | array_repeat(t.c,Int64(2)) |
   +----------------------------+
   | [[1, 2], [1, 2]]           |
   +----------------------------+
   +----------------------------+
   | array_repeat(t.d,Int64(2)) |
   +----------------------------+
   | [[1, 2], [1, 2]]           |
   +----------------------------+
   ```
   
   ## Are there any user-facing changes?
   
   array_repeat now works on lists with non-nullable or custom-named element 
fields. No API changes.
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to