MCPcopy Create free account
hub / github.com/apache/arrow / ScanFileContents

Function ScanFileContents

cpp/src/parquet/file_reader.cc:937–994  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

935// File scanner for performance testing
936
937int64_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}

Callers 2

mainFunction · 0.85
ScanContentsMethod · 0.85

Calls 15

GetTypeByteSizeFunction · 0.85
ScanAllValuesFunction · 0.85
ParquetExceptionFunction · 0.85
resizeMethod · 0.80
physical_typeMethod · 0.80
sizeMethod · 0.45
num_columnsMethod · 0.45
metadataMethod · 0.45
num_row_groupsMethod · 0.45
RowGroupMethod · 0.45
ColumnMethod · 0.45
descrMethod · 0.45

Tested by

no test coverage detected