Skip to content

Commit

Permalink
Merge pull request #39 from ClickHouse/count-from-record-batch
Browse files Browse the repository at this point in the history
Allow to get number of rows in record batch

(cherry picked from commit 1d93838)
  • Loading branch information
Avogar authored and nikitamikhaylov committed Oct 15, 2024
1 parent 45ea0d6 commit fb031b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cpp/src/arrow/ipc/reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,23 @@ class RecordBatchFileReaderImpl : public RecordBatchFileReader {
return total;
}

Result<int64_t> RecordBatchCountRows(int i) override {
DCHECK_GE(i, 0);
DCHECK_LT(i, num_record_batches());
ARROW_ASSIGN_OR_RAISE(auto outer_message,
ReadMessageFromBlock(GetRecordBatchBlock(i)));
auto metadata = outer_message->metadata();
const flatbuf::Message* message = nullptr;
RETURN_NOT_OK(
internal::VerifyMessage(metadata->data(), metadata->size(), &message));
auto batch = message->header_as_RecordBatch();
if (batch == nullptr) {
return Status::IOError(
"Header-type of flatbuffer-encoded Message is not RecordBatch.");
}
return batch->length();
}

Status Open(const std::shared_ptr<io::RandomAccessFile>& file, int64_t footer_offset,
const IpcReadOptions& options) {
owned_file_ = file;
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/arrow/ipc/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ class ARROW_EXPORT RecordBatchFileReader
/// \brief Computes the total number of rows in the file.
virtual Result<int64_t> CountRows() = 0;

virtual Result<int64_t> RecordBatchCountRows(int i) = 0;

/// \brief Begin loading metadata for the desired batches into memory.
///
/// This method will also begin loading all dictionaries messages into memory.
Expand Down

0 comments on commit fb031b0

Please sign in to comment.