@@ -62,37 +62,55 @@ def graph_env(tmp_path):
6262 return config , datasets , people_table
6363
6464
65- def test_basic_node_selection (graph_env ):
65+ @pytest .mark .parametrize ("execute_method" , ["execute" , "execute_datafusion" ])
66+ def test_basic_node_selection (graph_env , execute_method ):
6667 config , datasets , _ = graph_env
6768 query = CypherQuery ("MATCH (p:Person) RETURN p.name, p.age" ).with_config (config )
68- result = query . execute ({"Person" : datasets ["Person" ]})
69+ result = getattr ( query , execute_method ) ({"Person" : datasets ["Person" ]})
6970 data = result .to_pydict ()
70- assert len (data ["name" ]) == 4
71- assert set (data .keys ()) == {"name" , "age" }
72- assert "Alice" in set (data ["name" ])
7371
74-
75- def test_filtered_query (graph_env ):
72+ # TODO: remove this if/else statements when the execute() also returns
73+ # Cypher dot notation
74+ if execute_method == "execute" :
75+ # execute() returns unqualified names for simple queries
76+ assert set (data .keys ()) == {"name" , "age" }
77+ assert len (data ["name" ]) == 4
78+ assert "Alice" in set (data ["name" ])
79+ else :
80+ # execute_datafusion() returns Cypher dot notation
81+ assert set (data .keys ()) == {"p.name" , "p.age" }
82+ assert len (data ["p.name" ]) == 4
83+ assert "Alice" in set (data ["p.name" ])
84+
85+
86+ @pytest .mark .parametrize ("execute_method" , ["execute" , "execute_datafusion" ])
87+ def test_filtered_query (graph_env , execute_method ):
7688 config , datasets , _ = graph_env
7789 query = CypherQuery (
7890 "MATCH (p:Person) WHERE p.age > 30 RETURN p.name, p.age"
7991 ).with_config (config )
80- result = query . execute ({"Person" : datasets ["Person" ]})
92+ result = getattr ( query , execute_method ) ({"Person" : datasets ["Person" ]})
8193 data = result .to_pydict ()
82- assert len (data ["name" ]) == 2
83- assert set (data ["name" ]) == {"Bob" , "David" }
84- assert all (age > 30 for age in data ["age" ])
94+
95+ if execute_method == "execute" :
96+ assert len (data ["name" ]) == 2
97+ assert set (data ["name" ]) == {"Bob" , "David" }
98+ assert all (age > 30 for age in data ["age" ])
99+ else :
100+ assert len (data ["p.name" ]) == 2
101+ assert set (data ["p.name" ]) == {"Bob" , "David" }
102+ assert all (age > 30 for age in data ["p.age" ])
85103
86104
87- def test_relationship_query (graph_env ):
105+ @pytest .mark .parametrize ("execute_method" , ["execute" , "execute_datafusion" ])
106+ def test_relationship_query (graph_env , execute_method ):
88107 config , datasets , _ = graph_env
89- # Alias outputs to stable column names regardless of internal qualification
90108 query = CypherQuery (
91109 "MATCH (p:Person)-[:WORKS_FOR]->(c:Company) "
92110 "RETURN p.person_id AS person_id, p.name AS name, c.company_id AS company_id"
93111 ).with_config (config )
94112
95- result = query . execute (
113+ result = getattr ( query , execute_method ) (
96114 {
97115 "Person" : datasets ["Person" ],
98116 "Company" : datasets ["Company" ],
@@ -105,7 +123,8 @@ def test_relationship_query(graph_env):
105123 assert data ["company_id" ] == [101 , 101 , 102 , 103 ]
106124
107125
108- def test_friendship_direct_and_network (graph_env ):
126+ @pytest .mark .parametrize ("execute_method" , ["execute" , "execute_datafusion" ])
127+ def test_friendship_direct_and_network (graph_env , execute_method ):
109128 config , datasets , _ = graph_env
110129 # Direct friends of Alice (person_id = 1)
111130 query_direct = CypherQuery (
@@ -114,7 +133,7 @@ def test_friendship_direct_and_network(graph_env):
114133 "RETURN b.person_id AS friend_id"
115134 ).with_config (config )
116135
117- result_direct = query_direct . execute (
136+ result_direct = getattr ( query_direct , execute_method ) (
118137 {
119138 "Person" : datasets ["Person" ],
120139 "FRIEND_OF" : datasets ["FRIEND_OF" ],
@@ -129,7 +148,7 @@ def test_friendship_direct_and_network(graph_env):
129148 "RETURN f.person_id AS person1_id, t.person_id AS person2_id"
130149 ).with_config (config )
131150
132- result_edges = query_edges . execute (
151+ result_edges = getattr ( query_edges , execute_method ) (
133152 {
134153 "Person" : datasets ["Person" ],
135154 "FRIEND_OF" : datasets ["FRIEND_OF" ],
@@ -140,15 +159,16 @@ def test_friendship_direct_and_network(graph_env):
140159 assert got == {(1 , 2 ), (1 , 3 ), (2 , 4 ), (3 , 4 )}
141160
142161
143- def test_two_hop_friends_of_friends (graph_env ):
162+ @pytest .mark .parametrize ("execute_method" , ["execute" , "execute_datafusion" ])
163+ def test_two_hop_friends_of_friends (graph_env , execute_method ):
144164 config , datasets , _ = graph_env
145165 query = CypherQuery (
146166 "MATCH (a:Person)-[:FRIEND_OF]->(b:Person)-[:FRIEND_OF]->(c:Person) "
147167 "WHERE a.person_id = 1 "
148168 "RETURN a.person_id AS a_id, b.person_id AS b_id, c.person_id AS c_id"
149169 ).with_config (config )
150170
151- result = query . execute (
171+ result = getattr ( query , execute_method ) (
152172 {
153173 "Person" : datasets ["Person" ],
154174 "FRIEND_OF" : datasets ["FRIEND_OF" ],
@@ -158,15 +178,42 @@ def test_two_hop_friends_of_friends(graph_env):
158178 assert set (data ["c_id" ]) == {4 }
159179
160180
161- def test_variable_length_path (graph_env ):
181+ @pytest .mark .parametrize ("execute_method" , ["execute" , "execute_datafusion" ])
182+ def test_variable_length_path (graph_env , execute_method ):
162183 config , datasets , _ = graph_env
163184 query = CypherQuery (
164185 "MATCH (p1:Person)-[:FRIEND_OF*1..2]-(p2:Person) "
165186 "RETURN p1.person_id AS p1, p2.person_id AS p2"
166187 ).with_config (config )
167- _ = query . execute (
188+ _ = getattr ( query , execute_method ) (
168189 {
169190 "Person" : datasets ["Person" ],
170191 "FRIEND_OF" : datasets ["FRIEND_OF" ],
171192 }
172193 )
194+
195+
196+ @pytest .mark .parametrize ("execute_method" , ["execute" , "execute_datafusion" ])
197+ def test_distinct_clause (graph_env , execute_method ):
198+ config , datasets , _ = graph_env
199+ query = CypherQuery (
200+ "MATCH (p:Person)-[:WORKS_FOR]->(c:Company) RETURN DISTINCT c.company_name"
201+ ).with_config (config )
202+
203+ result = getattr (query , execute_method )(
204+ {
205+ "Person" : datasets ["Person" ],
206+ "Company" : datasets ["Company" ],
207+ "WORKS_FOR" : datasets ["WORKS_FOR" ],
208+ }
209+ )
210+ data = result .to_pydict ()
211+
212+ if execute_method == "execute" :
213+ # execute() returns qualified column names for relationship queries
214+ assert len (data ["c__company_name" ]) == 3
215+ assert set (data ["c__company_name" ]) == {"TechCorp" , "DataInc" , "CloudSoft" }
216+ else :
217+ # execute_datafusion() returns Cypher dot notation
218+ assert len (data ["c.company_name" ]) == 3
219+ assert set (data ["c.company_name" ]) == {"TechCorp" , "DataInc" , "CloudSoft" }
0 commit comments