Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Commit edc857b

Browse files
committed
match node implementation
1 parent 1b518a8 commit edc857b

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

google/cloud/firestore_v1/base_query.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,28 +1417,32 @@ def _where_conditions_from_cursor(
14171417
cursor_values, before = cursor
14181418
size = len(cursor_values)
14191419

1420+
if is_start_cursor:
1421+
filter_func = pipeline_expressions.Expression.greater_than
1422+
else:
1423+
filter_func = pipeline_expressions.Expression.less_than
1424+
14201425
field = orderings[size - 1].expr
14211426
value = pipeline_expressions.Constant(cursor_values[size - 1])
14221427

1423-
if not is_start_cursor:
1424-
condition = field.less_than(value)
1425-
else:
1426-
condition = field.greater_than(value)
1428+
# Add condition for last bound
1429+
condition = filter_func(field, value)
14271430

14281431
if (is_start_cursor and before) or (not is_start_cursor and not before):
1432+
# When the cursor bound is inclusive, then the last bound
1433+
# can be equal to the value, otherwise it's not equal
14291434
condition = pipeline_expressions.Or(condition, field.equal(value))
14301435

1436+
# Iterate backwards over the remaining bounds, adding a condition for each one
14311437
for i in range(size - 2, -1, -1):
14321438
field = orderings[i].expr
14331439
value = pipeline_expressions.Constant(cursor_values[i])
14341440

1435-
if not is_start_cursor:
1436-
current_filter = field.less_than(value)
1437-
else:
1438-
current_filter = field.greater_than(value)
1439-
1441+
# For each field in the orderings, the condition is either
1442+
# a) lessThan|greaterThan the cursor value,
1443+
# b) or equal the cursor value and lessThan|greaterThan the cursor values for other fields
14401444
condition = pipeline_expressions.Or(
1441-
current_filter,
1445+
filter_func(field, value),
14421446
pipeline_expressions.And(field.equal(value), condition),
14431447
)
14441448

0 commit comments

Comments
 (0)