-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add row_num interface to IRecordBatchSupplier
#79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
90db25b
d6f7ab9
99ab2d8
20fbd8b
ce826f1
065bbb5
3869692
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,7 @@ class IRecordBatchSupplier { | |
| public: | ||
| virtual ~IRecordBatchSupplier() = default; | ||
| virtual std::shared_ptr<arrow::RecordBatch> GetNextBatch() = 0; | ||
| virtual int64_t row_num() const = 0; | ||
| }; | ||
|
Comment on lines
78
to
82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Odps suppliers won't compile IRecordBatchSupplier now requires a pure-virtual row_num(), but ODPSStreamRecordBatchSupplier and ODPSTableRecordBatchSupplier don’t override it, so instantiation is ill-formed and the build will fail. Agent Prompt
|
||
|
|
||
| class SupplierWrapperWithFirstBatch : public IRecordBatchSupplier { | ||
|
|
@@ -111,6 +112,14 @@ class SupplierWrapperWithFirstBatch : public IRecordBatchSupplier { | |
| return batch; // Return the batch from the current supplier | ||
| } | ||
|
|
||
| int64_t row_num() const override { | ||
| int64_t total_rows = 0; | ||
| for (const auto& supplier : suppliers_) { | ||
| total_rows += supplier->row_num(); | ||
| } | ||
| return total_rows; | ||
| } | ||
|
|
||
| private: | ||
| std::vector<std::shared_ptr<IRecordBatchSupplier>> suppliers_; | ||
| std::shared_ptr<arrow::RecordBatch> first_batch_; | ||
|
|
@@ -127,7 +136,10 @@ class CSVStreamRecordBatchSupplier : public IRecordBatchSupplier { | |
|
|
||
| std::shared_ptr<arrow::RecordBatch> GetNextBatch() override; | ||
|
|
||
| int64_t row_num() const override { return row_num_; } | ||
|
|
||
| private: | ||
| int64_t row_num_; | ||
| std::string file_path_; | ||
| std::shared_ptr<arrow::csv::StreamingReader> reader_; | ||
| }; | ||
|
|
@@ -141,6 +153,8 @@ class CSVTableRecordBatchSupplier : public IRecordBatchSupplier { | |
|
|
||
| std::shared_ptr<arrow::RecordBatch> GetNextBatch() override; | ||
|
|
||
| int64_t row_num() const override { return table_->num_rows(); } | ||
|
|
||
| private: | ||
| std::string file_path_; | ||
| std::shared_ptr<arrow::Table> table_; | ||
|
|
@@ -166,6 +180,16 @@ class ArrowRecordBatchArraySupplier : public IRecordBatchSupplier { | |
|
|
||
| std::shared_ptr<arrow::RecordBatch> GetNextBatch() override; | ||
|
|
||
| int64_t row_num() const override { | ||
| int64_t total_rows = 0; | ||
| if (!arrays_.empty()) { | ||
| for (const auto& batch : arrays_[0]) { | ||
| total_rows += batch->length(); | ||
| } | ||
| } | ||
| return total_rows; | ||
| } | ||
|
|
||
| private: | ||
| // NUM_COLUMNS * NUM_BATCHES | ||
| std::vector<std::vector<std::shared_ptr<arrow::Array>>> arrays_; | ||
|
|
@@ -182,12 +206,15 @@ class ArrowRecordBatchArraySupplier : public IRecordBatchSupplier { | |
| class ArrowRecordBatchStreamSupplier : public IRecordBatchSupplier { | ||
| public: | ||
| ArrowRecordBatchStreamSupplier( | ||
| const std::shared_ptr<arrow::RecordBatchReader>& reader) | ||
| : reader_(reader) {} | ||
| const std::shared_ptr<arrow::RecordBatchReader>& reader, int64_t row_num) | ||
| : row_num_(row_num), reader_(reader) {} | ||
|
|
||
| std::shared_ptr<arrow::RecordBatch> GetNextBatch() override; | ||
|
|
||
| int64_t row_num() const override { return row_num_; } | ||
|
|
||
| private: | ||
| int64_t row_num_; | ||
| std::shared_ptr<arrow::RecordBatchReader> reader_; | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -185,6 +185,17 @@ void ArrowReader::batch_read(std::shared_ptr<arrow::dataset::Scanner> scanner, | |
| if (!scanner) { | ||
| THROW_INVALID_ARGUMENT_EXCEPTION("Scanner is null"); | ||
| } | ||
| auto row_num_result = scanner->CountRows(); | ||
| int64_t row_num = 0; | ||
| if (!row_num_result.ok()) { | ||
| LOG(WARNING) << "Failed to count rows via scanner: " | ||
| << row_num_result.status().message(); | ||
| THROW_IO_EXCEPTION("Failed to count rows via scanner: " + | ||
| row_num_result.status().message()); | ||
| } else { | ||
| VLOG(10) << "Row count from scanner: " << row_num_result.ValueOrDie(); | ||
| row_num = row_num_result.ValueOrDie(); | ||
| } | ||
|
Comment on lines
+188
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3. Countrows becomes hard requirement ArrowReader::batch_read now throws if scanner->CountRows() fails, even though it separately creates a RecordBatchReader afterward; this turns a preallocation hint into a hard failure path and can break previously-working reads. Agent Prompt
|
||
|
|
||
| auto batch_reader_result = scanner->ToRecordBatchReader(); | ||
| if (!batch_reader_result.ok()) { | ||
|
|
@@ -195,8 +206,8 @@ void ArrowReader::batch_read(std::shared_ptr<arrow::dataset::Scanner> scanner, | |
| } | ||
| auto batch_reader = batch_reader_result.ValueOrDie(); | ||
|
|
||
| auto batch_supplier = | ||
| std::make_shared<neug::ArrowRecordBatchStreamSupplier>(batch_reader); | ||
| auto batch_supplier = std::make_shared<neug::ArrowRecordBatchStreamSupplier>( | ||
| batch_reader, row_num); | ||
|
|
||
| int num_cols = sharedState->columnNum(); | ||
| output.clear(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Row_num size_t wraparound risk
🐞 Bug⛯ ReliabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools