mark1russell7 opened a new issue, #537:
URL: https://github.com/apache/arrow-js/issues/537

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   Two record batches of one dictionary column have dictionaries that start 
with the same chunk and then differ: `shared.concat(["c"])` and 
`shared.concat(["X"])`, where `shared` is `["a", "b"]`. The written batches are 
`["a", "b", "c"]` and `["a", "X"]`. Both the stream and the file format read 
back `["a", "b", "c"]` and `["a", "c"]`. The second batch silently gets the 
dictionary of the first batch.
   
   **Version and platform:** `apache-arrow` 21.2.0, Node.js 24.22.2 on Linux 
(GitHub Actions), and Node.js 24.21.0 on Windows.
   
   **Repro.** Save as `repro.ts` and run `node repro.ts` (Node.js 24 strips the 
types). It exits 1 while the fault is present.
   
   ```ts
   // F0147: apache-arrow 21.2.0. RecordBatchWriter._writeDictionaries() 
compares only the first chunk of a dictionary with
   // the dictionary of the previous batch. When the first chunk is the same 
object and the number of chunks is the same,
   // it writes no DictionaryBatch, also when a later chunk changed. The reader 
then decodes the second batch with the
   // dictionary of the first batch.
   import * as A from "apache-arrow";
   
   const type = new A.Dictionary(new A.Utf8(), new A.Int32(), 0);
   const shared = A.vectorFromArray(["a", "b"], new A.Utf8());
   const first = A.makeData({ type, length: 3, nullCount: 0, data: 
Int32Array.of(0, 1, 2), dictionary: shared.concat(A.vectorFromArray(["c"], new 
A.Utf8())) });
   const second = A.makeData({ type, length: 2, nullCount: 0, data: 
Int32Array.of(0, 2), dictionary: shared.concat(A.vectorFromArray(["X"], new 
A.Utf8())) });
   const table = new A.Table({ d: A.makeVector([first, second]) });
   
   const batches = (t: A.Table): string => t.batches.map((batch) => 
JSON.stringify(Array.from(batch.getChild("d") ?? []))).join(" | ");
   console.log(`written: ${batches(table)}`);
   
   let faults = 0;
   for (const format of ["stream", "file"] as const) {
     const read = A.tableFromIPC(A.tableToIPC(table, format));
     console.log(`read (${format}): ${batches(read)}`);
     if (batches(read) !== batches(table)) faults++;
   }
   
   if (faults > 0) {
     console.log(`BUG PRESENT: ${faults} of 2 formats read a different second 
batch than was written.`);
     process.exit(1);
   }
   console.log("OK: each format reads the batches that were written.");
   ```
   
   **Output** ([CI 
run](https://github.com/mark1russell7/wirelab/actions/runs/44240950212)):
   
   ```
   node: v24.22.2, os: Linux 7.0.0-1019-azure
   
   written: ["a","b","c"] | ["a","X"]
   read (stream): ["a","b","c"] | ["a","c"]
   read (file): ["a","b","c"] | ["a","c"]
   BUG PRESENT: 2 of 2 formats read a different second batch than was written.
   run.sh exit code: 1
   ```
   
   **Expected:** The second batch reads back as `["a", "X"]`. The writer writes 
a replacement DictionaryBatch (stream), or refuses the table (file, where a 
replacement is not allowed), when a chunk after the first one changed.
   
   **Cause:** `RecordBatchWriter._writeDictionaries()` in `src/ipc/writer.ts` 
writes a replacement only when `prevDictionary.data[0] !== chunks[0]`. 
Otherwise it writes the chunks after the previous number of chunks as deltas. 
With the same first chunk and the same number of chunks, it writes nothing, so 
a change in a later chunk is lost.
   
   An AI coding assistant (Claude Code) found this fault, wrote the repro and 
wrote this text.
   


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