]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/csharp/test/Apache.Arrow.Tests/TableTests.cs
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / csharp / test / Apache.Arrow.Tests / TableTests.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.Collections.Generic;
18using Apache.Arrow.Types;
19using Xunit;
20
21namespace Apache.Arrow.Tests
22{
23 public class TableTests
24 {
25 public static Table MakeTableWithOneColumnOfTwoIntArrays(int lengthOfEachArray)
26 {
27 Array intArray = ColumnTests.MakeIntArray(lengthOfEachArray);
28 Array intArrayCopy = ColumnTests.MakeIntArray(lengthOfEachArray);
29
30 Field field = new Field.Builder().Name("f0").DataType(Int32Type.Default).Build();
31 Schema s0 = new Schema.Builder().Field(field).Build();
32
33 Column column = new Column(field, new List<Array> { intArray, intArrayCopy });
34 Table table = new Table(s0, new List<Column> { column });
35 return table;
36 }
37
38 [Fact]
39 public void TestEmptyTable()
40 {
41 Table table = new Table();
42 Assert.Equal(0, table.ColumnCount);
43 Assert.Equal(0, table.RowCount);
44 }
45
46 [Fact]
47 public void TestTableBasics()
48 {
49 Table table = MakeTableWithOneColumnOfTwoIntArrays(10);
50 Assert.Equal(20, table.RowCount);
51 Assert.Equal(1, table.ColumnCount);
52 }
53
54 [Fact]
55 public void TestTableAddRemoveAndSetColumn()
56 {
57 Table table = MakeTableWithOneColumnOfTwoIntArrays(10);
58
59 Array nonEqualLengthIntArray = ColumnTests.MakeIntArray(10);
60 Field field1 = new Field.Builder().Name("f1").DataType(Int32Type.Default).Build();
61 Column nonEqualLengthColumn = new Column(field1, new[] { nonEqualLengthIntArray});
62 Assert.Throws<ArgumentException>(() => table.InsertColumn(-1, nonEqualLengthColumn));
63 Assert.Throws<ArgumentException>(() => table.InsertColumn(1, nonEqualLengthColumn));
64
65 Array equalLengthIntArray = ColumnTests.MakeIntArray(20);
66 Field field2 = new Field.Builder().Name("f2").DataType(Int32Type.Default).Build();
67 Column equalLengthColumn = new Column(field2, new[] { equalLengthIntArray});
68 Column existingColumn = table.Column(0);
69
70 Table newTable = table.InsertColumn(0, equalLengthColumn);
71 Assert.Equal(2, newTable.ColumnCount);
72 Assert.True(newTable.Column(0) == equalLengthColumn);
73 Assert.True(newTable.Column(1) == existingColumn);
74
75 newTable = newTable.RemoveColumn(1);
76 Assert.Equal(1, newTable.ColumnCount);
77 Assert.True(newTable.Column(0) == equalLengthColumn);
78
79 newTable = table.SetColumn(0, existingColumn);
80 Assert.True(newTable.Column(0) == existingColumn);
81 }
82 }
83}