forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.h
More file actions
237 lines (214 loc) · 8.17 KB
/
Copy pathgenerator.h
File metadata and controls
237 lines (214 loc) · 8.17 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// 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.
#pragma once
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include "arrow/array/array_base.h"
#include "arrow/testing/gtest_util.h"
#include "arrow/testing/visibility.h"
#include "arrow/type_fwd.h"
namespace arrow {
class ARROW_TESTING_EXPORT ConstantArrayGenerator {
public:
/// \brief Generates a constant BooleanArray
///
/// \param[in] size the size of the array to generate
/// \param[in] value to repeat
///
/// \return a generated Array
static std::shared_ptr<Array> Boolean(int64_t size, bool value = false);
/// \brief Generates a constant UInt8Array
///
/// \param[in] size the size of the array to generate
/// \param[in] value to repeat
///
/// \return a generated Array
static std::shared_ptr<Array> UInt8(int64_t size, uint8_t value = 0);
/// \brief Generates a constant Int8Array
///
/// \param[in] size the size of the array to generate
/// \param[in] value to repeat
///
/// \return a generated Array
static std::shared_ptr<Array> Int8(int64_t size, int8_t value = 0);
/// \brief Generates a constant UInt16Array
///
/// \param[in] size the size of the array to generate
/// \param[in] value to repeat
///
/// \return a generated Array
static std::shared_ptr<Array> UInt16(int64_t size, uint16_t value = 0);
/// \brief Generates a constant UInt16Array
///
/// \param[in] size the size of the array to generate
/// \param[in] value to repeat
///
/// \return a generated Array
static std::shared_ptr<Array> Int16(int64_t size, int16_t value = 0);
/// \brief Generates a constant UInt32Array
///
/// \param[in] size the size of the array to generate
/// \param[in] value to repeat
///
/// \return a generated Array
static std::shared_ptr<Array> UInt32(int64_t size, uint32_t value = 0);
/// \brief Generates a constant UInt32Array
///
/// \param[in] size the size of the array to generate
/// \param[in] value to repeat
///
/// \return a generated Array
static std::shared_ptr<Array> Int32(int64_t size, int32_t value = 0);
/// \brief Generates a constant UInt64Array
///
/// \param[in] size the size of the array to generate
/// \param[in] value to repeat
///
/// \return a generated Array
static std::shared_ptr<Array> UInt64(int64_t size, uint64_t value = 0);
/// \brief Generates a constant UInt64Array
///
/// \param[in] size the size of the array to generate
/// \param[in] value to repeat
///
/// \return a generated Array
static std::shared_ptr<Array> Int64(int64_t size, int64_t value = 0);
/// \brief Generates a constant Float32Array
///
/// \param[in] size the size of the array to generate
/// \param[in] value to repeat
///
/// \return a generated Array
static std::shared_ptr<Array> Float32(int64_t size, float value = 0);
/// \brief Generates a constant Float64Array
///
/// \param[in] size the size of the array to generate
/// \param[in] value to repeat
///
/// \return a generated Array
static std::shared_ptr<Array> Float64(int64_t size, double value = 0);
/// \brief Generates a constant StringArray
///
/// \param[in] size the size of the array to generate
/// \param[in] value to repeat
///
/// \return a generated Array
static std::shared_ptr<Array> String(int64_t size, std::string value = "");
template <typename ArrowType, typename CType = typename ArrowType::c_type>
static std::shared_ptr<Array> Numeric(int64_t size, CType value = 0) {
switch (ArrowType::type_id) {
case Type::BOOL:
return Boolean(size, static_cast<bool>(value));
case Type::UINT8:
return UInt8(size, static_cast<uint8_t>(value));
case Type::INT8:
return Int8(size, static_cast<int8_t>(value));
case Type::UINT16:
return UInt16(size, static_cast<uint16_t>(value));
case Type::INT16:
return Int16(size, static_cast<int16_t>(value));
case Type::UINT32:
return UInt32(size, static_cast<uint32_t>(value));
case Type::INT32:
return Int32(size, static_cast<int32_t>(value));
case Type::UINT64:
return UInt64(size, static_cast<uint64_t>(value));
case Type::INT64:
return Int64(size, static_cast<int64_t>(value));
case Type::FLOAT:
return Float32(size, static_cast<float>(value));
case Type::DOUBLE:
return Float64(size, static_cast<double>(value));
case Type::INTERVAL_DAY_TIME:
case Type::DATE32: {
EXPECT_OK_AND_ASSIGN(auto viewed,
Int32(size, static_cast<uint32_t>(value))->View(date32()));
return viewed;
}
case Type::INTERVAL_MONTHS: {
EXPECT_OK_AND_ASSIGN(auto viewed,
Int32(size, static_cast<uint32_t>(value))
->View(std::make_shared<MonthIntervalType>()));
return viewed;
}
case Type::TIME32: {
EXPECT_OK_AND_ASSIGN(auto viewed,
Int32(size, static_cast<uint32_t>(value))
->View(std::make_shared<Time32Type>(TimeUnit::SECOND)));
return viewed;
}
case Type::TIME64: {
EXPECT_OK_AND_ASSIGN(auto viewed, Int64(size, static_cast<uint64_t>(value))
->View(std::make_shared<Time64Type>()));
return viewed;
}
case Type::DATE64: {
EXPECT_OK_AND_ASSIGN(auto viewed,
Int64(size, static_cast<uint64_t>(value))->View(date64()));
return viewed;
}
case Type::TIMESTAMP: {
EXPECT_OK_AND_ASSIGN(
auto viewed, Int64(size, static_cast<int64_t>(value))
->View(std::make_shared<TimestampType>(TimeUnit::SECOND)));
return viewed;
}
default:
return nullptr;
}
}
/// \brief Generates a constant Array of zeroes
///
/// \param[in] size the size of the array to generate
/// \param[in] type the type of the Array
///
/// \return a generated Array
static std::shared_ptr<Array> Zeroes(int64_t size,
const std::shared_ptr<DataType>& type);
/// \brief Generates a RecordBatch of zeroes
///
/// \param[in] size the size of the array to generate
/// \param[in] schema to conform to
///
/// This function is handy to return of RecordBatch of a desired shape.
///
/// \return a generated RecordBatch
static std::shared_ptr<RecordBatch> Zeroes(int64_t size,
const std::shared_ptr<Schema>& schema);
/// \brief Generates a RecordBatchReader by repeating a RecordBatch
///
/// \param[in] n_batch the number of times it repeats batch
/// \param[in] batch the RecordBatch to repeat
///
/// \return a generated RecordBatchReader
static std::shared_ptr<RecordBatchReader> Repeat(
int64_t n_batch, const std::shared_ptr<RecordBatch> batch);
/// \brief Generates a RecordBatchReader of zeroes batches
///
/// \param[in] n_batch the number of RecordBatch
/// \param[in] batch_size the size of each RecordBatch
/// \param[in] schema to conform to
///
/// \return a generated RecordBatchReader
static std::shared_ptr<RecordBatchReader> Zeroes(int64_t n_batch, int64_t batch_size,
const std::shared_ptr<Schema>& schema);
};
ARROW_TESTING_EXPORT
Result<std::shared_ptr<Array>> ScalarVectorToArray(const ScalarVector& scalars);
} // namespace arrow