diff --git a/parquet/parquet_cursor.cc b/parquet/parquet_cursor.cc index 782784f..35502cd 100644 --- a/parquet/parquet_cursor.cc +++ b/parquet/parquet_cursor.cc @@ -586,6 +586,17 @@ start: return false; } + while(table->getNumColumns() >= scanners.size()) { + scanners.push_back(std::shared_ptr()); + // If it doesn't exist, it's the rowId as of the last nextRowGroup call + colRows.push_back(rowGroupStartRowId); + colNulls.push_back(false); + colIntValues.push_back(0); + colDoubleValues.push_back(0); + colByteArrayValues.push_back(parquet::ByteArray()); + } + + rowGroupStartRowId = rowId; rowGroupId++; rowGroupMetadata = reader->metadata()->RowGroup(rowGroupId); @@ -712,16 +723,6 @@ void ParquetCursor::ensureColumn(int col) { return; // need to ensure a scanner exists (and skip the # of rows in the rowgroup) - while((unsigned int)col >= scanners.size()) { - scanners.push_back(std::shared_ptr()); - // If it doesn't exist, it's the rowId as of the last nextRowGroup call - colRows.push_back(rowGroupStartRowId); - colNulls.push_back(false); - colIntValues.push_back(0); - colDoubleValues.push_back(0); - colByteArrayValues.push_back(parquet::ByteArray()); - } - if(scanners[col].get() == NULL) { std::shared_ptr colReader = rowGroup->Column(col); scanners[col] = parquet::Scanner::Make(colReader); diff --git a/parquet/parquet_table.cc b/parquet/parquet_table.cc index dbc6c14..a0ede14 100644 --- a/parquet/parquet_table.cc +++ b/parquet/parquet_table.cc @@ -13,6 +13,11 @@ std::string ParquetTable::columnName(int i) { return columnNames[i]; } +unsigned int ParquetTable::getNumColumns() { + return columnNames.size(); +} + + std::string ParquetTable::CreateStatement() { std::unique_ptr reader = parquet::ParquetFileReader::OpenFile( file.data(), diff --git a/parquet/parquet_table.h b/parquet/parquet_table.h index 43321f6..6b35cae 100644 --- a/parquet/parquet_table.h +++ b/parquet/parquet_table.h @@ -16,6 +16,7 @@ public: ParquetTable(std::string file, std::string tableName); std::string CreateStatement(); std::string columnName(int idx); + unsigned int getNumColumns(); std::shared_ptr getMetadata(); const std::string& getFile(); const std::string& getTableName();