-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Description
Cursors store boundary values (> cursor_value). This is fine for normal enumerations but can lead to problems with NestedEnumerators. Nested cursors depend on the exact values of outer items, but that state is never explicitly stored. If data changes between runs, say a new outer value becomes eligible for processing, the NestedEnumerator doesn't recognize that and uses cursor state for inner layers from the old value.
test "nested cursors depend on outer values" do
outer = [10, 20, 30]
middle = [1, 2, 3]
inner = [:a, :b, :c]
# next- [20, 2, :b]
cursor = [0, 0, 0]
enums = [
->(cursor) { enumerator_builder.build_array_enumerator(outer, cursor: cursor) },
->(_outer_item, cursor) { enumerator_builder.build_array_enumerator(middle, cursor: cursor) },
->(outer_item, middle_item, cursor) {
v = inner.map { |i| [outer_item, middle_item, i] }
enumerator_builder.build_array_enumerator(v, cursor: cursor)
},
]
enum = NestedEnumerator.new(enums, cursor: cursor).each
value_and_cursor = enum.take(1)[0]
assert_equal([[20, 2, :b], [0, 0, 1]], value_and_cursor)
# next should be [20, 2, :c] but we insert a new item in between so next is [15, 2, :c].
# an argument could be made that next should be [15, 1, :a]
outer = [10, 15, 20, 30]
enum = NestedEnumerator.new(enums, cursor: value_and_cursor[1]).each
value_and_cursor = enum.take(1)[0]
assert_equal([[20, 2, :c], [0, 0, 2]], value_and_cursor)
endReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels