MCPcopy Create free account
hub / github.com/apache/orc / TestMultipleSeeksWithPredicates

Function TestMultipleSeeksWithPredicates

c++/test/TestPredicatePushdown.cc:261–308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259 }
260
261 void TestMultipleSeeksWithPredicates(Reader* reader) {
262 // Build search argument (x >= 300000 AND x < 600000) for column 'int1'. Only the 2nd
263 // row group will be selected.
264 std::unique_ptr<SearchArgument> sarg =
265 SearchArgumentFactory::newBuilder()
266 ->startAnd()
267 .startNot()
268 .lessThan("int1", PredicateDataType::LONG, Literal(static_cast<int64_t>(300000L)))
269 .end()
270 .lessThan("int1", PredicateDataType::LONG, Literal(static_cast<int64_t>(600000L)))
271 .end()
272 .build();
273 RowReaderOptions rowReaderOpts;
274 rowReaderOpts.searchArgument(std::move(sarg));
275 auto rowReader = reader->createRowReader(rowReaderOpts);
276
277 // Read only one row after each seek
278 auto readBatch = rowReader->createRowBatch(1);
279 auto& batch0 = dynamic_cast<StructVectorBatch&>(*readBatch);
280 auto& batch1 = dynamic_cast<LongVectorBatch&>(*batch0.fields[0]);
281 auto& batch2 = dynamic_cast<StringVectorBatch&>(*batch0.fields[1]);
282
283 // Seek within the 1st row group will go to the start of the 2nd row group
284 rowReader->seekToRow(10);
285 EXPECT_TRUE(rowReader->next(*readBatch));
286 EXPECT_EQ(1000, rowReader->getRowNumber()) << "Should start at the 2nd row group";
287 EXPECT_EQ(1, readBatch->numElements);
288 EXPECT_EQ(300000, batch1.data[0]);
289 EXPECT_EQ("10000", std::string(batch2.data[0], static_cast<size_t>(batch2.length[0])));
290
291 // Seek within the 2nd row group (1000 rows) which is selected by the search argument
292 uint64_t seekRowNum[] = {1001, 1010, 1100, 1500, 1999};
293 for (uint64_t pos : seekRowNum) {
294 rowReader->seekToRow(pos);
295 EXPECT_TRUE(rowReader->next(*readBatch));
296 EXPECT_EQ(pos, rowReader->getRowNumber());
297 EXPECT_EQ(1, readBatch->numElements);
298 EXPECT_EQ(300 * pos, batch1.data[0]);
299 EXPECT_EQ(std::to_string(10 * pos),
300 std::string(batch2.data[0], static_cast<size_t>(batch2.length[0])));
301 }
302
303 // Seek advance the 2nd row group will go to the end of file
304 rowReader->seekToRow(2000);
305 EXPECT_FALSE(rowReader->next(*readBatch));
306 EXPECT_EQ(3500, rowReader->getRowNumber());
307 EXPECT_EQ(0, readBatch->numElements);
308 }
309
310 TEST(TestPredicatePushdown, testPredicatePushdown) {
311 MemoryOutputStream memStream(DEFAULT_MEM_STREAM_SIZE);

Callers 1

TESTFunction · 0.85

Calls 10

LiteralClass · 0.85
searchArgumentMethod · 0.80
buildMethod · 0.65
endMethod · 0.65
seekToRowMethod · 0.65
nextMethod · 0.65
getRowNumberMethod · 0.65
to_stringFunction · 0.50
createRowReaderMethod · 0.45
createRowBatchMethod · 0.45

Tested by

no test coverage detected