Don't segfault on full table scan

This commit is contained in:
Colin Dellow 2018-03-04 17:49:19 -05:00
parent 7edb5e472f
commit 4c54ab89ae
2 changed files with 14 additions and 6 deletions

View File

@ -16,10 +16,10 @@ ParquetCursor::ParquetCursor(ParquetTable* table) {
this->numRowGroups = reader->metadata()->num_row_groups(); this->numRowGroups = reader->metadata()->num_row_groups();
} }
void ParquetCursor::nextRowGroup() { bool ParquetCursor::nextRowGroup() {
// TODO: skip row groups that cannot satisfy the constraints // TODO: skip row groups that cannot satisfy the constraints
if(this->rowGroupId >= this->numRowGroups) if((this->rowGroupId + 1) >= this->numRowGroups)
return; return false;
rowGroupId++; rowGroupId++;
rowGroupMetadata = this->reader->metadata()->RowGroup(0); rowGroupMetadata = this->reader->metadata()->RowGroup(0);
@ -40,11 +40,19 @@ void ParquetCursor::nextRowGroup() {
types[i] = rowGroupMetadata->schema()->Column(i)->physical_type(); types[i] = rowGroupMetadata->schema()->Column(i)->physical_type();
logicalTypes[i] = rowGroupMetadata->schema()->Column(i)->logical_type(); logicalTypes[i] = rowGroupMetadata->schema()->Column(i)->logical_type();
} }
return true;
} }
void ParquetCursor::next() { void ParquetCursor::next() {
if(rowsLeftInRowGroup == 0) if(rowsLeftInRowGroup == 0) {
nextRowGroup(); if(!nextRowGroup()) {
// put rowId over the edge so eof returns true
rowId++;
return;
}
}
rowsLeftInRowGroup--; rowsLeftInRowGroup--;
rowId++; rowId++;
} }

View File

@ -26,7 +26,7 @@ class ParquetCursor {
int numRowGroups; int numRowGroups;
int rowsLeftInRowGroup; int rowsLeftInRowGroup;
void nextRowGroup(); bool nextRowGroup();
public: public:
ParquetCursor(ParquetTable* table); ParquetCursor(ParquetTable* table);