omkenge commented on PR #1693:
URL: https://github.com/apache/iceberg-python/pull/1693#issuecomment-2673517716

   **Issue:**
   When no rows are updated (i.e., none of the source composite keys match the 
target), the code calls pa.Table.from_arrays([], names=...). This passes 0 
arrays for a schema that expects 6 arrays(origianl schema of table), causing 
the error.
   **ERROR**
   ```
       rows_to_update = upsert_util.get_rows_to_update(df, 
matched_iceberg_table, join_cols)
                        
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/workspaces/pyiceberg/pyiceberg/table/upsert_util.py", line 89, in 
get_rows_to_update
       rows_to_update_table = pa.Table.from_arrays([], 
names=source_table.column_names)
                              
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "pyarrow/table.pxi", line 4851, in pyarrow.lib.Table.from_arrays
     File "pyarrow/table.pxi", line 1593, in pyarrow.lib._sanitize_arrays
     File "pyarrow/table.pxi", line 1557, in pyarrow.lib._schema_from_arrays
   ValueError: Length of names (6) does not match length of arrays (0)
   ```
   **Solution:**
   Create an empty array for each column in the source schema:
   
   ```
   empty_arrays = [pa.array([], type=field.type) for field in 
source_table.schema]
   rows_to_update_table = pa.Table.from_arrays(empty_arrays, 
schema=source_table.schema)
   ```


-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to