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


##########
src/Apache.Arrow/Ipc/DictionaryMemo.cs:
##########
@@ -107,11 +107,48 @@ public void AddOrReplaceDictionary(long id, IArrowArray 
dictionary)
             _idToDictionary[id] = dictionary;
         }
 
-        public void AddDeltaDictionary(long id, IArrowArray deltaDictionary, 
MemoryAllocator allocator = default)
+        /// <summary>
+        /// Adds or replaces a dictionary the memo owns, releasing the one it 
replaces. Readers own
+        /// their dictionaries; each record batch holds its own reference.
+        /// </summary>
+        public void ReplaceOwnedDictionary(long id, IArrowArray dictionary)
         {
-            IArrowArray currentDictionary = _idToDictionary[id];
-            IArrowArray dictionary = ArrowArrayConcatenator.Concatenate(new 
List<IArrowArray> { currentDictionary, deltaDictionary }, allocator);
-            AddOrReplaceDictionary(id, dictionary);
+            _idToDictionary.TryGetValue(id, out IArrowArray previous);
+            _idToDictionary[id] = dictionary;
+            if (!ReferenceEquals(previous, dictionary))
+            {
+                previous?.Dispose();
+            }
+        }
+
+        /// <summary>
+        /// Appends a delta to a dictionary the memo owns, releasing both the 
delta and the
+        /// dictionary it replaces.
+        /// </summary>
+        public void AddOwnedDeltaDictionary(long id, IArrowArray 
deltaDictionary, MemoryAllocator allocator = default)
+        {
+            try
+            {
+                IArrowArray currentDictionary = _idToDictionary[id];
+                IArrowArray dictionary = 
ArrowArrayConcatenator.Concatenate(new List<IArrowArray> { currentDictionary, 
deltaDictionary }, allocator);
+                ReplaceOwnedDictionary(id, dictionary);

Review Comment:
   Please add lifecycle tests that replace a loaded dictionary and apply a 
delta. `DictionaryReferenceTests.Write` reuses one batch, and 
`ArrowStreamWriter` emits dictionaries only once, so the new replacement/delta 
disposal paths are never exercised. Verify that earlier batches remain 
readable, the replaced dictionary and delta allocations are released correctly, 
and the delta is disposed when concatenation fails.



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