]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/csharp/src/Apache.Arrow/Arrays/DictionaryArray.cs
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / csharp / src / Apache.Arrow / Arrays / DictionaryArray.cs
CommitLineData
1d09f67e
TL
1// Licensed to the Apache Software Foundation (ASF) under one or more
2// contributor license agreements. See the NOTICE file distributed with
3// this work for additional information regarding copyright ownership.
4// The ASF licenses this file to You under the Apache License, Version 2.0
5// (the "License"); you may not use this file except in compliance with
6// the License. You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16using System;
17using System.IO;
18using Apache.Arrow.Types;
19
20namespace Apache.Arrow
21{
22 public class DictionaryArray : Array
23 {
24 public IArrowArray Dictionary { get; }
25 public IArrowArray Indices { get; }
26 public ArrowBuffer IndicesBuffer => Data.Buffers[1];
27
28 public DictionaryArray(ArrayData data) : base(data)
29 {
30 data.EnsureBufferCount(2);
31 data.EnsureDataType(ArrowTypeId.Dictionary);
32
33 if (data.Dictionary == null)
34 {
35 throw new ArgumentException($"{nameof(data.Dictionary)} must not be null");
36 }
37
38 var dicType = (DictionaryType)data.DataType;
39 data.Dictionary.EnsureDataType(dicType.ValueType.TypeId);
40
41 var indicesData = new ArrayData(dicType.IndexType, data.Length, data.NullCount, data.Offset, data.Buffers, data.Children);
42
43 Indices = ArrowArrayFactory.BuildArray(indicesData);
44 Dictionary = ArrowArrayFactory.BuildArray(data.Dictionary);
45 }
46
47 public DictionaryArray(DictionaryType dataType, IArrowArray indicesArray, IArrowArray dictionary) :
48 base(new ArrayData(dataType, indicesArray.Length, indicesArray.Data.NullCount, indicesArray.Data.Offset, indicesArray.Data.Buffers, indicesArray.Data.Children, dictionary.Data))
49 {
50 Data.EnsureBufferCount(2);
51
52 indicesArray.Data.EnsureDataType(dataType.IndexType.TypeId);
53 dictionary.Data.EnsureDataType(dataType.ValueType.TypeId);
54
55 Indices = indicesArray;
56 Dictionary = dictionary;
57 }
58
59 public override void Accept(IArrowArrayVisitor visitor) => Accept(this, visitor);
60 }
61}