Skip to content

Commit 10c855a

Browse files
killme2008MichaelScofield
authored andcommitted
fix: the align in range query must exist (#17)
1 parent 6723c7c commit 10c855a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/parser/mod.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11027,6 +11027,43 @@ impl<'a> Parser<'a> {
1102711027
}
1102811028
rewrite_projection
1102911029
} else {
11030+
// `align` not found, report an error if the projection contains `range_fn` but without rewriting them.
11031+
11032+
let align_fill_validate = |expr: &Expr| {
11033+
rewrite_calculation_expr(expr, true, &mut |e: &Expr| match e {
11034+
Expr::Function(func) => {
11035+
if let Some(name) = func.name.0.first() {
11036+
if name.value.as_str() == "range_fn" {
11037+
let FunctionArguments::List(args) = &func.args else {
11038+
unreachable!()
11039+
};
11040+
11041+
if args.args.len() < 5 {
11042+
return Err(ParserError::ParserError(
11043+
"ALIGN argument cannot be omitted in the range select query".into(),
11044+
));
11045+
}
11046+
}
11047+
}
11048+
Ok(None)
11049+
}
11050+
_ => Ok(None),
11051+
})
11052+
};
11053+
11054+
projection
11055+
.iter()
11056+
.map(|select_item| {
11057+
match select_item {
11058+
SelectItem::UnnamedExpr(expr) => {
11059+
align_fill_validate(expr)?;
11060+
}
11061+
_ => {}
11062+
}
11063+
Ok(())
11064+
})
11065+
.collect::<Result<Vec<()>, ParserError>>()?;
11066+
1103011067
projection
1103111068
};
1103211069

0 commit comments

Comments
 (0)