Skip to content

Commit 5333150

Browse files
committed
readyset-sql: Convert UPPER and LOWER
We don't currently support COLLATE in the argument, and both nom-sql and sqlparser-rs will error during parsing/conversion if it's encountered. Change-Id: Idcf919ee24f25a066a236c74f4a28057aa925fa7
1 parent b00f8d2 commit 5333150

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

readyset-sql/src/ast/expression.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ impl TryFromDialect<sqlparser::ast::Expr> for Expr {
832832
field,
833833
syntax: _, // We only support FROM
834834
expr,
835-
} => Ok(Self::Call(crate::ast::FunctionExpr::Extract {
835+
} => Ok(Self::Call(FunctionExpr::Extract {
836836
field: field.into(),
837837
expr: expr.try_into_dialect(dialect)?,
838838
})),
@@ -1048,7 +1048,7 @@ impl FromDialect<sqlparser::ast::Ident> for Expr {
10481048

10491049
/// Convert a function call into an expression.
10501050
///
1051-
/// We don't turn every function into a [`crate::ast::FunctionExpr`], beacuse we have some special
1051+
/// We don't turn every function into a [`FunctionExpr`], beacuse we have some special
10521052
/// cases that turn into other kinds of expressions, such as `DATE(x)` into `CAST(x AS DATE)`.
10531053
impl TryFromDialect<sqlparser::ast::Function> for Expr {
10541054
fn try_from_dialect(
@@ -1071,7 +1071,7 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
10711071
FunctionArguments::List(FunctionArgumentList { args, .. })
10721072
if args == vec![FunctionArg::Unnamed(FunctionArgExpr::Wildcard)] =>
10731073
{
1074-
return Ok(Self::Call(crate::ast::FunctionExpr::CountStar));
1074+
return Ok(Self::Call(FunctionExpr::CountStar));
10751075
}
10761076
_ => {}
10771077
}
@@ -1100,22 +1100,22 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
11001100
};
11011101
Ok(match name_lowercase.as_str() {
11021102
// TODO: fix this unnecessary cloning
1103-
"avg" => Self::Call(crate::ast::FunctionExpr::Avg {
1103+
"avg" => Self::Call(FunctionExpr::Avg {
11041104
expr: Box::new(exprs[0].clone()),
11051105
distinct,
11061106
}),
11071107
// TODO: check for `count(*)` which we have a separate enum variant for
1108-
"count" => Self::Call(crate::ast::FunctionExpr::Count {
1108+
"count" => Self::Call(FunctionExpr::Count {
11091109
expr: Box::new(exprs[0].clone()),
11101110
distinct,
11111111
}),
1112-
"group_concat" => Self::Call(crate::ast::FunctionExpr::GroupConcat {
1112+
"group_concat" => Self::Call(FunctionExpr::GroupConcat {
11131113
expr: Box::new(exprs[0].clone()),
11141114
separator,
11151115
}),
1116-
"max" => Self::Call(crate::ast::FunctionExpr::Max(Box::new(exprs[0].clone()))),
1117-
"min" => Self::Call(crate::ast::FunctionExpr::Min(Box::new(exprs[0].clone()))),
1118-
"sum" => Self::Call(crate::ast::FunctionExpr::Sum {
1116+
"max" => Self::Call(FunctionExpr::Max(Box::new(exprs[0].clone()))),
1117+
"min" => Self::Call(FunctionExpr::Min(Box::new(exprs[0].clone()))),
1118+
"sum" => Self::Call(FunctionExpr::Sum {
11191119
expr: Box::new(exprs[0].clone()),
11201120
distinct,
11211121
}),
@@ -1125,7 +1125,18 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
11251125
postgres_style: false,
11261126
},
11271127
"extract" | "substring" => todo!(),
1128-
_ => Self::Call(crate::ast::FunctionExpr::Call {
1128+
// TODO(mvzink): support COLLATE for upper and lower. nom-sql doesn't seem to parse
1129+
// collation here, and in the case of sqlparser-rs we would have to pull it out of the
1130+
// inner expression
1131+
"lower" => Self::Call(FunctionExpr::Lower {
1132+
expr: Box::new(exprs[0].clone()),
1133+
collation: None,
1134+
}),
1135+
"upper" => Self::Call(FunctionExpr::Upper {
1136+
expr: Box::new(exprs[0].clone()),
1137+
collation: None,
1138+
}),
1139+
_ => Self::Call(FunctionExpr::Call {
11291140
name: name.into_dialect(dialect),
11301141
arguments: exprs,
11311142
}),

0 commit comments

Comments
 (0)