Skip to content

Commit 00e6e6f

Browse files
committed
readyset-sql: Implement conversion of sqlparser ROW syntax
This was missing but tested by a readyset-sql-passes test which hadn't been converted away from nom-sql (fixed in a forthcoming patch). Change-Id: I6a6a6964854c7d3c647552b315f75b8989240e61 Reviewed-on: https://gerrit.readyset.name/c/readyset/+/9665 Reviewed-by: Mohamed Yasser Abdelhamed Abdeen <[email protected]> Tested-by: Buildkite CI
1 parent 054434f commit 00e6e6f

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

readyset-sql-parsing/tests/parity.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,8 @@ fn test_create_table_with_data_directory_option() {
524524
DEFAULT CHARSET=utf8mb4;"#
525525
);
526526
}
527+
528+
#[test]
529+
fn test_row() {
530+
check_parse_both!(r#"SELECT ROW(1, 2, 3);"#);
531+
}

readyset-sql/src/ast/expression.rs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,27 +1339,34 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
13391339
expr: next_expr()?,
13401340
distinct,
13411341
})
1342-
} else if ident.value.eq_ignore_ascii_case("GROUP_CONCAT") {
1343-
Self::Call(FunctionExpr::GroupConcat {
1344-
expr: next_expr()?,
1345-
separator,
1346-
})
1347-
} else if ident.value.eq_ignore_ascii_case("MAX") {
1348-
Self::Call(FunctionExpr::Max(next_expr()?))
1349-
} else if ident.value.eq_ignore_ascii_case("MIN") {
1350-
Self::Call(FunctionExpr::Min(next_expr()?))
1351-
} else if ident.value.eq_ignore_ascii_case("SUM") {
1352-
Self::Call(FunctionExpr::Sum {
1353-
expr: next_expr()?,
1354-
distinct,
1355-
})
13561342
} else if ident.value.eq_ignore_ascii_case("DATE") {
13571343
// TODO: Arguably, this should be in a SQL rewrite pass to preserve input when rendering
13581344
Self::Cast {
13591345
expr: next_expr()?,
13601346
ty: crate::ast::SqlType::Date,
13611347
postgres_style: false,
13621348
}
1349+
} else if ident.value.eq_ignore_ascii_case("EXTRACT") {
1350+
return failed!("{ident} should have been converted earlier");
1351+
} else if ident.value.eq_ignore_ascii_case("GROUP_CONCAT") {
1352+
Self::Call(FunctionExpr::GroupConcat {
1353+
expr: next_expr()?,
1354+
separator,
1355+
})
1356+
} else if ident.value.eq_ignore_ascii_case("JSON_OBJECT_AGG") {
1357+
Self::Call(FunctionExpr::JsonObjectAgg {
1358+
key: next_expr()?,
1359+
value: next_expr()?,
1360+
allow_duplicate_keys: true,
1361+
})
1362+
} else if ident.value.eq_ignore_ascii_case("JSONB_OBJECT_AGG")
1363+
|| ident.value.eq_ignore_ascii_case("JSON_OBJECTAGG")
1364+
{
1365+
Self::Call(FunctionExpr::JsonObjectAgg {
1366+
key: next_expr()?,
1367+
value: next_expr()?,
1368+
allow_duplicate_keys: false,
1369+
})
13631370
} else if ident.value.eq_ignore_ascii_case("LOWER") {
13641371
let expr = next_expr()?;
13651372
match *expr {
@@ -1372,6 +1379,20 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
13721379
collation: None,
13731380
}),
13741381
}
1382+
} else if ident.value.eq_ignore_ascii_case("MAX") {
1383+
Self::Call(FunctionExpr::Max(next_expr()?))
1384+
} else if ident.value.eq_ignore_ascii_case("MIN") {
1385+
Self::Call(FunctionExpr::Min(next_expr()?))
1386+
} else if ident.value.eq_ignore_ascii_case("ROW") {
1387+
Self::Row {
1388+
explicit: true,
1389+
exprs: exprs.try_collect()?,
1390+
}
1391+
} else if ident.value.eq_ignore_ascii_case("SUM") {
1392+
Self::Call(FunctionExpr::Sum {
1393+
expr: next_expr()?,
1394+
distinct,
1395+
})
13751396
} else if ident.value.eq_ignore_ascii_case("UPPER") {
13761397
let expr = next_expr()?;
13771398
match *expr {
@@ -1384,22 +1405,6 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
13841405
collation: None,
13851406
}),
13861407
}
1387-
} else if ident.value.eq_ignore_ascii_case("JSON_OBJECT_AGG") {
1388-
Self::Call(FunctionExpr::JsonObjectAgg {
1389-
key: next_expr()?,
1390-
value: next_expr()?,
1391-
allow_duplicate_keys: true,
1392-
})
1393-
} else if ident.value.eq_ignore_ascii_case("JSONB_OBJECT_AGG")
1394-
|| ident.value.eq_ignore_ascii_case("JSON_OBJECTAGG")
1395-
{
1396-
Self::Call(FunctionExpr::JsonObjectAgg {
1397-
key: next_expr()?,
1398-
value: next_expr()?,
1399-
allow_duplicate_keys: false,
1400-
})
1401-
} else if ident.value.eq_ignore_ascii_case("EXTRACT") {
1402-
return failed!("{ident} should have been converted earlier");
14031408
} else {
14041409
ident.value = ident.value.to_lowercase();
14051410
Self::Call(FunctionExpr::Call {

0 commit comments

Comments
 (0)