forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apacheGH-36795: [C#] Implement support for dense and sparse unions (a…
…pache#36797) ### What changes are included in this PR? Support dense and sparse unions in the C# implementation. Adds Archery support for C# unions. ### Are these changes tested? Yes ### Are there any user-facing changes? Unions are now supported in the C# implementation. **This PR includes breaking changes to public APIs.** The public APIs for the UnionArray and UnionType were changed fairly substantially. As these were previously not implemented properly, the impact of the changes ought to be minimal. The ChunkedArray and Column classes were changed to hold IArrowArrays instead of Arrays. To accomodate this, a constructor was added which may introduce ambiguity in calling code. This could be avoided by changing the overloaded constructor to instead be a factory method. This didn't seem worthwhile but could be reconsidered. The metadata version was finally increased to V5. * Closes: apache#36795 Authored-by: Curt Hagenlocher <[email protected]> Signed-off-by: David Li <[email protected]>
- Loading branch information
1 parent
5408fef
commit 9aa67b2
Showing
32 changed files
with
797 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// 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 Apache.Arrow.Types; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Apache.Arrow | ||
{ | ||
public class DenseUnionArray : UnionArray | ||
{ | ||
public ArrowBuffer ValueOffsetBuffer => Data.Buffers[1]; | ||
|
||
public ReadOnlySpan<int> ValueOffsets => ValueOffsetBuffer.Span.CastTo<int>(); | ||
|
||
public DenseUnionArray( | ||
IArrowType dataType, | ||
int length, | ||
IEnumerable<IArrowArray> children, | ||
ArrowBuffer typeIds, | ||
ArrowBuffer valuesOffsetBuffer, | ||
int nullCount = 0, | ||
int offset = 0) | ||
: base(new ArrayData( | ||
dataType, length, nullCount, offset, new[] { typeIds, valuesOffsetBuffer }, | ||
children.Select(child => child.Data))) | ||
{ | ||
_fields = children.ToArray(); | ||
ValidateMode(UnionMode.Dense, Type.Mode); | ||
} | ||
|
||
public DenseUnionArray(ArrayData data) | ||
: base(data) | ||
{ | ||
ValidateMode(UnionMode.Dense, Type.Mode); | ||
data.EnsureBufferCount(2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// 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 Apache.Arrow.Types; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Apache.Arrow | ||
{ | ||
public class SparseUnionArray : UnionArray | ||
{ | ||
public SparseUnionArray( | ||
IArrowType dataType, | ||
int length, | ||
IEnumerable<IArrowArray> children, | ||
ArrowBuffer typeIds, | ||
int nullCount = 0, | ||
int offset = 0) | ||
: base(new ArrayData( | ||
dataType, length, nullCount, offset, new[] { typeIds }, | ||
children.Select(child => child.Data))) | ||
{ | ||
_fields = children.ToArray(); | ||
ValidateMode(UnionMode.Sparse, Type.Mode); | ||
} | ||
|
||
public SparseUnionArray(ArrayData data) | ||
: base(data) | ||
{ | ||
ValidateMode(UnionMode.Sparse, Type.Mode); | ||
data.EnsureBufferCount(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.