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

Method testSerialization

bolt/vector/tests/VectorTest.cpp:829–930  ·  view source on GitHub ↗

Serialize odd and even rows into separate streams. Read serialized data back and compare with the original data.

Source from the content-addressed store, hash-verified

827 /// Serialize odd and even rows into separate streams. Read serialized data
828 /// back and compare with the original data.
829 void testSerialization(VectorPtr source) {
830 // Serialization functions expect loaded vectors.
831 source = BaseVector::loadedVectorShared(source);
832 auto sourceRow = makeRowVector({"c"}, {source});
833 auto sourceRowType = asRowType(sourceRow->type());
834
835 VectorStreamGroup even(pool());
836 even.createStreamTree(sourceRowType, source->size() / 4);
837
838 VectorStreamGroup odd(pool());
839 odd.createStreamTree(sourceRowType, source->size() / 3);
840
841 std::vector<IndexRange> evenIndices;
842 std::vector<IndexRange> oddIndices;
843 for (vector_size_t i = 0; i < source->size(); ++i) {
844 if (i % 2 == 0) {
845 evenIndices.push_back(IndexRange{i, 1});
846 } else {
847 oddIndices.push_back(IndexRange{i, 1});
848 }
849 }
850
851 std::vector<vector_size_t> evenSizes(evenIndices.size());
852 std::vector<vector_size_t*> evenSizePointers(evenSizes.size());
853 for (int32_t i = 0; i < evenSizes.size(); ++i) {
854 evenSizePointers[i] = &evenSizes[i];
855 }
856
857 std::vector<vector_size_t> oddSizes(oddIndices.size());
858 std::vector<vector_size_t*> oddSizePointers(oddSizes.size());
859 for (int32_t i = 0; i < oddSizes.size(); ++i) {
860 oddSizePointers[i] = &oddSizes[i];
861 }
862
863 VectorStreamGroup::estimateSerializedSize(
864 source, evenIndices, evenSizePointers.data());
865 VectorStreamGroup::estimateSerializedSize(
866 source, oddIndices, oddSizePointers.data());
867 even.append(
868 sourceRow, folly::Range(evenIndices.data(), evenIndices.size() / 2));
869 even.append(
870 sourceRow,
871 folly::Range(
872 &evenIndices[evenIndices.size() / 2],
873 evenIndices.size() - evenIndices.size() / 2));
874 odd.append(
875 sourceRow, folly::Range(oddIndices.data(), oddIndices.size() / 2));
876 odd.append(
877 sourceRow,
878 folly::Range(
879 &oddIndices[oddIndices.size() / 2],
880 oddIndices.size() - oddIndices.size() / 2));
881
882 std::stringstream evenStream;
883 std::stringstream oddStream;
884 OStreamOutputStream evenOutputStream(&evenStream);
885 OStreamOutputStream oddOutputStream(&oddStream);
886 even.flush(&evenOutputStream);

Callers

nothing calls this directly

Calls 15

asRowTypeFunction · 0.85
createStreamTreeMethod · 0.80
strMethod · 0.80
childAtMethod · 0.80
equalValueAtMethod · 0.80
poolFunction · 0.50
RangeClass · 0.50
readFunction · 0.50
typeMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected