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

Method TestCreate

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

Source from the content-addressed store, hash-verified

3375
3376 template <size_t BYTE_WIDTH = 16>
3377 std::shared_ptr<Array> TestCreate(int32_t precision, const DecimalVector& draw,
3378 const std::vector<uint8_t>& valid_bytes,
3379 int64_t offset) const {
3380 auto type = std::make_shared<TYPE>(precision, 4);
3381 auto builder = std::make_shared<DecimalBuilder>(type);
3382
3383 const size_t size = draw.size();
3384
3385 ARROW_EXPECT_OK(builder->Reserve(size));
3386
3387 for (size_t i = 0; i < size; ++i) {
3388 if (valid_bytes[i]) {
3389 ARROW_EXPECT_OK(builder->Append(draw[i]));
3390 } else {
3391 ARROW_EXPECT_OK(builder->AppendNull());
3392 }
3393 }
3394
3395 std::shared_ptr<Array> out;
3396 FinishAndCheckPadding(builder.get(), &out);
3397 EXPECT_EQ(builder->length(), 0);
3398
3399 std::vector<uint8_t> raw_bytes;
3400
3401 raw_bytes.reserve(size * BYTE_WIDTH);
3402 MakeData<BYTE_WIDTH>(draw, &raw_bytes);
3403
3404 auto expected_data = std::make_shared<Buffer>(raw_bytes.data(), BYTE_WIDTH);
3405 std::shared_ptr<Buffer> expected_null_bitmap;
3406 EXPECT_OK_AND_ASSIGN(expected_null_bitmap, internal::BytesToBits(valid_bytes));
3407
3408 int64_t expected_null_count = CountNulls(valid_bytes);
3409 auto expected = std::make_shared<DecimalArray>(
3410 type, size, expected_data, expected_null_bitmap, expected_null_count);
3411
3412 std::shared_ptr<Array> lhs = out->Slice(offset);
3413 std::shared_ptr<Array> rhs = expected->Slice(offset);
3414 ASSERT_ARRAYS_EQUAL(*rhs, *lhs);
3415
3416 return out;
3417 }
3418};
3419
3420using Decimal32Test = DecimalTest<Decimal32Type>;

Callers 1

TEST_PFunction · 0.80

Calls 13

FinishAndCheckPaddingFunction · 0.85
BytesToBitsFunction · 0.85
CountNullsFunction · 0.85
EXPECT_OK_AND_ASSIGNFunction · 0.50
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