| 935 | // File scanner for performance testing |
| 936 | |
| 937 | int64_t ScanFileContents(std::vector<int> columns, const int32_t column_batch_size, |
| 938 | ParquetFileReader* reader) { |
| 939 | std::vector<int16_t> rep_levels(column_batch_size); |
| 940 | std::vector<int16_t> def_levels(column_batch_size); |
| 941 | |
| 942 | int num_columns = static_cast<int>(columns.size()); |
| 943 | |
| 944 | // columns are not specified explicitly. Add all columns |
| 945 | if (columns.size() == 0) { |
| 946 | num_columns = reader->metadata()->num_columns(); |
| 947 | columns.resize(num_columns); |
| 948 | for (int i = 0; i < num_columns; i++) { |
| 949 | columns[i] = i; |
| 950 | } |
| 951 | } |
| 952 | if (num_columns == 0) { |
| 953 | // If we still have no columns(none in file), return early. The remainder of function |
| 954 | // expects there to be at least one column. |
| 955 | return 0; |
| 956 | } |
| 957 | |
| 958 | std::vector<int64_t> total_rows(num_columns, 0); |
| 959 | |
| 960 | for (int r = 0; r < reader->metadata()->num_row_groups(); ++r) { |
| 961 | auto group_reader = reader->RowGroup(r); |
| 962 | int col = 0; |
| 963 | for (auto i : columns) { |
| 964 | std::shared_ptr<ColumnReader> col_reader = group_reader->Column(i); |
| 965 | size_t value_byte_size = GetTypeByteSize(col_reader->descr()->physical_type()); |
| 966 | std::vector<uint8_t> values(column_batch_size * value_byte_size); |
| 967 | |
| 968 | int64_t values_read = 0; |
| 969 | while (col_reader->HasNext()) { |
| 970 | int64_t levels_read = |
| 971 | ScanAllValues(column_batch_size, def_levels.data(), rep_levels.data(), |
| 972 | values.data(), &values_read, col_reader.get()); |
| 973 | if (col_reader->descr()->max_repetition_level() > 0) { |
| 974 | for (size_t i = 0; i < static_cast<size_t>(levels_read); i++) { |
| 975 | if (rep_levels[i] == 0) { |
| 976 | total_rows[col]++; |
| 977 | } |
| 978 | } |
| 979 | } else { |
| 980 | total_rows[col] += levels_read; |
| 981 | } |
| 982 | } |
| 983 | col++; |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | for (int i = 1; i < num_columns; ++i) { |
| 988 | if (total_rows[0] != total_rows[i]) { |
| 989 | throw ParquetException("Parquet error: Total rows among columns do not match"); |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | return total_rows[0]; |
| 994 | } |
no test coverage detected