Add empty graph test on analyze

This commit is contained in:
Josip Mrden
2023-06-26 13:02:45 +02:00
parent 2f4f2896e2
commit 1fdf0b9bec
2 changed files with 23 additions and 3 deletions

View File

@@ -1563,7 +1563,8 @@ std::vector<std::vector<TypedValue>> AnalyzeGraphQueryHandler::AnalyzeGraphCreat
total_degree += *vertex.OutDegree(view) + *vertex.InDegree(view);
});
auto average_degree = static_cast<double>(total_degree) / static_cast<double>(no_vertices);
auto average_degree =
no_vertices > 0 ? static_cast<double>(total_degree) / static_cast<double>(no_vertices) : 0;
auto index_stats = storage::LabelIndexStats{.count = no_vertices, .avg_degree = average_degree};
execution_db_accessor->SetIndexStats(index_info, index_stats);
label_stats.emplace_back(std::make_pair(index_info, index_stats));
@@ -1597,8 +1598,9 @@ std::vector<std::vector<TypedValue>> AnalyzeGraphQueryHandler::AnalyzeGraphCreat
return prev_result + utils::ChiSquaredValue(value_entry.second, avg_group_size);
});
double average_degree =
static_cast<double>(vertex_degree_counter[label_property]) / static_cast<double>(count_property_value);
double average_degree = count_property_value > 0 ? static_cast<double>(vertex_degree_counter[label_property]) /
static_cast<double>(count_property_value)
: 0;
auto index_stats =
storage::LabelPropertyIndexStats{.count = count_property_value,

View File

@@ -454,5 +454,23 @@ def test_given_supernode_when_subquery_and_union_then_carry_information(memgraph
assert expected_explain == result_with_analysis
def test_given_empty_graph_when_analyzing_graph_return_zero_degree(memgraph):
memgraph.execute("CREATE INDEX ON :Node;")
label_stats = next(memgraph.execute_and_fetch("analyze graph;"))
expected_analysis = {
"label": "Node",
"property": None,
"num estimation nodes": 0,
"num groups": None,
"avg group size": None,
"chi-squared value": None,
"avg degree": 0.0,
}
assert set(label_stats) == set(expected_analysis)
if __name__ == "__main__":
sys.exit(pytest.main([__file__, "-rA"]))