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>
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
278276namespace {
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
290288arrow::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 )
0 commit comments