4747#include " runtime/runtime_profile.h"
4848#include " runtime/runtime_state.h"
4949#include " testutil/desc_tbl_builder.h"
50+ #include " util/debug_points.h"
5051namespace doris {
5152class OrcReaderTest : public testing ::Test {
5253public:
@@ -442,73 +443,47 @@ TEST_F(OrcReaderTest, deletion_vector_filters_rows_without_query_conjuncts) {
442443
443444namespace {
444445
445- // Fail only after the ORC footer and row reader have been initialized. This makes the
446- // exception originate from seekToRow's actual I/O, rather than from opening the file.
447- class RowIdSeekInputStream : public orc ::InputStream {
448- public:
449- explicit RowIdSeekInputStream (io::IOContext* io_ctx)
450- : _input(orc::readLocalFile(" ./be/test/exec/test_data/orc_scanner/orders.orc" )),
451- _io_ctx(io_ctx) {}
452-
453- uint64_t getLength () const override { return _input->getLength (); }
454- uint64_t getNaturalReadSize () const override { return _input->getNaturalReadSize (); }
455- const std::string& getName () const override { return _input->getName (); }
456-
457- void read (void * buf, uint64_t length, uint64_t offset) override {
458- if (_failure) {
459- ++failed_reads;
460- _failure ();
461- }
462- _input->read (buf, length, offset);
463- }
464-
465- void fail_reads (std::string message, bool cancel_on_read = false ) {
466- _failure = [this , message = std::move (message), cancel_on_read] {
467- if (cancel_on_read) {
468- _io_ctx->should_stop = true ;
469- }
470- throw orc::ParseError (message);
471- };
472- }
473-
474- void fail_with_doris_exception () {
475- _failure = [] { throw Exception (ErrorCode::MEM_ALLOC_FAILED , " injected memory limit" ); };
476- }
477-
478- size_t failed_reads = 0 ;
479-
480- private:
481- std::unique_ptr<orc::InputStream> _input;
482- io::IOContext* _io_ctx;
483- std::function<void ()> _failure;
484- };
485-
486446class OrcRowIdSeekTest : public testing ::TestWithParam<bool > {
487447protected:
488448 void SetUp () override {
449+ debug_points_enabled = config::enable_debug_points;
489450 range.path = " ./be/test/exec/test_data/orc_scanner/orders.orc" ;
490451 reader = std::make_unique<OrcReader>(&profile, nullptr , params, range, 1 , " UTC" , &io_ctx,
491452 nullptr , GetParam ());
492- auto stream = std::make_unique<RowIdSeekInputStream>(&io_ctx);
493- input = stream.get ();
494- reader->_reader = orc::createReader (std::move (stream), orc::ReaderOptions ());
453+ reader->_reader = orc::createReader (orc::readLocalFile (range.path ), orc::ReaderOptions ());
495454 reader->_row_reader = reader->_reader ->createRowReader (orc::RowReaderOptions ());
455+ reader->_batch = reader->_row_reader ->createRowBatch (1 );
496456 reader->_read_by_rows = true ;
497457 reader->_row_ids = {1 , 2 };
498458 reader->_lazy_read_ctx .can_lazy_read = GetParam ();
499459 }
500460
461+ void TearDown () override {
462+ DebugPoints::instance ()->remove (" OrcReader::rowid_seek.inject_error" );
463+ config::enable_debug_points = debug_points_enabled;
464+ }
465+
466+ void fail_seek (std::function<void ()> failure) {
467+ config::enable_debug_points = true ;
468+ DebugPoints::instance ()->add_with_callback (" OrcReader::rowid_seek.inject_error" ,
469+ std::function<void ()>([this , failure] {
470+ ++failed_seeks;
471+ failure ();
472+ }));
473+ }
474+
501475 TFileScanRangeParams params;
502476 TFileRangeDesc range;
503477 io::IOContext io_ctx;
504478 RuntimeProfile profile {" OrcRowIdSeekTest" };
505- RowIdSeekInputStream* input = nullptr ;
479+ bool debug_points_enabled = false ;
480+ size_t failed_seeks = 0 ;
506481 std::unique_ptr<OrcReader> reader;
507482};
508483
509484TEST_P (OrcRowIdSeekTest, SeekIoFailureReturnsError) {
510485 const std::string message = " [NOT_FOUND] missing ORC file" ;
511- input-> fail_reads ( message);
486+ fail_seek ([ message] { throw orc::ParseError (message); } );
512487 Block block;
513488 size_t read_rows = 0 ;
514489 bool eof = false ;
@@ -520,11 +495,14 @@ TEST_P(OrcRowIdSeekTest, SeekIoFailureReturnsError) {
520495 EXPECT_NE (status.to_string ().find (message), std::string::npos);
521496 EXPECT_FALSE (eof);
522497 EXPECT_EQ (reader->_row_ids , (std::list<int64_t > {1 , 2 }));
523- EXPECT_EQ (input-> failed_reads , 1 );
498+ EXPECT_EQ (failed_seeks , 1 );
524499}
525500
526501TEST_P (OrcRowIdSeekTest, CancellationDuringSeekReturnsEof) {
527- input->fail_reads (" stop" , true );
502+ fail_seek ([this ] {
503+ io_ctx.should_stop = true ;
504+ throw orc::ParseError (" stop" );
505+ });
528506 Block block;
529507 size_t read_rows = 99 ;
530508 bool eof = false ;
@@ -534,11 +512,11 @@ TEST_P(OrcRowIdSeekTest, CancellationDuringSeekReturnsEof) {
534512 EXPECT_TRUE (io_ctx.should_stop );
535513 EXPECT_TRUE (eof);
536514 EXPECT_EQ (read_rows, 0 );
537- EXPECT_EQ (input-> failed_reads , 1 );
515+ EXPECT_EQ (failed_seeks , 1 );
538516}
539517
540518TEST_P (OrcRowIdSeekTest, DorisExceptionsKeepTheirErrorCode) {
541- input-> fail_with_doris_exception ( );
519+ fail_seek ([] { throw Exception (ErrorCode:: MEM_ALLOC_FAILED , " injected memory limit " ); } );
542520 Block block;
543521 size_t read_rows = 0 ;
544522 bool eof = false ;
@@ -548,42 +526,45 @@ TEST_P(OrcRowIdSeekTest, DorisExceptionsKeepTheirErrorCode) {
548526 } catch (const Exception& e) {
549527 EXPECT_EQ (e.code (), ErrorCode::MEM_ALLOC_FAILED );
550528 }
551- EXPECT_EQ (input-> failed_reads , 1 );
529+ EXPECT_EQ (failed_seeks , 1 );
552530}
553531
554532TEST_P (OrcRowIdSeekTest, StopWithoutCancellationReturnsError) {
555- input-> fail_reads ( " stop" );
533+ fail_seek ([] { throw orc::ParseError ( " stop" ); } );
556534 Block block;
557535 size_t read_rows = 0 ;
558536 bool eof = false ;
559537 const auto status = reader->get_next_block (&block, &read_rows, &eof);
560538 EXPECT_FALSE (status.ok ());
561539 EXPECT_FALSE (eof);
562- EXPECT_EQ (input-> failed_reads , 1 );
540+ EXPECT_EQ (failed_seeks , 1 );
563541}
564542
565543TEST_P (OrcRowIdSeekTest, CancellationDoesNotHideAnIoFailure) {
566- input->fail_reads (" ORC read I/O failure" , true );
544+ fail_seek ([this ] {
545+ io_ctx.should_stop = true ;
546+ throw orc::ParseError (" ORC read I/O failure" );
547+ });
567548 Block block;
568549 size_t read_rows = 0 ;
569550 bool eof = false ;
570551 const auto status = reader->get_next_block (&block, &read_rows, &eof);
571552 EXPECT_FALSE (status.ok ());
572553 EXPECT_FALSE (eof);
573- EXPECT_EQ (input-> failed_reads , 1 );
554+ EXPECT_EQ (failed_seeks , 1 );
574555}
575556
576557TEST_P (OrcRowIdSeekTest, EmptyRowIdsReturnZeroRowsAndEof) {
577558 reader->_row_ids .clear ();
578- input-> fail_reads ( " must not read " );
559+ fail_seek ([] { throw orc::ParseError ( " must not seek " ); } );
579560 Block block;
580561 size_t read_rows = 99 ;
581562 bool eof = false ;
582563 const auto status = reader->get_next_block (&block, &read_rows, &eof);
583564 EXPECT_TRUE (status.ok ()) << status;
584565 EXPECT_TRUE (eof);
585566 EXPECT_EQ (read_rows, 0 );
586- EXPECT_EQ (input-> failed_reads , 0 );
567+ EXPECT_EQ (failed_seeks , 0 );
587568}
588569
589570TEST_P (OrcRowIdSeekTest, NormalSeekConsumesOnlyTheRequestedRowId) {
@@ -596,15 +577,15 @@ TEST_P(OrcRowIdSeekTest, NormalSeekConsumesOnlyTheRequestedRowId) {
596577
597578TEST_P (OrcRowIdSeekTest, AlreadyCancelledDoesNotSeek) {
598579 io_ctx.should_stop = true ;
599- input-> fail_reads ( " must not read " );
580+ fail_seek ([] { throw orc::ParseError ( " must not seek " ); } );
600581 Block block;
601582 size_t read_rows = 99 ;
602583 bool eof = false ;
603584 const auto status = reader->get_next_block (&block, &read_rows, &eof);
604585 EXPECT_TRUE (status.ok ()) << status;
605586 EXPECT_TRUE (eof);
606587 EXPECT_EQ (read_rows, 0 );
607- EXPECT_EQ (input-> failed_reads , 0 );
588+ EXPECT_EQ (failed_seeks , 0 );
608589}
609590
610591INSTANTIATE_TEST_SUITE_P (LazyAndNonLazy, OrcRowIdSeekTest, testing::Bool());
0 commit comments