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

Method TestCreate

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

Source from the content-addressed store, hash-verified

3298
3299 template <size_t BYTE_WIDTH = 16>
3300 std::shared_ptr<Array> TestCreate(int32_t precision, const DecimalVector& draw,
3301 const std::vector<uint8_t>& valid_bytes,
3302 int64_t offset) const {
3303 auto type = std::make_shared<TYPE>(precision, 4);
3304 auto builder = std::make_shared<DecimalBuilder>(type);
3305
3306 const size_t size = draw.size();
3307
3308 ARROW_EXPECT_OK(builder->Reserve(size));
3309
3310 for (size_t i = 0; i < size; ++i) {
3311 if (valid_bytes[i]) {
3312 ARROW_EXPECT_OK(builder->Append(draw[i]));
3313 } else {
3314 ARROW_EXPECT_OK(builder->AppendNull());
3315 }
3316 }
3317
3318 std::shared_ptr<Array> out;
3319 FinishAndCheckPadding(builder.get(), &out);
3320 EXPECT_EQ(builder->length(), 0);
3321
3322 std::vector<uint8_t> raw_bytes;
3323
3324 raw_bytes.reserve(size * BYTE_WIDTH);
3325 MakeData<BYTE_WIDTH>(draw, &raw_bytes);
3326
3327 auto expected_data = std::make_shared<Buffer>(raw_bytes.data(), BYTE_WIDTH);
3328 std::shared_ptr<Buffer> expected_null_bitmap;
3329 EXPECT_OK_AND_ASSIGN(expected_null_bitmap, internal::BytesToBits(valid_bytes));
3330
3331 int64_t expected_null_count = CountNulls(valid_bytes);
3332 auto expected = std::make_shared<DecimalArray>(
3333 type, size, expected_data, expected_null_bitmap, expected_null_count);
3334
3335 std::shared_ptr<Array> lhs = out->Slice(offset);
3336 std::shared_ptr<Array> rhs = expected->Slice(offset);
3337 ASSERT_ARRAYS_EQUAL(*rhs, *lhs);
3338
3339 return out;
3340 }
3341};
3342
3343using 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