forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray-test.cc
More file actions
117 lines (95 loc) · 3.87 KB
/
Copy patharray-test.cc
File metadata and controls
117 lines (95 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// 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.
#include <cstdint>
#include <cstdlib>
#include <memory>
#include <vector>
#include "gtest/gtest.h"
#include "arrow/array.h"
#include "arrow/test-util.h"
#include "arrow/type.h"
#include "arrow/types/primitive.h"
#include "arrow/util/buffer.h"
#include "arrow/util/memory-pool.h"
namespace arrow {
class TestArray : public ::testing::Test {
public:
void SetUp() { pool_ = default_memory_pool(); }
protected:
MemoryPool* pool_;
};
TEST_F(TestArray, TestNullCount) {
auto data = std::make_shared<PoolBuffer>(pool_);
auto null_bitmap = std::make_shared<PoolBuffer>(pool_);
std::unique_ptr<Int32Array> arr(new Int32Array(100, data, 10, null_bitmap));
ASSERT_EQ(10, arr->null_count());
std::unique_ptr<Int32Array> arr_no_nulls(new Int32Array(100, data));
ASSERT_EQ(0, arr_no_nulls->null_count());
}
TEST_F(TestArray, TestLength) {
auto data = std::make_shared<PoolBuffer>(pool_);
std::unique_ptr<Int32Array> arr(new Int32Array(100, data));
ASSERT_EQ(arr->length(), 100);
}
ArrayPtr MakeArrayFromValidBytes(const std::vector<uint8_t>& v, MemoryPool* pool) {
int32_t null_count = v.size() - std::accumulate(v.begin(), v.end(), 0);
std::shared_ptr<Buffer> null_buf = test::bytes_to_null_buffer(v);
BufferBuilder value_builder(pool);
for (size_t i = 0; i < v.size(); ++i) {
value_builder.Append<int32_t>(0);
}
ArrayPtr arr(new Int32Array(v.size(), value_builder.Finish(), null_count, null_buf));
return arr;
}
TEST_F(TestArray, TestEquality) {
auto array = MakeArrayFromValidBytes({1, 0, 1, 1, 0, 1, 0, 0}, pool_);
auto equal_array = MakeArrayFromValidBytes({1, 0, 1, 1, 0, 1, 0, 0}, pool_);
auto unequal_array = MakeArrayFromValidBytes({1, 1, 1, 1, 0, 1, 0, 0}, pool_);
EXPECT_TRUE(array->Equals(array));
EXPECT_TRUE(array->Equals(equal_array));
EXPECT_TRUE(equal_array->Equals(array));
EXPECT_FALSE(equal_array->Equals(unequal_array));
EXPECT_FALSE(unequal_array->Equals(equal_array));
EXPECT_TRUE(array->RangeEquals(4, 8, 4, unequal_array));
EXPECT_FALSE(array->RangeEquals(0, 4, 0, unequal_array));
EXPECT_FALSE(array->RangeEquals(0, 8, 0, unequal_array));
EXPECT_FALSE(array->RangeEquals(1, 2, 1, unequal_array));
}
TEST_F(TestArray, TestIsNull) {
// clang-format off
std::vector<uint8_t> null_bitmap = {1, 0, 1, 1, 0, 1, 0, 0,
1, 0, 1, 1, 0, 1, 0, 0,
1, 0, 1, 1, 0, 1, 0, 0,
1, 0, 1, 1, 0, 1, 0, 0,
1, 0, 0, 1};
// clang-format on
int32_t null_count = 0;
for (uint8_t x : null_bitmap) {
if (x == 0) { ++null_count; }
}
std::shared_ptr<Buffer> null_buf = test::bytes_to_null_buffer(null_bitmap);
std::unique_ptr<Array> arr;
arr.reset(new Int32Array(null_bitmap.size(), nullptr, null_count, null_buf));
ASSERT_EQ(null_count, arr->null_count());
ASSERT_EQ(5, null_buf->size());
ASSERT_TRUE(arr->null_bitmap()->Equals(*null_buf.get()));
for (size_t i = 0; i < null_bitmap.size(); ++i) {
EXPECT_EQ(null_bitmap[i], !arr->IsNull(i)) << i;
}
}
TEST_F(TestArray, TestCopy) {}
} // namespace arrow