paul-heyse opened a new issue, #4846:
URL: https://github.com/apache/arrow-adbc/issues/4846

   ### What happened?
   
   `adbc_ingest` into a PostgreSQL array column stores a NULL **element** of a 
list as the element type's zero value. It raises no error and gives no warning. 
The affected types are `float8[]`, `bigint[]`, `text[]`, `boolean[]` and a 
domain over `double precision[]`.
   
   Other NULL cases are stored correctly:
   
   | Arrow value | Column type | Stored |
   |---|---|---|
   | `[1.5, None]` | `double precision[]` | `{1.5,0}` |
   | `[1, None]` | `bigint[]` | `{1,0}` |
   | `['a', None]` | `text[]` | `{a,""}` |
   | `[True, None]` | `boolean[]` | `{t,f}` |
   | `[1.5, None]` | domain over `double precision[]` | `{1.5,0}` |
   | `None` (scalar) | `double precision`, `uuid` | `NULL` (correct) |
   | `None` (whole list) | `double precision[]` | `NULL` (correct) |
   | `[]` | `double precision[]` | `{}` (correct) |
   
   Expected: `{1.5,NULL}`, `{1,NULL}`, `{a,NULL}`, `{t,NULL}`.
   
   ### Reproducer
   
   ```python
   # adbc-driver-postgresql==1.12.0, adbc-driver-manager==1.12.0, 
pyarrow==25.0.1, PostgreSQL 18.6
   import adbc_driver_postgresql.dbapi as adbc
   import pyarrow as pa
   
   url = "postgresql:///scratch"  # any empty database
   with adbc.connect(url) as conn, conn.cursor() as cur:
       cur.execute("CREATE TABLE t (v double precision[])")
       cur.adbc_ingest("t", pa.table({"v": pa.array([[1.5, None]], 
pa.list_(pa.float64()))}), mode="append")
       conn.commit()
       cur.execute("SELECT v::text FROM t")
       print(cur.fetchall())  # [('{1.5,0}',)]; expected [('{1.5,NULL}',)]
   ```
   
   ### Probable cause
   
   This is from reading the source on `main` at `63e765286` (2026-09-30); it is 
not a tested patch. In `c/driver/postgresql/copy/writer.h`, 
`PostgresCopyListFieldWriter::Write` puts `has_null_flags = 0` in the array 
header. Its element loop then calls `child_->Write(...)` for every element 
without testing the child's validity bitmap. Only the tuple writer and the 
dictionary writer test validity. The binary array format expects a `-1` length 
for a NULL element, and the flags word to say NULLs are present.
   
   The list writer was last changed by #4320 (the fix for #4319, a sibling 
silent-misalignment issue with sliced list arrays). The CHANGELOG for 1.12.0, 
and for the 1.13.0 rc, lists no change for NULL elements. I found no existing 
issue or PR for this.
   
   ### Environment
   
   - `adbc-driver-postgresql` 1.12.0 and `adbc-driver-manager` 1.12.0 (PyPI 
wheels)
   - pyarrow 25.0.1
   - CPython 3.14
   - PostgreSQL 18.6 on Linux x86_64
   


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