MCPcopy Create free account
hub / github.com/apache/arrow / TestCreate

Method TestCreate

cpp/src/arrow/array/array_test.cc:3250–3290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3248
3249 template <size_t BYTE_WIDTH = 16>
3250 std::shared_ptr<Array> TestCreate(int32_t precision, const DecimalVector& draw,
3251 const std::vector<uint8_t>& valid_bytes,
3252 int64_t offset) const {
3253 auto type = std::make_shared<TYPE>(precision, 4);
3254 auto builder = std::make_shared<DecimalBuilder>(type);
3255
3256 const size_t size = draw.size();
3257
3258 ARROW_EXPECT_OK(builder->Reserve(size));
3259
3260 for (size_t i = 0; i < size; ++i) {
3261 if (valid_bytes[i]) {
3262 ARROW_EXPECT_OK(builder->Append(draw[i]));
3263 } else {
3264 ARROW_EXPECT_OK(builder->AppendNull());
3265 }
3266 }
3267
3268 std::shared_ptr<Array> out;
3269 FinishAndCheckPadding(builder.get(), &out);
3270 EXPECT_EQ(builder->length(), 0);
3271
3272 std::vector<uint8_t> raw_bytes;
3273
3274 raw_bytes.reserve(size * BYTE_WIDTH);
3275 MakeData<BYTE_WIDTH>(draw, &raw_bytes);
3276
3277 auto expected_data = std::make_shared<Buffer>(raw_bytes.data(), BYTE_WIDTH);
3278 std::shared_ptr<Buffer> expected_null_bitmap;
3279 EXPECT_OK_AND_ASSIGN(expected_null_bitmap, internal::BytesToBits(valid_bytes));
3280
3281 int64_t expected_null_count = CountNulls(valid_bytes);
3282 auto expected = std::make_shared<DecimalArray>(
3283 type, size, expected_data, expected_null_bitmap, expected_null_count);
3284
3285 std::shared_ptr<Array> lhs = out->Slice(offset);
3286 std::shared_ptr<Array> rhs = expected->Slice(offset);
3287 ASSERT_ARRAYS_EQUAL(*rhs, *lhs);
3288
3289 return out;
3290 }
3291};
3292
3293using Decimal32Test = DecimalTest<Decimal32Type>;

Callers 1

TEST_PFunction · 0.80

Calls 13

FinishAndCheckPaddingFunction · 0.85
EXPECT_OK_AND_ASSIGNFunction · 0.85
BytesToBitsFunction · 0.85
CountNullsFunction · 0.85
sizeMethod · 0.45
ReserveMethod · 0.45
AppendMethod · 0.45
AppendNullMethod · 0.45
getMethod · 0.45
lengthMethod · 0.45
reserveMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected