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

Function plan_window_function_common

src/sql/src/plan/query.rs:5884–5931  ·  view source on GitHub ↗

The common part of the planning of all window functions.

(
    ecx: &ExprContext,
    name: &<Aug as AstInfo>::ItemName,
    over: &Option<WindowSpec<Aug>>,
)

Source from the content-addressed store, hash-verified

5882
5883/// The common part of the planning of all window functions.
5884fn plan_window_function_common(
5885 ecx: &ExprContext,
5886 name: &<Aug as AstInfo>::ItemName,
5887 over: &Option<WindowSpec<Aug>>,
5888) -> Result<
5889 (
5890 bool,
5891 Vec<HirScalarExpr>,
5892 Vec<ColumnOrder>,
5893 mz_expr::WindowFrame,
5894 Vec<HirScalarExpr>,
5895 ),
5896 PlanError,
5897> {
5898 if !ecx.allow_windows {
5899 sql_bail!(
5900 "window functions are not allowed in {} (function {})",
5901 ecx.name,
5902 name
5903 );
5904 }
5905
5906 let window_spec = match over.as_ref() {
5907 Some(over) => over,
5908 None => sql_bail!("window function {} requires an OVER clause", name),
5909 };
5910 if window_spec.ignore_nulls && window_spec.respect_nulls {
5911 sql_bail!("Both IGNORE NULLS and RESPECT NULLS were given.");
5912 }
5913 let window_frame = match window_spec.window_frame.as_ref() {
5914 Some(frame) => plan_window_frame(frame)?,
5915 None => mz_expr::WindowFrame::default(),
5916 };
5917 let mut partition = Vec::new();
5918 for expr in &window_spec.partition_by {
5919 partition.push(plan_expr(ecx, expr)?.type_as_any(ecx)?);
5920 }
5921
5922 let (order_by_exprs, col_orders) = plan_function_order_by(ecx, &window_spec.order_by)?;
5923
5924 Ok((
5925 window_spec.ignore_nulls,
5926 order_by_exprs,
5927 col_orders,
5928 window_frame,
5929 partition,
5930 ))
5931}
5932
5933fn plan_window_frame(
5934 WindowFrame {

Callers 2

plan_functionFunction · 0.85

Calls 6

plan_window_frameFunction · 0.85
plan_exprFunction · 0.85
plan_function_order_byFunction · 0.85
type_as_anyMethod · 0.80
as_refMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected