Skip to content

Commit 43f3b0e

Browse files
nom-sql: Allow whitespace inside ROW values and some function calls
Previously, nom expected function arguments to appear immediately after the opening parenthesis. As a result, queries with whitespace before the first argument or after the last one would fail to parse. This behavior also affected ROW value expressions. This commit fixes both cases. Fixes: REA-5237 Closes: #1488 Release-Note-Core: Make parser more flexible with whitespaces in function arguments and `IN` list values. Change-Id: Id4d8a8961fa602cfd1583a54c517e0994f1911aa Reviewed-on: https://gerrit.readyset.name/c/readyset/+/9195 Tested-by: Buildkite CI Reviewed-by: Marcelo Altmann <marcelo@readyset.io>
1 parent 49564ef commit 43f3b0e

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

logictests/functions.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ select x, COALESCE(y, 2) FROM t1;
99
----
1010
1
1111
2
12+
13+
query I
14+
SELECT COUNT ( 1 ) FROM t1;
15+
----
16+
1

logictests/where_in.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ select sum(id) from t1 where value in (another, 2);
2121
3
2222

2323
query I ok
24-
select max(id) from t1 where id not in (another, 2);
24+
select max(id) from t1 where id not in ( another, 2 );
2525
----
2626
4
2727

nom-sql/src/common.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ fn agg_fx_args(
107107
) -> impl Fn(LocatedSpan<&[u8]>) -> NomSqlResult<&[u8], (Expr, bool)> {
108108
move |i| {
109109
let (i, _) = whitespace0(i)?;
110-
delimited(tag("("), agg_function_arguments(dialect), tag(")"))(i)
110+
let (i, _) = tag("(")(i)?;
111+
let (i, _) = whitespace0(i)?;
112+
let (i, args) = agg_function_arguments(dialect)(i)?;
113+
let (i, _) = whitespace0(i)?;
114+
let (i, _) = tag(")")(i)?;
115+
Ok((i, args))
111116
}
112117
}
113118

@@ -281,6 +286,7 @@ fn substring(dialect: Dialect) -> impl Fn(LocatedSpan<&[u8]>) -> NomSqlResult<&[
281286
let (i, _) = alt((tag_no_case("substring"), tag_no_case("substr")))(i)?;
282287
let (i, _) = whitespace0(i)?;
283288
let (i, _) = tag("(")(i)?;
289+
let (i, _) = whitespace0(i)?;
284290
let (i, string) = expression(dialect)(i)?;
285291
let (i, pos) = opt(preceded(
286292
tuple((whitespace1, tag_no_case("from"), whitespace1)),

nom-sql/src/expression.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ fn row_expr_implicit(dialect: Dialect) -> impl Fn(LocatedSpan<&[u8]>) -> NomSqlR
792792
move |i| {
793793
// Implicit row exprs must have two or more elements
794794
let (i, _) = tag("(")(i)?;
795+
let (i, _) = whitespace0(i)?;
795796
let (i, first_expr) = expression(dialect)(i)?;
796797
let (i, _) = ws_sep_comma(i)?;
797798
let (i, rest_exprs) = separated_list1(
@@ -801,6 +802,7 @@ fn row_expr_implicit(dialect: Dialect) -> impl Fn(LocatedSpan<&[u8]>) -> NomSqlR
801802
map(bracketed_expr_list(dialect), Expr::Array),
802803
)),
803804
)(i)?;
805+
let (i, _) = whitespace0(i)?;
804806
let (i, _) = tag(")")(i)?;
805807

806808
let mut exprs = Vec::with_capacity(rest_exprs.len() + 1);

0 commit comments

Comments
 (0)