Skip to content

Commit b79f275

Browse files
committed
refactor(silo): apply clangd suggestions
1 parent 16f5099 commit b79f275

126 files changed

Lines changed: 537 additions & 699 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-tidy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ Checks: >-
2828
# positives for overridden 'T& operator=(T&)'.
2929
CheckOptions:
3030
- key: readability-identifier-length.IgnoredVariableNames
31-
value: \_
32-
- key: readability-identifier-length.IgnoredVariableNames
33-
value: to
31+
value: '_|to'
32+
- key: readability-identifier-length.IgnoredParameterNames
33+
value: '_|to'
3434
- key: readability-identifier-naming.NamespaceCase
3535
value: lower_case
3636
- key: readability-identifier-naming.ClassCase

src/main.test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "silo/common/log.h"
1111
#include "silo/common/panic.h"
1212

13+
namespace {
14+
1315
int changeCwdToTestFolder() {
1416
// Look for the test data directory (`testBaseData`) in the current directory and up to
1517
// <search_depth> directories above the current directory. If found, change the current working
@@ -29,6 +31,8 @@ int changeCwdToTestFolder() {
2931
return 1;
3032
}
3133

34+
} // namespace
35+
3236
int main(int argc, char* argv[]) {
3337
if (auto exit = changeCwdToTestFolder()) {
3438
return exit;

src/silo/database.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
namespace silo {
2424

2525
Database::Database(schema::DatabaseSchema database_schema)
26-
: schema(database_schema),
26+
: schema(std::move(database_schema)),
2727
table(std::make_shared<storage::Table>(schema.getDefaultTableSchema())) {}
2828

2929
DatabaseInfo Database::getDatabaseInfo() const {

src/silo/database.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#pragma once
22

3-
#include <cstddef>
43
#include <filesystem>
5-
#include <string>
64

75
#include "silo/common/data_version.h"
86
#include "silo/common/silo_directory.h"
@@ -23,7 +21,7 @@ class Database {
2321
DataVersion data_version_ = DataVersion::mineDataVersion();
2422

2523
public:
26-
Database(silo::schema::DatabaseSchema database_schema);
24+
explicit Database(silo::schema::DatabaseSchema database_schema);
2725

2826
virtual ~Database() = default;
2927

@@ -33,7 +31,7 @@ class Database {
3331

3432
[[nodiscard]] virtual DatabaseInfo getDatabaseInfo() const;
3533

36-
virtual DataVersion::Timestamp getDataVersionTimestamp() const;
34+
[[nodiscard]] virtual DataVersion::Timestamp getDataVersionTimestamp() const;
3735
};
3836

3937
} // namespace silo

src/silo/database.test.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
#include <filesystem>
44
#include <fstream>
5-
#include <istream>
65
#include <map>
76

87
#include <gtest/gtest.h>
98

109
#include "config/source/yaml_file.h"
11-
#include "silo/append/append.h"
1210
#include "silo/append/database_inserter.h"
1311
#include "silo/append/ndjson_line_reader.h"
14-
#include "silo/common/nucleotide_symbols.h"
1512
#include "silo/common/phylo_tree.h"
1613
#include "silo/config/preprocessing_config.h"
1714
#include "silo/database_info.h"
@@ -38,7 +35,7 @@ std::shared_ptr<silo::Database> buildTestDatabase() {
3835
);
3936

4037
std::map<std::filesystem::path, silo::common::LineageTreeAndIdMap> lineage_trees;
41-
for (auto filename : config.initialization_files.getLineageDefinitionFilenames()) {
38+
for (const auto& filename : config.initialization_files.getLineageDefinitionFilenames()) {
4239
lineage_trees[filename] =
4340
silo::common::LineageTreeAndIdMap::fromLineageDefinitionFilePath(filename);
4441
}
@@ -52,10 +49,10 @@ std::shared_ptr<silo::Database> buildTestDatabase() {
5249
auto database = std::make_shared<silo::Database>(
5350
silo::Database{silo::initialize::Initializer::createSchemaFromConfigFiles(
5451
std::move(database_config),
55-
std::move(reference_genomes),
56-
std::move(lineage_trees),
57-
std::move(phylo_tree_file),
58-
/*without_unaligned_columns=*/false
52+
reference_genomes,
53+
lineage_trees,
54+
phylo_tree_file,
55+
/*without_unaligned_sequences=*/false
5956
)}
6057
);
6158
std::ifstream input(input_directory / "input.ndjson");

src/silo/database_info.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
#pragma once
22

3-
#include <cinttypes>
4-
#include <map>
5-
#include <vector>
6-
73
#include <fmt/format.h>
84
#include <nlohmann/json.hpp>
95

10-
#include "silo/common/format_number.h"
11-
#include "silo/common/nucleotide_symbols.h"
12-
136
namespace silo {
147

158
struct DatabaseInfo {
@@ -28,7 +21,7 @@ void to_json(nlohmann::json& json, const silo::DatabaseInfo& databaseInfo);
2821
template <>
2922
class [[maybe_unused]] fmt::formatter<silo::DatabaseInfo> {
3023
public:
31-
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
24+
static constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3225
[[maybe_unused]] static auto format(silo::DatabaseInfo database_info, format_context& ctx)
3326
-> decltype(ctx.out()) {
3427
return fmt::format_to(ctx.out(), "{}", nlohmann::json{database_info}.dump());

src/silo/query_engine/actions/action.cpp

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
#include <algorithm>
44
#include <cctype>
55
#include <chrono>
6-
#include <map>
76
#include <memory>
8-
#include <random>
97
#include <utility>
108

119
#include <arrow/acero/exec_plan.h>
@@ -28,7 +26,6 @@
2826
#include "silo/query_engine/bad_request.h"
2927
#include "silo/query_engine/copy_on_write_bitmap.h"
3028
#include "silo/query_engine/exec_node/arrow_util.h"
31-
#include "silo/query_engine/exec_node/ndjson_sink.h"
3229
#include "silo/query_engine/exec_node/throttled_batch_reslicer.h"
3330
#include "silo/query_engine/exec_node/zstd_decompress_expression.h"
3431
#include "silo/storage/column/column_type_visitor.h"
@@ -57,7 +54,7 @@ std::optional<arrow::Ordering> Action::getOrdering() const {
5754
using arrow::compute::SortOrder;
5855

5956
std::vector<arrow::compute::SortKey> sort_keys;
60-
for (auto order_by_field : order_by_fields) {
57+
for (const auto& order_by_field : order_by_fields) {
6158
auto sort_order = order_by_field.ascending ? SortOrder::Ascending : SortOrder::Descending;
6259
sort_keys.emplace_back(order_by_field.name, sort_order);
6360
}
@@ -224,7 +221,8 @@ QueryPlan Action::toQueryPlan(
224221
std::string_view request_id
225222
) {
226223
validateOrderByFields(table->schema);
227-
auto query_plan = toQueryPlanImpl(table, partition_filters, query_options, request_id);
224+
auto query_plan =
225+
toQueryPlanImpl(std::move(table), std::move(partition_filters), query_options, request_id);
228226
if (!query_plan.status().ok()) {
229227
SILO_PANIC("Arrow error: {}", query_plan.status().ToString());
230228
};
@@ -235,7 +233,7 @@ arrow::Result<arrow::acero::ExecNode*> Action::addSortNode(
235233
arrow::acero::ExecPlan* arrow_plan,
236234
arrow::acero::ExecNode* node,
237235
const std::vector<schema::ColumnIdentifier>& output_fields,
238-
const arrow::Ordering ordering,
236+
const arrow::Ordering& ordering,
239237
std::optional<size_t> /*num_rows_to_produce*/
240238
) {
241239
arrow::AsyncGenerator<std::optional<arrow::ExecBatch>> generator;
@@ -277,14 +275,14 @@ arrow::Result<arrow::acero::ExecNode*> Action::addSortNode(
277275

278276
namespace {
279277

280-
uint64_t hash64(uint64_t x, uint64_t seed) {
281-
x ^= seed;
282-
x ^= x >> 33;
283-
x *= 0xff51afd7ed558ccdULL;
284-
x ^= x >> 33;
285-
x *= 0xc4ceb9fe1a85ec53ULL;
286-
x ^= x >> 33;
287-
return x;
278+
uint64_t hash64(uint64_t value, uint64_t seed) {
279+
value ^= seed;
280+
value ^= value >> 33;
281+
value *= 0xff51afd7ed558ccdULL;
282+
value ^= value >> 33;
283+
value *= 0xc4ceb9fe1a85ec53ULL;
284+
value ^= value >> 33;
285+
return value;
288286
}
289287

290288
arrow::Result<arrow::acero::ExecNode*> removeRandomizeColumn(
@@ -341,7 +339,7 @@ arrow::Result<arrow::acero::ExecNode*> Action::addRandomizeColumn(
341339
return std::nullopt;
342340
}
343341

344-
auto input_batch = maybe_input_batch.value();
342+
const auto& input_batch = maybe_input_batch.value();
345343
SILO_ASSERT(!input_batch.values.empty());
346344
auto rows_in_batch = input_batch.values.at(0).length();
347345
SILO_ASSERT_NE(rows_in_batch, arrow::Datum::kUnknownLength);
@@ -406,8 +404,8 @@ class ColumnToReferenceSequenceVisitor {
406404
public:
407405
template <Column ColumnType>
408406
std::optional<std::string> operator()(
409-
const TableSchema& table_schema,
410-
const ColumnIdentifier& column_identifier
407+
const TableSchema& /*table_schema*/,
408+
const ColumnIdentifier& /*column_identifier*/
411409
) {
412410
return std::nullopt;
413411
}
@@ -419,7 +417,7 @@ std::optional<std::string> ColumnToReferenceSequenceVisitor::operator(
419417
const TableSchema& table_schema,
420418
const ColumnIdentifier& column_identifier
421419
) {
422-
auto metadata =
420+
auto* metadata =
423421
table_schema.getColumnMetadata<SequenceColumnPartition<Nucleotide>>(column_identifier.name)
424422
.value();
425423
std::string reference;
@@ -435,7 +433,7 @@ std::optional<std::string> ColumnToReferenceSequenceVisitor::operator(
435433
const TableSchema& table_schema,
436434
const ColumnIdentifier& column_identifier
437435
) {
438-
auto metadata =
436+
auto* metadata =
439437
table_schema.getColumnMetadata<SequenceColumnPartition<AminoAcid>>(column_identifier.name)
440438
.value();
441439
std::string reference;
@@ -451,7 +449,7 @@ std::optional<std::string> ColumnToReferenceSequenceVisitor::operator(
451449
const TableSchema& table_schema,
452450
const ColumnIdentifier& column_identifier
453451
) {
454-
auto metadata =
452+
auto* metadata =
455453
table_schema.getColumnMetadata<ZstdCompressedStringColumnPartition>(column_identifier.name)
456454
.value();
457455
return metadata->dictionary_string;
@@ -465,18 +463,17 @@ arrow::Result<arrow::acero::ExecNode*> Action::addZstdDecompressNode(
465463
const silo::schema::TableSchema& table_schema
466464
) const {
467465
auto output_fields = getOutputSchema(table_schema);
468-
bool needs_decompression =
469-
std::any_of(output_fields.begin(), output_fields.end(), [](const auto& column_identifier) {
470-
return schema::isSequenceColumn(column_identifier.type);
471-
});
466+
bool needs_decompression = std::ranges::any_of(output_fields, [](const auto& column_identifier) {
467+
return schema::isSequenceColumn(column_identifier.type);
468+
});
472469
if (needs_decompression) {
473470
size_t sum_of_reference_genome_sizes = 0;
474471

475472
std::vector<arrow::compute::Expression> column_expressions;
476473
std::vector<std::string> column_names;
477-
for (auto column : getOutputSchema(table_schema)) {
474+
for (const auto& column : getOutputSchema(table_schema)) {
478475
if (auto reference = storage::column::visit(column.type, ColumnToReferenceSequenceVisitor{}, table_schema, column)) {
479-
column_expressions.push_back(exec_node::ZstdDecompressExpression::Make(
476+
column_expressions.push_back(exec_node::ZstdDecompressExpression::make(
480477
arrow::compute::field_ref(arrow::FieldRef{column.name}), reference.value()
481478
));
482479
sum_of_reference_genome_sizes += reference.value().length();
@@ -511,7 +508,7 @@ arrow::Result<arrow::acero::ExecNode*> Action::addZstdDecompressNode(
511508
"additional sink node to help backpressure application before zstd decompression"
512509
);
513510

514-
SILO_ASSERT_GT(sum_of_reference_genome_sizes, 0u);
511+
SILO_ASSERT_GT(sum_of_reference_genome_sizes, 0U);
515512

516513
// We aim for 64 MB batch size to give the plan time to apply backpressure
517514
auto maximum_batch_size =
@@ -520,7 +517,7 @@ arrow::Result<arrow::acero::ExecNode*> Action::addZstdDecompressNode(
520517
// Delay delivery of large number of batches to about 100 MB per second
521518
// A batch targets 64 MB, therefore we allow 1.5 batches per second.
522519
// Therefore, we should never emit more than one resliced batch per 0.667 seconds
523-
constexpr std::chrono::milliseconds target_batch_rate{667};
520+
constexpr std::chrono::milliseconds TARGET_BATCH_RATE{667};
524521

525522
ARROW_ASSIGN_OR_RAISE(
526523
node,
@@ -531,7 +528,7 @@ arrow::Result<arrow::acero::ExecNode*> Action::addZstdDecompressNode(
531528
arrow::acero::SourceNodeOptions{
532529
schema_of_sequence_batches,
533530
exec_node::ThrottledBatchReslicer{
534-
batch_generator, maximum_batch_size, target_batch_rate, backpressure_monitor
531+
batch_generator, maximum_batch_size, TARGET_BATCH_RATE, backpressure_monitor
535532
}
536533
}
537534
)

src/silo/query_engine/actions/action.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "silo/config/runtime_config.h"
1313
#include "silo/query_engine/copy_on_write_bitmap.h"
14-
#include "silo/query_engine/filter/operators/operator.h"
1514
#include "silo/query_engine/query_plan.h"
1615
#include "silo/schema/database_schema.h"
1716
#include "silo/storage/table.h"
@@ -37,7 +36,7 @@ class Action {
3736
virtual ~Action() = default;
3837

3938
// Returns the type of this action, which is used for logging the performance by Action type
40-
virtual std::string_view getType() const = 0;
39+
[[nodiscard]] virtual std::string_view getType() const = 0;
4140

4241
QueryPlan toQueryPlan(
4342
std::shared_ptr<const storage::Table> table,
@@ -53,9 +52,9 @@ class Action {
5352
std::optional<uint32_t> randomize_seed
5453
);
5554

56-
std::optional<arrow::Ordering> getOrdering() const;
55+
[[nodiscard]] std::optional<arrow::Ordering> getOrdering() const;
5756

58-
virtual std::vector<schema::ColumnIdentifier> getOutputSchema(
57+
[[nodiscard]] virtual std::vector<schema::ColumnIdentifier> getOutputSchema(
5958
const silo::schema::TableSchema& table_schema
6059
) const = 0;
6160

@@ -81,7 +80,7 @@ class Action {
8180
) const;
8281

8382
private:
84-
virtual arrow::Result<QueryPlan> toQueryPlanImpl(
83+
[[nodiscard]] virtual arrow::Result<QueryPlan> toQueryPlanImpl(
8584
std::shared_ptr<const storage::Table> table,
8685
std::vector<CopyOnWriteBitmap> partition_filters,
8786
const config::QueryOptions& query_options,
@@ -92,7 +91,7 @@ class Action {
9291
arrow::acero::ExecPlan* arrow_plan,
9392
arrow::acero::ExecNode* node,
9493
const std::vector<schema::ColumnIdentifier>& output_fields,
95-
const arrow::Ordering ordering,
94+
const arrow::Ordering& ordering,
9695
std::optional<size_t> num_rows_to_produce
9796
);
9897

0 commit comments

Comments
 (0)