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


##########
src/Apache.Arrow/Arrays/ArrayDataConcatenator.cs:
##########
@@ -286,6 +287,201 @@ public void Visit(UnionType type)
 
             public void Visit(MapType type) => 
ConcatenateLists(type.UnsortedKey()); /* Can't tell if the output is still 
sorted */
 
+            public void Visit(RunEndEncodedType type)
+            {
+                ArrowTypeId runEndsTypeId = type.RunEndsDataType.TypeId;
+                if (runEndsTypeId != ArrowTypeId.Int16 &&
+                    runEndsTypeId != ArrowTypeId.Int32 &&
+                    runEndsTypeId != ArrowTypeId.Int64)
+                {
+                    throw new InvalidOperationException(
+                        $"Run-ends array must be Int16, Int32, or Int64, but 
got {runEndsTypeId}");
+                }
+
+                var slicedValues = new List<ArrayData>(_arrayDataList.Count);
+                ArrowBuffer.Builder<short> int16Builder = null;
+                ArrowBuffer.Builder<int> int32Builder = null;
+                ArrowBuffer.Builder<long> int64Builder = null;
+
+                switch (runEndsTypeId)
+                {
+                    case ArrowTypeId.Int16: int16Builder = new 
ArrowBuffer.Builder<short>(); break;
+                    case ArrowTypeId.Int32: int32Builder = new 
ArrowBuffer.Builder<int>(); break;
+                    case ArrowTypeId.Int64: int64Builder = new 
ArrowBuffer.Builder<long>(); break;
+                }
+
+                long baseOffset = 0;
+                int physicalRunCount = 0;
+
+                foreach (ArrayData arrayData in _arrayDataList)
+                {
+                    arrayData.EnsureDataType(type.TypeId);
+
+                    ArrayData runEndsData = arrayData.Children[0];
+                    ArrayData valuesData = arrayData.Children[1];
+
+                    if (runEndsData.DataType.TypeId != runEndsTypeId)
+                    {
+                        throw new ArgumentException(
+                            $"All run-end encoded arrays must have the same 
run-ends type. Expected <{runEndsTypeId}> but got 
<{runEndsData.DataType.TypeId}>.");
+                    }
+                    if (valuesData.DataType.TypeId != 
type.ValuesDataType.TypeId)
+                    {
+                        throw new ArgumentException(
+                            $"All run-end encoded arrays must have the same 
values type. Expected <{type.ValuesDataType.TypeId}> but got 
<{valuesData.DataType.TypeId}>.");
+                    }
+
+                    if (arrayData.Length == 0)
+                    {
+                        continue;
+                    }
+
+                    int logicalOffset = arrayData.Offset;
+                    int logicalLength = arrayData.Length;
+                    int logicalEnd = logicalOffset + logicalLength;
+
+                    int physicalStart;
+                    int physicalEndExclusive;
+
+                    switch (runEndsTypeId)
+                    {
+                        case ArrowTypeId.Int16:
+                            {
+                                ReadOnlySpan<short> re = 
runEndsData.Buffers[1].Span.CastTo<short>()
+                                    .Slice(runEndsData.Offset, 
runEndsData.Length);
+                                physicalStart = FindPhysicalStartInt16(re, 
logicalOffset);
+                                physicalEndExclusive = 
FindPhysicalEndExclusiveInt16(re, logicalEnd, physicalStart);
+                                for (int p = physicalStart; p < 
physicalEndExclusive; p++)
+                                {
+                                    int adjustedEnd = Math.Min((int)re[p], 
logicalEnd) - logicalOffset;
+                                    
int16Builder.Append(checked((short)(baseOffset + adjustedEnd)));
+                                }

Review Comment:
   I'm okay with this for now.



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