hqx871 commented on issue #35616:
URL: https://github.com/apache/arrow/issues/35616#issuecomment-1549550794
The code is very simple.
```
void printParquetFile(const std::string &path) {
arrow::Status st;
// Open Parquet file reader
std::unique_ptr<parquet::arrow::FileReader> arrow_reader;
auto file_reader = parquet::ParquetFileReader::OpenFile(path, true);
st = parquet::arrow::FileReader::Make(
arrow::default_memory_pool(),
std::move(file_reader), &arrow_reader);
if (!st.ok()) {
throw std::runtime_error(st.ToString());
}
auto meta = arrow_reader->parquet_reader()->metadata();
std::cout << path << " row num:" << meta->num_rows() << std::endl;
//auto totalGroupNum = meta->num_row_groups();
//std::map<std::string, int32_t> columnMap;
auto schema = meta->schema();
std::vector<int> readColumnIds;
for (int i = 0; i < meta->num_columns(); ++i) {
auto column = schema->Column(i);
std::cout << "col:" << std::to_string(i)
<< ", path:" << column->path()->ToDotString()
<< ", name:" << column->path()->ToDotVector()[0]
<< ", max definition level:" << column->max_definition_level()
<< std::endl;
readColumnIds.push_back(i);
}
for (int group = 0; group < meta->num_row_groups(); ++group) {
auto rowGroup = meta->RowGroup(group);
auto groupRowNum = rowGroup->num_rows();
std::shared_ptr<arrow::RecordBatchReader> batchReader;
st = arrow_reader->GetRecordBatchReader({group}, {18},
&batchReader);
if (!st.ok()) {
// Handle error instantiating file reader...
throw std::runtime_error(st.ToString());
}
int groupReadLines = 0;
while (groupReadLines < groupRowNum) {
std::shared_ptr<arrow::RecordBatch> rowBatch;
//st = batchReader->ReadNext(&rowBatch);
try{
st = batchReader->ReadNext(&rowBatch);
} catch (const std::exception& ex) {
throw std::runtime_error(ex.what());
}
if (!st.ok()) {
// Handle error instantiating file reader...
throw std::runtime_error(st.ToString());
}
groupReadLines += rowBatch->num_rows();
}
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]