Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: fix shift to batch bounds #770

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions crates/sparrow-runtime/src/execute/operation/shift_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,15 @@ impl ShiftToColumnOperation {
Err(not_found) => not_found,
};
let (prefix, suffix) = pending.split(split_length)?;
// TODO: What if suffix is empty?
self.pending = Some(suffix);

if suffix.len() == 0 {
// If the suffix is empty, set the pending batch to empty.
// This ensures that we won't try to send an empty batch if
// we flush the pending set on the next iteration.
self.pending = None;
} else {
self.pending = Some(suffix);
}

// The subsort column can naively monotonically increase and preserve the
// uniqueness invariant.
Expand Down Expand Up @@ -572,8 +579,8 @@ impl ShiftToColumnOperation {
// so we can output the pending batch. The next call to `try_next` should
// see that `computed.pending.take()` returns `None`, indicating there is
// nothing else.

let result = self.pending.take();

// Update the subsort column to be monotonically increasing from 0,
// to match the pattern of the merged results. We don't update the
// subsort column in the pending batch, as it helps keep the correct
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"_time":"2023-08-11T14:03:35.000000000","_key":"Project","thread_ts":null,"ts":1691762610.0,"channel":"Project"}
{"_time":"2023-08-11T14:03:45.000000000","_key":"Project","thread_ts":null,"ts":1691762620.0,"channel":"Project"}
{"_time":"2023-08-11T14:03:55.000000000","_key":"Project","thread_ts":null,"ts":1691762630.0,"channel":"Project"}
24 changes: 24 additions & 0 deletions python/pytests/shift_by_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ async def source() -> kd.sources.CsvString:
)


@pytest.fixture(scope="module")
async def filter_source() -> kd.sources.CsvString:
content = "\n".join(
[
"thread_ts,ts,channel",
"null,1691762610.0,Project",
"null,1691762620.0,Project",
"null,1691762630.0,Project",
"1691762650.0,1691762650.0,Project",
"1691762650.0,1691762660.0,Project",
]
)
return await kd.sources.CsvString.create(
content, time_column="ts", key_column="channel", time_unit="s"
)


async def test_shift_by_timedelta(source, golden) -> None:
time = source.col("time")
golden.jsonl(
Expand Down Expand Up @@ -55,3 +72,10 @@ async def test_shift_collect(source, golden) -> None:
}
)
)


# Regression test for https://github.com/kaskada-ai/kaskada/issues/726
async def test_filter_to_shift(filter_source, golden) -> None:
messages = filter_source.filter(filter_source.col("thread_ts").is_null())
messages = messages.shift_by(timedelta(seconds=5))
golden.jsonl(messages)
Loading