MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / plan_window_frame

Function plan_window_frame

src/sql/src/plan/query.rs:5933–6013  ·  view source on GitHub ↗
(
    WindowFrame {
        units,
        start_bound,
        end_bound,
    }: &WindowFrame,
)

Source from the content-addressed store, hash-verified

5931}
5932
5933fn plan_window_frame(
5934 WindowFrame {
5935 units,
5936 start_bound,
5937 end_bound,
5938 }: &WindowFrame,
5939) -> Result<mz_expr::WindowFrame, PlanError> {
5940 use mz_expr::WindowFrameBound::*;
5941 let units = window_frame_unit_ast_to_expr(units)?;
5942 let start_bound = window_frame_bound_ast_to_expr(start_bound);
5943 let end_bound = end_bound
5944 .as_ref()
5945 .map(window_frame_bound_ast_to_expr)
5946 .unwrap_or(CurrentRow);
5947
5948 // Validate bounds according to Postgres rules
5949 match (&start_bound, &end_bound) {
5950 // Start bound can't be UNBOUNDED FOLLOWING
5951 (UnboundedFollowing, _) => {
5952 sql_bail!("frame start cannot be UNBOUNDED FOLLOWING")
5953 }
5954 // End bound can't be UNBOUNDED PRECEDING
5955 (_, UnboundedPreceding) => {
5956 sql_bail!("frame end cannot be UNBOUNDED PRECEDING")
5957 }
5958 // Start bound should come before end bound in the list of bound definitions
5959 (CurrentRow, OffsetPreceding(_)) => {
5960 sql_bail!("frame starting from current row cannot have preceding rows")
5961 }
5962 (OffsetFollowing(_), OffsetPreceding(_) | CurrentRow) => {
5963 sql_bail!("frame starting from following row cannot have preceding rows")
5964 }
5965 // The above rules are adopted from Postgres.
5966 // The following rules are Materialize-specific.
5967 (OffsetPreceding(o1), OffsetFollowing(o2)) => {
5968 // Note that the only hard limit is that partition size + offset should fit in i64, so
5969 // in theory, we could support much larger offsets than this. But for our current
5970 // performance, even 1000000 is quite big.
5971 if *o1 > 1000000 || *o2 > 1000000 {
5972 sql_bail!("Window frame offsets greater than 1000000 are currently not supported")
5973 }
5974 }
5975 (OffsetPreceding(o1), OffsetPreceding(o2)) => {
5976 if *o1 > 1000000 || *o2 > 1000000 {
5977 sql_bail!("Window frame offsets greater than 1000000 are currently not supported")
5978 }
5979 }
5980 (OffsetFollowing(o1), OffsetFollowing(o2)) => {
5981 if *o1 > 1000000 || *o2 > 1000000 {
5982 sql_bail!("Window frame offsets greater than 1000000 are currently not supported")
5983 }
5984 }
5985 (OffsetPreceding(o), CurrentRow) => {
5986 if *o > 1000000 {
5987 sql_bail!("Window frame offsets greater than 1000000 are currently not supported")
5988 }
5989 }
5990 (CurrentRow, OffsetFollowing(o)) => {

Callers 1

Calls 4

mapMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected