Add empty graph test on analyze
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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"]))
|
||||
|
||||
Reference in New Issue
Block a user