Copilot commented on code in PR #433:
URL: https://github.com/apache/arrow-dotnet/pull/433#discussion_r4682263252


##########
src/Apache.Arrow/Ipc/ArrowStreamWriter.cs:
##########
@@ -1570,12 +1570,15 @@ public virtual void Dispose()
 
     internal static class DictionaryCollector
     {
-        internal static void Collect(RecordBatch recordBatch, ref 
DictionaryMemo dictionaryMemo)
+        // Dictionary ids were assigned to the writer schema's own Field 
instances when the
+        // schema was serialized, and DictionaryMemo keys on Field reference 
identity — a batch
+        // built with its own (value-equal) Schema would be minted a fresh, 
undeclared id.
+        // Resolve ids against the writer's schema; only take column data from 
the batch.
+        internal static void Collect(Schema writerSchema, RecordBatch 
recordBatch, ref DictionaryMemo dictionaryMemo)
         {
-            Schema schema = recordBatch.Schema;
-            for (int i = 0; i < schema.FieldsList.Count; i++)
+            for (int i = 0; i < writerSchema.FieldsList.Count; i++)
             {
-                Field field = schema.GetFieldByIndex(i);
+                Field field = writerSchema.GetFieldByIndex(i);
                 IArrowArray array = recordBatch.Column(i);

Review Comment:
   This only makes dictionary collection use the writer schema, but the 
subsequent record-batch serialization still calls 
`PrepareWritingRecordBatch(recordBatch)`, which walks 
`recordBatch.Schema.FieldsList` and `GetDictionaryOffset` assigns IDs by 
`Field` reference. When a later batch has a value-equal but distinct schema, 
the dictionary is emitted under the writer field's ID (for example, 0) while 
the record batch header is encoded with a newly assigned ID (for example, 1); 
the reader then cannot resolve that dictionary. The new 
`TestGetRecordBatchesWithDistinctSchemaInstancesPerBatch` exercises exactly 
this path. The record-batch field traversal also needs to use the writer schema 
(or otherwise map batch fields back to the writer fields).



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