Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit b01c4f4

Browse files
author
Adam Mitchell
authored
Fix queries larger than 50 (#99)
## What is the goal of this PR? To fix a bug that caused queries with more than 50 results to fail. This case was not correctly covered with a regression test and that has now been fixed. ## What are the changes implemented in this PR? - Added a test for queries with a size larger than 50 in order to trigger results batching. - Fixed a mismatch between batch options and batch size.
1 parent 8de3a39 commit b01c4f4

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

grakn/service/Session/util/RequestBuilder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ def start_iterating_get_attributes_by_value(value, datatype, batch_size=None):
7979
start_iterating_get_attributes_by_value = staticmethod(start_iterating_get_attributes_by_value)
8080

8181
@staticmethod
82-
def continue_iterating(iterator_id, batch_options=None):
83-
transaction_iter_req = RequestBuilder._base_iterate_with_options(batch_options)
82+
def continue_iterating(iterator_id, batch_options):
83+
transaction_iter_req = transaction_messages.Transaction.Iter.Req()
84+
transaction_iter_req.options.CopyFrom(batch_options)
8485
transaction_iter_req.iteratorId = iterator_id
8586
return transaction_iter_req
8687

tests/integration/test_grakn.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,19 @@ def test_query_valid_result(self):
180180
answers = self.tx.query("match $x isa person; get;")
181181
self.assertIsNotNone(answers)
182182

183-
184183
def test_query_empty_result(self):
184+
""" Ensures that empty query results behave like empty iterators """
185185
answers = self.tx.query('match $x isa person, has age 9999; get;')
186186
with self.assertRaises(StopIteration):
187187
next(answers)
188188

189+
def test_query_with_multiple_batches(self):
190+
""" Ensures that the query batching code works as intended and does not regress """
191+
self.tx.query('define giraffe sub entity;')
192+
for i in range(150):
193+
self.tx.query('insert $x isa giraffe;')
194+
answers = self.tx.query('match $x isa giraffe; get $x;')
195+
self.assertEquals(sum(1 for _ in answers), 150)
189196

190197
def test_query_invalid_syntax(self):
191198
""" Invalid syntax -- expected behavior is an exception & closed transaction """

0 commit comments

Comments
 (0)