CurtHagenlocher commented on code in PR #332:
URL: https://github.com/apache/arrow-dotnet/pull/332#discussion_r3158479650


##########
src/Apache.Arrow.Operations/Shredding/ShreddedVariantArrayBuilder.cs:
##########
@@ -0,0 +1,513 @@
+// 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.Collections.Generic;
+using Apache.Arrow;
+using Apache.Arrow.Arrays;
+using Apache.Arrow.Memory;
+using Apache.Arrow.Scalars.Variant;
+using Apache.Arrow.Types;
+
+namespace Apache.Arrow.Operations.Shredding
+{
+    /// <summary>
+    /// Assembles a shredded <see cref="VariantArray"/> from pre-shredded rows.
+    /// Produces an Arrow struct with shared <c>metadata</c>, residual 
<c>value</c>,
+    /// and the <c>typed_value</c> tree whose Arrow shape matches the <see 
cref="ShredSchema"/>.
+    /// </summary>
+    public static class ShreddedVariantArrayBuilder
+    {
+        /// <summary>
+        /// Builds a shredded <see cref="VariantArray"/> from the output of
+        /// <see 
cref="VariantShredder.Shred(System.Collections.Generic.IEnumerable{VariantValue},
 ShredSchema)"/>.
+        /// </summary>
+        /// <param name="schema">The shredding schema applied to each 
row.</param>
+        /// <param name="metadata">The column-level variant metadata (shared 
across rows).</param>
+        /// <param name="rows">Per-row shred results whose residual bytes 
reference <paramref name="metadata"/>.</param>
+        /// <param name="allocator">Arrow memory allocator, or default if 
null.</param>
+        public static VariantArray Build(
+            ShredSchema schema,
+            byte[] metadata,
+            IReadOnlyList<ShredResult> rows,
+            MemoryAllocator allocator = null)
+        {
+            if (schema == null) throw new 
ArgumentNullException(nameof(schema));
+            if (metadata == null) throw new 
ArgumentNullException(nameof(metadata));
+            if (rows == null) throw new ArgumentNullException(nameof(rows));
+
+            int rowCount = rows.Count;
+
+            // metadata column: emit the shared bytes once per row. (A 
dictionary-encoded
+            // or run-end-encoded representation would compress this; 
VariantArray's reader
+            // already handles those, but for simplicity we emit the plain 
binary form.)
+            BinaryArray.Builder metadataBuilder = new BinaryArray.Builder();
+            for (int i = 0; i < rowCount; i++)
+            {
+                metadataBuilder.Append((ReadOnlySpan<byte>)metadata);
+            }
+            BinaryArray metadataArr = metadataBuilder.Build(allocator);
+
+            // value column: residual bytes (or null).
+            BinaryArray valueArr = BuildBinaryColumn(rows, allocator);

Review Comment:
   My concern with doing that is a hypothetical scenario where we're shredding 
a column in a very large table. We get the values as an `IArrowArrayStream` 
instead of an `IArrowArray` and we run each of the batches through 
`ShredSchemaInferrer`, leaving us with a `ShredSchema`. Now we take a second 
pass through the `IArrowArrayStream` and shred the batches, one at a time. Each 
of the batches will need to conform to the shredded schema and we can't just 
omit `values` in one of them without knowing whether or not it can be omitted 
in all of them.
   
   In short, I think this would require a separate knob based on the bigger 
picture.



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