From 4c54ab89ae6d7be7a209dec85286a5e43ca96d5f Mon Sep 17 00:00:00 2001 From: Colin Dellow Date: Sun, 4 Mar 2018 17:49:19 -0500 Subject: [PATCH] Don't segfault on full table scan --- parquet/parquet_cursor.cc | 18 +++++++++++++----- parquet/parquet_cursor.h | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/parquet/parquet_cursor.cc b/parquet/parquet_cursor.cc index 205e4d5..906ad91 100644 --- a/parquet/parquet_cursor.cc +++ b/parquet/parquet_cursor.cc @@ -16,10 +16,10 @@ ParquetCursor::ParquetCursor(ParquetTable* table) { this->numRowGroups = reader->metadata()->num_row_groups(); } -void ParquetCursor::nextRowGroup() { +bool ParquetCursor::nextRowGroup() { // TODO: skip row groups that cannot satisfy the constraints - if(this->rowGroupId >= this->numRowGroups) - return; + if((this->rowGroupId + 1) >= this->numRowGroups) + return false; rowGroupId++; rowGroupMetadata = this->reader->metadata()->RowGroup(0); @@ -40,11 +40,19 @@ void ParquetCursor::nextRowGroup() { types[i] = rowGroupMetadata->schema()->Column(i)->physical_type(); logicalTypes[i] = rowGroupMetadata->schema()->Column(i)->logical_type(); } + + return true; } void ParquetCursor::next() { - if(rowsLeftInRowGroup == 0) - nextRowGroup(); + if(rowsLeftInRowGroup == 0) { + if(!nextRowGroup()) { + // put rowId over the edge so eof returns true + rowId++; + return; + } + } + rowsLeftInRowGroup--; rowId++; } diff --git a/parquet/parquet_cursor.h b/parquet/parquet_cursor.h index 1497603..16f5128 100644 --- a/parquet/parquet_cursor.h +++ b/parquet/parquet_cursor.h @@ -26,7 +26,7 @@ class ParquetCursor { int numRowGroups; int rowsLeftInRowGroup; - void nextRowGroup(); + bool nextRowGroup(); public: ParquetCursor(ParquetTable* table);