CurtHagenlocher commented on code in PR #257: URL: https://github.com/apache/arrow-dotnet/pull/257#discussion_r2839021660
########## src/Apache.Arrow.Operations/Comparison.cs: ########## @@ -0,0 +1,390 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +using System; +using System.Numerics; +using Apache.Arrow; +using Apache.Arrow.Memory; +using Apache.Arrow.Types; + +namespace Apache.Arrow.Operations; + +public static class Comparison +{ + /// <summary> + /// Negate a boolean array, flipping true to false, false to true. Nulls remain null + /// </summary> + /// <param name="mask"></param> + /// <param name="allocator"></param> + /// <returns></returns> + public static BooleanArray Invert(BooleanArray mask, MemoryAllocator? allocator = null) + { + var builder = new BooleanArray.Builder(); + builder.Reserve(mask.Length); + foreach (var val in mask) Review Comment: > Is it that an array assumes it is the unique owner of its value and validity buffer and might mutate them directly? It is because an array assumes that it's the unique owner of its buffers, yes. So if you share the buffer and the first array is disposed, the second one will be holding an invalid buffer. To fix this, buffers would need something like a reference count. This would also be very helpful when exporting via the C API, but I think I've convinced myself that the functionality can't be added in a backwards-compatible way. The library doesn't support mutable arrays either, which is also a gap if you wanted to optimize computation over arrays. A processing engine might determine, for instance that the expression `a + b` could just reuse `a`'s storage as the target of the computation and avoid having to allocate a new array -- if `a` is never going to be used again. I'm skeptical that C# has the right semantics to implement this in a purely "safe" way but haven't put much effort into working anything out. (Of course, types like `StringArray` are extremely hard to mutate in place no matter what the capabilities of the implementation language.) -- 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]
