Skip to content

Commit fc6b0b7

Browse files
killme2008MichaelScofield
authored andcommitted
fix: the align in range query must exist (#17)
1 parent 2751be1 commit fc6b0b7

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
@@ -12158,6 +12158,43 @@ impl<'a> Parser<'a> {
1215812158
}
1215912159
rewrite_projection
1216012160
} else {
12161+
// `align` not found, report an error if the projection contains `range_fn` but without rewriting them.
12162+
12163+
let align_fill_validate = |expr: &Expr| {
12164+
rewrite_calculation_expr(expr, true, &mut |e: &Expr| match e {
12165+
Expr::Function(func) => {
12166+
if let Some(name) = func.name.0.first() {
12167+
if name.value.as_str() == "range_fn" {
12168+
let FunctionArguments::List(args) = &func.args else {
12169+
unreachable!()
12170+
};
12171+
12172+
if args.args.len() < 5 {
12173+
return Err(ParserError::ParserError(
12174+
"ALIGN argument cannot be omitted in the range select query".into(),
12175+
));
12176+
}
12177+
}
12178+
}
12179+
Ok(None)
12180+
}
12181+
_ => Ok(None),
12182+
})
12183+
};
12184+
12185+
projection
12186+
.iter()
12187+
.map(|select_item| {
12188+
match select_item {
12189+
SelectItem::UnnamedExpr(expr) => {
12190+
align_fill_validate(expr)?;
12191+
}
12192+
_ => {}
12193+
}
12194+
Ok(())
12195+
})
12196+
.collect::<Result<Vec<()>, ParserError>>()?;
12197+
1216112198
projection
1216212199
};
1216312200

0 commit comments

Comments
 (0)