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

[GLUTEN-6213][CH] Reduce memory usage for some window functions #6214

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 19 additions & 2 deletions cpp-ch/local-engine/Parser/WindowRelParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,25 @@ DB::WindowFrame WindowRelParser::parseWindowFrame(const WindowInfo & win_info)
const auto & signature_function_name = win_info.signature_function_name;
const auto & window_function = win_info.measure->measure();
win_frame.type = parseWindowFrameType(signature_function_name, window_function);
parseBoundType(window_function.lower_bound(), true, win_frame.begin_type, win_frame.begin_offset, win_frame.begin_preceding);
parseBoundType(window_function.upper_bound(), false, win_frame.end_type, win_frame.end_offset, win_frame.end_preceding);

/// row_number is not related to window frame bound settings.
/// This is a tricky way, but OOM has happened to many times in practice .
/// Let's wait for a new fix in `CH` and remove this later. https://github.com/ClickHouse/ClickHouse/issues/65642
if (signature_function_name == "row_number")
{
win_frame.begin_type = DB::WindowFrame::BoundaryType::Offset;
win_frame.begin_offset = 1;
win_frame.begin_preceding = true;

win_frame.end_type = DB::WindowFrame::BoundaryType::Current;
win_frame.end_offset = 0;
win_frame.end_preceding = false;
}
else
{
parseBoundType(window_function.lower_bound(), true, win_frame.begin_type, win_frame.begin_offset, win_frame.begin_preceding);
parseBoundType(window_function.upper_bound(), false, win_frame.end_type, win_frame.end_offset, win_frame.end_preceding);
}

// special cases
if (signature_function_name == "lead" || signature_function_name == "lag")
Expand Down
Loading