mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
add boundary order check
This commit is contained in:
parent
c18749a704
commit
8212976dc0
@ -121,11 +121,21 @@ void WindowFrame::checkValid() const
|
||||
if (end_type == BoundaryType::Offset
|
||||
&& begin_type == BoundaryType::Offset)
|
||||
{
|
||||
// Frame starting with following rows can't have preceding rows.
|
||||
if (!(end_preceding && !begin_preceding))
|
||||
{
|
||||
// Should probably check here that starting offset is less than
|
||||
// ending offset, but with regard to ORDER BY direction for RANGE
|
||||
// frames.
|
||||
// Frame start offset must be less or equal that the frame end offset.
|
||||
const bool begin_before_end
|
||||
= begin_offset * (begin_preceding ? -1 : 1)
|
||||
<= end_offset * (end_preceding ? -1 : 1);
|
||||
|
||||
if (!begin_before_end)
|
||||
{
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS,
|
||||
"Frame start offset {} {} does not precede the frame end offset {} {}",
|
||||
begin_offset, begin_preceding ? "PRECEDING" : "FOLLOWING",
|
||||
end_offset, end_preceding ? "PRECEDING" : "FOLLOWING");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -135,4 +145,20 @@ void WindowFrame::checkValid() const
|
||||
toString());
|
||||
}
|
||||
|
||||
void WindowDescription::checkValid() const
|
||||
{
|
||||
frame.checkValid();
|
||||
|
||||
// RANGE OFFSET requires exactly one ORDER BY column.
|
||||
if (frame.type == WindowFrame::FrameType::Range
|
||||
&& (frame.begin_type == WindowFrame::BoundaryType::Offset
|
||||
|| frame.end_type == WindowFrame::BoundaryType::Offset)
|
||||
&& order_by.size() != 1)
|
||||
{
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS,
|
||||
"The RANGE OFFSET window frame requires exactly one ORDER BY column, {} given",
|
||||
order_by.size());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -131,7 +131,10 @@ struct WindowDescription
|
||||
// The window functions that are calculated for this window.
|
||||
std::vector<WindowFunctionDescription> window_functions;
|
||||
|
||||
|
||||
std::string dump() const;
|
||||
|
||||
void checkValid() const;
|
||||
};
|
||||
|
||||
using WindowFunctionDescriptions = std::vector<WindowFunctionDescription>;
|
||||
|
@ -60,21 +60,11 @@ WindowStep::WindowStep(const DataStream & input_stream_,
|
||||
, window_functions(window_functions_)
|
||||
, input_header(input_stream_.header)
|
||||
{
|
||||
const auto & frame = window_description.frame;
|
||||
// We don't remove any columns, only add, so probably we don't have to update
|
||||
// the output DataStream::distinct_columns.
|
||||
frame.checkValid();
|
||||
|
||||
// RANGE OFFSET requires exactly one ORDER BY column.
|
||||
if (frame.type == WindowFrame::FrameType::Range
|
||||
&& (frame.begin_type == WindowFrame::BoundaryType::Offset
|
||||
|| frame.end_type == WindowFrame::BoundaryType::Offset)
|
||||
&& window_description.order_by.size() != 1)
|
||||
{
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS,
|
||||
"The RANGE OFFSET window frame requires exactly one ORDER BY column, {} given",
|
||||
window_description.order_by.size());
|
||||
}
|
||||
window_description.checkValid();
|
||||
|
||||
}
|
||||
|
||||
void WindowStep::transformPipeline(QueryPipeline & pipeline)
|
||||
|
Loading…
Reference in New Issue
Block a user