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

Fix incorrect window function cancellation handling #5818

Merged
merged 5 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
27 changes: 17 additions & 10 deletions dbms/src/DataStreams/WindowBlockInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,28 @@ void WindowBlockInputStream::initialWorkspaces()
only_have_pure_window = onlyHaveRowNumberAndRank();
}

std::optional<Block> WindowBlockInputStream::returnIfCancelledOrKilled()
{
if (isCancelledOrThrowIfKilled())
{
if (!window_blocks.empty())
window_blocks.erase(window_blocks.begin(), window_blocks.end());
input_is_finished = true;
return {Block{}};
}
return {};
}

Block WindowBlockInputStream::readImpl()
{
const auto & stream = children.back();
while (!input_is_finished)
{
if (auto res = returnIfCancelledOrKilled(); res.has_value())
return res.value();

if (Block output_block = tryGetOutputBlock())
{
return output_block;
}

Block block = stream->read();
if (!block)
Expand All @@ -91,6 +104,8 @@ Block WindowBlockInputStream::readImpl()
tryCalculate();
}

if (auto res = returnIfCancelledOrKilled(); res.has_value())
return res.value();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When query was canceled or killed, we should return {} or Block{}?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block res;
if (isCancelledOrThrowIfKilled())
return res;

same as IProfilingBlockInputStream, return Block{} directly.

// return last partition block, if already return then return null
return tryGetOutputBlock();
}
Expand Down Expand Up @@ -374,14 +389,6 @@ void WindowBlockInputStream::writeOutCurrentRow()

Block WindowBlockInputStream::tryGetOutputBlock()
{
if (isCancelledOrThrowIfKilled())
{
if (!window_blocks.empty())
window_blocks.erase(window_blocks.begin(), window_blocks.end());
input_is_finished = true;
return {};
}

assert(first_not_ready_row.block >= first_block_number);
// The first_not_ready_row might be past-the-end if we have already
// calculated the window functions for all input rows. That's why the
Expand Down
1 change: 1 addition & 0 deletions dbms/src/DataStreams/WindowBlockInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class WindowBlockInputStream : public IProfilingBlockInputStream
protected:
Block readImpl() override;
void appendInfo(FmtBuffer & buffer) const override;
std::optional<Block> returnIfCancelledOrKilled();

LoggerPtr log;

Expand Down