Skip to content

Commit

Permalink
fix: insertion search e2e and insertion column tests, dont allow non-…
Browse files Browse the repository at this point in the history
…empty value for insertion search
  • Loading branch information
danielgrittner committed Jul 24, 2023
1 parent ae900da commit 19af04d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
"value": ""
}
},
"expectedQueryResult": [
{
"count": 17
}
]
"expectedError": {
"error": "Bad request",
"message": "The field 'value' in an InsertionContains expression must not be an empty string"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"filterExpression": {
"type": "InsertionContains",
"column": "insertions",
"position": 25701,
"value": "CC+++"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"filterExpression": {
"type": "InsertionContains",
"column": "insertions",
"position": 25701,
"position": 22339,
"value": ".*GCT.*GGT.*"
}
},
Expand Down
12 changes: 8 additions & 4 deletions src/silo/query_engine/filter_expressions/insertion_contains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ void from_json(const nlohmann::json& json, std::unique_ptr<InsertionContains>& f
json.contains("value"), "The field 'value' is required in an InsertionContains expression"
)
CHECK_SILO_QUERY(
json["value"].is_string() || json["value"].is_null(),
"The field 'value' in an InsertionContains expression needs to be a string or null"
json["value"].is_string() && !json["value"].is_null(),
"The field 'value' in an InsertionContains expression needs to be a string"
)
const std::string& column_name = json["column"];
uint32_t position = json["position"];
const std::string& value = json["value"].is_null() ? "" : json["value"].get<std::string>();
const uint32_t position = json["position"];
const std::string& value = json["value"].get<std::string>();
CHECK_SILO_QUERY(
!value.empty(),
"The field 'value' in an InsertionContains expression must not be an empty string"
)
CHECK_SILO_QUERY(
validateRegexPattern(value),
"The field 'value' in the InsertionContains expression does not contain a valid regex "
Expand Down
21 changes: 12 additions & 9 deletions src/silo/storage/column/insertion_column.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,29 @@ TEST(InsertionColumn, shouldReturnTheCorrectSearchedValues) {
InsertionColumnPartition under_test(lookup);

under_test.insert("25701:ACCA");
under_test.insert("2301:CCG");
under_test.insert("2301:CCG");
under_test.insert("19832:TTACAT,25701:ACCA");
under_test.insert("25701:CCG");
under_test.insert("25701:CCG");
under_test.insert("25701:TTACAT,25701:ACCA");
under_test.insert("25701:ACCA");
under_test.insert("19832:TTACAT,25701:ACCA,29903:AGCTGTTCAG");
under_test.insert("25701:TTACAT,25701:ACCA,25701:AGCTGTTCAG");

under_test.buildInsertionIndex();

const auto result1 = under_test.search(".*CC.*");
const auto result1 = under_test.search(25701, ".*CC.*");
ASSERT_EQ(*result1, roaring::Roaring({0, 1, 2, 3, 4, 5}));

const auto result2 = under_test.search(".*TTA.*CAT.*");
const auto result2 = under_test.search(25701, ".*TTA.*CAT.*");
ASSERT_EQ(*result2, roaring::Roaring({3, 5}));

const auto result3 = under_test.search(".*AGC.*TGT.*TCA.*G.*");
const auto result3 = under_test.search(25701, ".*AGC.*TGT.*TCA.*G.*");
ASSERT_EQ(*result3, roaring::Roaring({5}));

const auto result4 = under_test.search(".*AGC.*TG.*T.*T.*C.*AG.*");
const auto result4 = under_test.search(25701, ".*AGC.*TG.*T.*T.*C.*AG.*");
ASSERT_EQ(*result4, roaring::Roaring({5}));

const auto result5 = under_test.search(".*TTT.*AAA.*");
const auto result5 = under_test.search(25701, ".*TTT.*AAA.*");
ASSERT_EQ(*result5, roaring::Roaring());

const auto result6 = under_test.search(100, ".*TTT.*AAA.*");
ASSERT_EQ(*result5, roaring::Roaring());
}
9 changes: 7 additions & 2 deletions src/silo/storage/column/insertion_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,18 @@ std::unique_ptr<roaring::Roaring> InsertionIndex::search(
const auto three_mers = extractThreeMers(search_pattern);
const std::regex regex_search_pattern(search_pattern);

const auto insertion_pos_it = insertion_positions.find(position);
if (insertion_pos_it == insertion_positions.end()) {
return std::make_unique<roaring::Roaring>();
}

if (!three_mers.empty()) {
return insertion_positions.at(position).searchWithThreeMerIndex(
return insertion_pos_it->second.searchWithThreeMerIndex(
three_mers, regex_search_pattern
);
}
auto result = std::make_unique<roaring::Roaring>();
for (const auto& insertion : insertion_positions.at(position).insertions) {
for (const auto& insertion : insertion_pos_it->second.insertions) {
if (std::regex_search(insertion.value, regex_search_pattern)) {
*result |= insertion.sequence_ids;
}
Expand Down

0 comments on commit 19af04d

Please sign in to comment.