diff --git a/cpp/src/graphar/label.cc b/cpp/src/graphar/label.cc index 64f3c1abe..83f597fcb 100644 --- a/cpp/src/graphar/label.cc +++ b/cpp/src/graphar/label.cc @@ -22,6 +22,9 @@ #include #include #include +#include + +namespace graphar { /// Read a parquet file by ParquetReader & get valid indices /// The first column_num labels are concerned. @@ -44,9 +47,9 @@ int read_parquet_file_and_get_valid_indices( // Initialize the column row counts std::vector col_row_counts(num_columns, 0); - bool** value = new bool*[num_columns]; + std::vector> value(num_columns); for (int i = 0; i < num_columns; i++) { - value[i] = new bool[row_num]; + value[i] = std::make_unique(row_num); } // Iterate over all the RowGroups in the file @@ -73,9 +76,9 @@ int read_parquet_file_and_get_valid_indices( // Read BATCH_SIZE values at a time. The number of rows read is // returned. values_read contains the number of non-null rows - rows_read = bool_reader->ReadBatch(BATCH_SIZE, nullptr, nullptr, - value[k] + col_row_counts[col_id], - &values_read); + rows_read = bool_reader->ReadBatch( + BATCH_SIZE, nullptr, nullptr, + value[k].get() + col_row_counts[col_id], &values_read); // There are no NULL values in the rows written col_row_counts[col_id] += rows_read; @@ -99,11 +102,7 @@ int read_parquet_file_and_get_valid_indices( } } - // destroy the allocated space - for (int i = 0; i < num_columns; i++) { - delete[] value[i]; - } - delete[] value; - return count; } + +} // namespace graphar diff --git a/cpp/src/graphar/label.h b/cpp/src/graphar/label.h index ec69e626b..0429d93f3 100644 --- a/cpp/src/graphar/label.h +++ b/cpp/src/graphar/label.h @@ -26,8 +26,7 @@ #include #include -#include -#include +#include #include using parquet::ConvertedType; @@ -37,6 +36,8 @@ using parquet::Type; using parquet::schema::GroupNode; using parquet::schema::PrimitiveNode; +namespace graphar { + constexpr int BATCH_SIZE = 1024; // the batch size /// The query type @@ -60,4 +61,6 @@ int read_parquet_file_and_get_valid_indices( uint64_t* bitmap = nullptr, const QUERY_TYPE query_type = QUERY_TYPE::COUNT); +} // namespace graphar + #endif // CPP_SRC_GRAPHAR_LABEL_H_