| 13 | } |
| 14 | |
| 15 | TEST(ArrowQueryResultTest, exportsCSRMetadataAsZeroCopyArrowArrays) { |
| 16 | ArrowQueryResult::CSRMetadata metadata; |
| 17 | metadata.indptr = {0, 2, 3}; |
| 18 | metadata.indices = {4, 5, 6}; |
| 19 | metadata.edgeIDs = {10, 11, 12}; |
| 20 | metadata.hasEdgeIDs = true; |
| 21 | std::vector<ArrowQueryResult::CSRMetadata> csrChunks; |
| 22 | csrChunks.push_back(std::move(metadata)); |
| 23 | |
| 24 | ArrowQueryResult result{{}, 8, std::move(csrChunks)}; |
| 25 | const auto& storedMetadata = result.getCSRMetadata(); |
| 26 | auto csrArrays = result.getCSRArrowArrays(); |
| 27 | |
| 28 | ASSERT_STREQ(csrArrays.indptr.schema.format, "l"); |
| 29 | ASSERT_STREQ(csrArrays.indices.schema.format, "l"); |
| 30 | ASSERT_TRUE(csrArrays.edgeIDs.has_value()); |
| 31 | ASSERT_STREQ(csrArrays.edgeIDs->schema.format, "l"); |
| 32 | ASSERT_EQ(csrArrays.indptr.array.length, static_cast<int64_t>(storedMetadata.indptr.size())); |
| 33 | ASSERT_EQ(csrArrays.indices.array.length, static_cast<int64_t>(storedMetadata.indices.size())); |
| 34 | ASSERT_EQ(csrArrays.edgeIDs->array.length, static_cast<int64_t>(storedMetadata.edgeIDs.size())); |
| 35 | // No validity bitmap (the array is non-nullable). |
| 36 | ASSERT_EQ(csrArrays.indptr.array.buffers[0], nullptr); |
| 37 | ASSERT_EQ(csrArrays.indices.array.buffers[0], nullptr); |
| 38 | ASSERT_EQ(csrArrays.edgeIDs->array.buffers[0], nullptr); |
| 39 | // Value-equivalence: the exported Arrow data buffers hold the merged |
| 40 | // CSR values. We check the contents rather than the backing pointer, |
| 41 | // so the test does not break if the merge path changes whether it moves |
| 42 | // or copies the per-batch vectors. |
| 43 | const auto* indptrData = static_cast<const int64_t*>(csrArrays.indptr.array.buffers[1]); |
| 44 | const auto* indicesData = static_cast<const int64_t*>(csrArrays.indices.array.buffers[1]); |
| 45 | const auto* edgeIDsData = static_cast<const int64_t*>(csrArrays.edgeIDs->array.buffers[1]); |
| 46 | ASSERT_NE(indptrData, nullptr); |
| 47 | ASSERT_NE(indicesData, nullptr); |
| 48 | ASSERT_NE(edgeIDsData, nullptr); |
| 49 | ASSERT_EQ(std::vector<int64_t>(indptrData, indptrData + storedMetadata.indptr.size()), |
| 50 | (std::vector<int64_t>{0, 2, 3})); |
| 51 | ASSERT_EQ(std::vector<int64_t>(indicesData, indicesData + storedMetadata.indices.size()), |
| 52 | (std::vector<int64_t>{4, 5, 6})); |
| 53 | ASSERT_EQ(std::vector<int64_t>(edgeIDsData, edgeIDsData + storedMetadata.edgeIDs.size()), |
| 54 | (std::vector<int64_t>{10, 11, 12})); |
| 55 | } |
| 56 | |
| 57 | TEST_F(ArrowTest, resultToArrow) { |
| 58 | auto query = "MATCH (a:person) WHERE a.fName = 'Bob' RETURN a.fName"; |
nothing calls this directly
no test coverage detected