diff --git a/velox/dwio/parquet/reader/DeltaBpDecoder.h b/velox/dwio/parquet/reader/DeltaBpDecoder.h index 7bb91ea02eaf..9d657be51292 100644 --- a/velox/dwio/parquet/reader/DeltaBpDecoder.h +++ b/velox/dwio/parquet/reader/DeltaBpDecoder.h @@ -78,6 +78,14 @@ class DeltaBpDecoder { } } + const char* bufferStart() { + return bufferStart_; + } + + int64_t validValuesCount() { + return static_cast(totalValuesRemaining_); + } + private: bool getVlqInt(uint64_t& v) { uint64_t tmp = 0; @@ -173,6 +181,7 @@ class DeltaBpDecoder { if (totalValueCount_ != 1) { initBlock(); } + totalValuesRemaining_--; return value; } else { ++miniBlockIdx_; @@ -201,7 +210,7 @@ class DeltaBpDecoder { valuesRemainingCurrentMiniBlock_--; totalValuesRemaining_--; - if (valuesRemainingCurrentMiniBlock_ == 0) { + if (valuesRemainingCurrentMiniBlock_ == 0 || totalValuesRemaining_ == 0) { bufferStart_ += bits::nbytes(deltaBitWidth_ * valuesPerMiniBlock_); } return value; diff --git a/velox/dwio/parquet/reader/PageReader.h b/velox/dwio/parquet/reader/PageReader.h index 7d826e0d16d9..41806da18338 100644 --- a/velox/dwio/parquet/reader/PageReader.h +++ b/velox/dwio/parquet/reader/PageReader.h @@ -529,6 +529,13 @@ void PageReader::readWithVisitor(Visitor& visitor) { visitor.setNumValuesBias(numValuesBeforePage); visitor.setRows(pageRows); callDecoder(nulls, nullsFromFastPath, visitor); + if (encoding_ == thrift::Encoding::DELTA_BINARY_PACKED && + deltaBpDecoder_->validValuesCount() == 0) { + VELOX_DCHECK( + deltaBpDecoder_->bufferStart() == pageData_ + encodedDataSize_, + "Once all data in the delta binary packed decoder has been read, " + "its buffer ptr should be moved to the end of the page."); + } if (currentVisitorRow_ < numVisitorRows_ || isMultiPage) { if (mayProduceNulls) { if (!isMultiPage) {