def test_simple_index_nx_to_memgraph(memgraph: Memgraph): graph = nx.Graph() graph.add_nodes_from([ (1, { "labels": "L1", "num": 123 }), (2, { "labels": "L1", "num": 123 }), (3, { "labels": ["L1", "L2", "L3"], "num": 123 }), ]) graph.add_edges_from([(1, 2), (1, 3)]) expected_indexes = { MemgraphIndex("L1", "id"), MemgraphIndex("L2", "id"), MemgraphIndex("L3", "id"), } for query in nx_to_cypher(graph, NetworkXCypherConfig(create_index=True)): memgraph.execute(query) actual_indexes = set(memgraph.get_indexes()) assert actual_indexes == expected_indexes
def test_create_index(memgraph): index1 = MemgraphIndex("NodeOne") index2 = MemgraphIndex("NodeOne", "name") memgraph.create_index(index1) memgraph.create_index(index2) assert set(memgraph.get_indexes()) == {index1, index2}
def test_create_duplicate_index(memgraph): index = MemgraphIndex("NodeOne") memgraph.create_index(index) memgraph.create_index(index) assert set(memgraph.get_indexes()) == {index}
def test_ensure_index(memgraph): old_indexes = [ MemgraphIndex("NodeOne"), MemgraphIndex("NodeOne", "name"), MemgraphIndex("NodeTwo"), MemgraphIndex("NodeTwo", "age"), ] for old_index in old_indexes: memgraph.create_index(old_index) assert set(memgraph.get_indexes()) == set(old_indexes) new_indexes = [ MemgraphIndex("NodeOne", "name"), MemgraphIndex("NodeTwo"), MemgraphIndex("NodeThree"), MemgraphIndex("NodeFour", "created_at"), ] memgraph.ensure_indexes(new_indexes) assert set(memgraph.get_indexes()) == set(new_indexes)
def test_huge_nx_to_memgraph_parallel_with_index( memgraph: Memgraph, big_random_nx_graph: nx.Graph): memgraph.create_index(MemgraphIndex("Label", "id")) nx_graph_to_memgraph_parallel(big_random_nx_graph)
def test_big_nx_to_memgraph_with_manual_index(memgraph: Memgraph, random_nx_graph: nx.Graph): memgraph.create_index(MemgraphIndex("Label", "id")) for query in nx_to_cypher(random_nx_graph): memgraph.execute(query)
def _create_index(self, label: str, property: str = None): """Returns Cypher query for index creation.""" index = MemgraphIndex(label, property) return f"CREATE INDEX ON {index.to_cypher()}(id);"