Skip to content

Commit c3adb7f

Browse files
committed
fix: the align in range query must exist
1 parent e98e6b3 commit c3adb7f

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/parser/mod.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10508,6 +10508,47 @@ impl<'a> Parser<'a> {
1050810508
}
1050910509
rewrite_projection
1051010510
} else {
10511+
// `align` not found, validate `range_fn`, report an error if it contains `fill`.
10512+
10513+
let align_fill_validate = |expr: &Expr| {
10514+
rewrite_calculation_expr(expr, true, &mut |e: &Expr| match e {
10515+
Expr::Function(func) => {
10516+
if let Some(name) = func.name.0.first() {
10517+
if name.value.as_str() == "range_fn" {
10518+
let FunctionArguments::List(args) = &func.args else {
10519+
unreachable!()
10520+
};
10521+
if let Some(FunctionArg::Unnamed(FunctionArgExpr::Expr(
10522+
Expr::Value(Value::SingleQuotedString(value)),
10523+
))) = args.args.last()
10524+
{
10525+
if !value.is_empty() {
10526+
return Err(ParserError::ParserError(
10527+
"ALIGN argument cannot be omitted in the range select query".into(),
10528+
));
10529+
}
10530+
}
10531+
}
10532+
}
10533+
Ok(None)
10534+
}
10535+
_ => Ok(None),
10536+
})
10537+
};
10538+
10539+
projection
10540+
.iter()
10541+
.map(|select_item| {
10542+
match select_item {
10543+
SelectItem::UnnamedExpr(expr) => {
10544+
align_fill_validate(expr)?;
10545+
}
10546+
_ => {}
10547+
}
10548+
Ok(())
10549+
})
10550+
.collect::<Result<Vec<()>, ParserError>>()?;
10551+
1051110552
projection
1051210553
};
1051310554

@@ -14350,7 +14391,7 @@ where
1435014391
Ok(())
1435114392
}
1435214393

14353-
fn collect_column_from_expr(expr: &Expr, columns: &mut HashSet<Expr>, remove: bool) {
14394+
fn collect_column_from_expr(expr: &Expr, columns: &mut BTreeSet<Expr>, remove: bool) {
1435414395
let _ = walk_expr(expr, &mut |e| {
1435514396
if matches!(e, Expr::CompoundIdentifier(_) | Expr::Identifier(_)) {
1435614397
if remove {

0 commit comments

Comments
 (0)