MCPcopy Create free account
hub / github.com/bytedance/bolt / testCopyEncoded

Method testCopyEncoded

bolt/vector/tests/VectorTest.cpp:379–486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

377 }
378
379 void testCopyEncoded(VectorPtr source) {
380 bool maybeConstant = false;
381 auto sourcePtr = source.get();
382 for (;;) {
383 auto encoding = sourcePtr->encoding();
384 maybeConstant = encoding == VectorEncoding::Simple::CONSTANT ||
385 encoding == VectorEncoding::Simple::LAZY;
386 if (maybeConstant) {
387 break;
388 }
389 if (encoding != VectorEncoding::Simple::DICTIONARY) {
390 break;
391 }
392 sourcePtr = sourcePtr->valueVector().get();
393 }
394
395 auto kind = source->typeKind();
396 auto isSmall = kind == TypeKind::BOOLEAN || kind == TypeKind::TINYINT;
397 auto sourceSize = source->size();
398 auto target = BaseVector::create(source->type(), sourceSize, pool());
399 // Writes target out of sequence by copying the first half of
400 // source to odd positions and the second half to even positions.
401 auto even = selectEven(sourceSize);
402 auto odd = selectOdd(sourceSize);
403 std::vector<vector_size_t> evenSource(sourceSize, INT32_MAX);
404 std::vector<vector_size_t> oddSource(sourceSize, INT32_MAX);
405
406 for (auto i = 0; i < sourceSize; ++i) {
407 if (i % 2 == 0) {
408 evenSource[i] = i / 2;
409 } else {
410 oddSource[i] = (sourceSize / 2) + (i / 2);
411 }
412 }
413 target->copy(source.get(), even, &evenSource[0], false);
414 target->copy(source.get(), odd, &oddSource[0], false);
415 // We check that a wrapped source tests the same via equalValueAt
416 // on the wrapping and via the translation of DecodedVector.
417 SelectivityVector allRows(sourceSize);
418 DecodedVector decoded(*source, allRows);
419 auto base = decoded.base();
420 auto nulls = decoded.nulls(&allRows);
421 auto indices = decoded.indices();
422 for (int32_t i = 0; i < sourceSize; ++i) {
423 if (i % 2 == 0) {
424 auto sourceIdx = evenSource[i];
425 EXPECT_TRUE(target->equalValueAt(source.get(), i, sourceIdx))
426 << "at " << i << ": " << target->toString(i) << " vs. "
427 << source->toString(sourceIdx);
428
429 // We check the same with 'decoded'.
430 if (source->isNullAt(sourceIdx)) {
431 EXPECT_TRUE(decoded.isNullAt(sourceIdx));
432 EXPECT_TRUE(nulls && bits::isBitNull(nulls, sourceIdx));
433 EXPECT_TRUE(target->isNullAt(i));
434 } else {
435 EXPECT_FALSE(nulls && bits::isBitNull(nulls, sourceIdx));
436 EXPECT_FALSE(decoded.isNullAt(sourceIdx));

Callers

nothing calls this directly

Calls 15

isBitNullFunction · 0.85
indicesMethod · 0.80
equalValueAtMethod · 0.80
createFunction · 0.50
poolFunction · 0.50
getMethod · 0.45
encodingMethod · 0.45
typeKindMethod · 0.45
sizeMethod · 0.45
typeMethod · 0.45
copyMethod · 0.45
baseMethod · 0.45

Tested by

no test coverage detected