]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/csharp/test/Apache.Arrow.Tests/DictionaryArrayTests.cs
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / csharp / test / Apache.Arrow.Tests / DictionaryArrayTests.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 Apache.Arrow.Types;
18using Xunit;
19
20namespace Apache.Arrow.Tests
21{
22 public class DictionaryArrayTests
23 {
24 [Fact]
25 public void CreateTest()
26 {
27 (StringArray originalDictionary, Int32Array originalIndicesArray, DictionaryArray dictionaryArray) =
28 CreateSimpleTestData();
29
30 Assert.Equal(dictionaryArray.Dictionary, originalDictionary);
31 Assert.Equal(dictionaryArray.Indices, originalIndicesArray);
32 }
33
34 [Fact]
35 public void SliceTest()
36 {
37 (StringArray originalDictionary, Int32Array originalIndicesArray, DictionaryArray dictionaryArray) =
38 CreateSimpleTestData();
39
40 int batchLength = originalIndicesArray.Length;
41 for (int offset = 0; offset < batchLength; offset++)
42 {
43 for (int length = 1; offset + length <= batchLength; length++)
44 {
45 var sliced = dictionaryArray.Slice(offset, length) as DictionaryArray;
46 var actualSlicedDictionary = sliced.Dictionary as StringArray;
47 var actualSlicedIndicesArray = sliced.Indices as Int32Array;
48
49 var expectedSlicedIndicesArray = originalIndicesArray.Slice(offset, length) as Int32Array;
50
51 //Dictionary is not sliced.
52 Assert.Equal(originalDictionary.Data, actualSlicedDictionary.Data);
53 Assert.Equal(expectedSlicedIndicesArray.ToList(), actualSlicedIndicesArray.ToList());
54 }
55 }
56 }
57
58 private Tuple<StringArray, Int32Array, DictionaryArray> CreateSimpleTestData()
59 {
60 StringArray originalDictionary = new StringArray.Builder().AppendRange(new[] { "a", "b", "c" }).Build();
61 Int32Array originalIndicesArray = new Int32Array.Builder().AppendRange(new[] { 0, 0, 1, 1, 2, 2 }).Build();
62 var dictionaryArray = new DictionaryArray(new DictionaryType(Int32Type.Default, StringType.Default, false), originalIndicesArray, originalDictionary);
63
64 return Tuple.Create(originalDictionary, originalIndicesArray, dictionaryArray);
65 }
66 }
67}