Skip to content

Commit 71105cd

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 5146a62 commit 71105cd

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
@@ -866,7 +866,7 @@ impl TryFromDialect<sqlparser::ast::Expr> for Expr {
866866
field,
867867
syntax: _, // We only support FROM
868868
expr,
869-
} => Ok(Self::Call(crate::ast::FunctionExpr::Extract {
869+
} => Ok(Self::Call(FunctionExpr::Extract {
870870
field: field.into(),
871871
expr: expr.try_into_dialect(dialect)?,
872872
})),
@@ -1078,7 +1078,7 @@ impl FromDialect<sqlparser::ast::Ident> for Expr {
10781078

10791079
/// Convert a function call into an expression.
10801080
///
1081-
/// We don't turn every function into a [`crate::ast::FunctionExpr`], beacuse we have some special
1081+
/// We don't turn every function into a [`FunctionExpr`], beacuse we have some special
10821082
/// cases that turn into other kinds of expressions, such as `DATE(x)` into `CAST(x AS DATE)`.
10831083
impl TryFromDialect<sqlparser::ast::Function> for Expr {
10841084
fn try_from_dialect(
@@ -1101,7 +1101,7 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
11011101
FunctionArguments::List(FunctionArgumentList { args, .. })
11021102
if args == vec![FunctionArg::Unnamed(FunctionArgExpr::Wildcard)] =>
11031103
{
1104-
return Ok(Self::Call(crate::ast::FunctionExpr::CountStar));
1104+
return Ok(Self::Call(FunctionExpr::CountStar));
11051105
}
11061106
_ => {}
11071107
}
@@ -1128,22 +1128,22 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
11281128
};
11291129
Ok(match name_lowercase.as_str() {
11301130
// TODO: fix this unnecessary cloning
1131-
"avg" => Self::Call(crate::ast::FunctionExpr::Avg {
1131+
"avg" => Self::Call(FunctionExpr::Avg {
11321132
expr: Box::new(exprs[0].clone()),
11331133
distinct,
11341134
}),
11351135
// TODO: check for `count(*)` which we have a separate enum variant for
1136-
"count" => Self::Call(crate::ast::FunctionExpr::Count {
1136+
"count" => Self::Call(FunctionExpr::Count {
11371137
expr: Box::new(exprs[0].clone()),
11381138
distinct,
11391139
}),
1140-
"group_concat" => Self::Call(crate::ast::FunctionExpr::GroupConcat {
1140+
"group_concat" => Self::Call(FunctionExpr::GroupConcat {
11411141
expr: Box::new(exprs[0].clone()),
11421142
separator,
11431143
}),
1144-
"max" => Self::Call(crate::ast::FunctionExpr::Max(Box::new(exprs[0].clone()))),
1145-
"min" => Self::Call(crate::ast::FunctionExpr::Min(Box::new(exprs[0].clone()))),
1146-
"sum" => Self::Call(crate::ast::FunctionExpr::Sum {
1144+
"max" => Self::Call(FunctionExpr::Max(Box::new(exprs[0].clone()))),
1145+
"min" => Self::Call(FunctionExpr::Min(Box::new(exprs[0].clone()))),
1146+
"sum" => Self::Call(FunctionExpr::Sum {
11471147
expr: Box::new(exprs[0].clone()),
11481148
distinct,
11491149
}),
@@ -1153,7 +1153,18 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
11531153
postgres_style: false,
11541154
},
11551155
"extract" | "substring" => todo!(),
1156-
_ => Self::Call(crate::ast::FunctionExpr::Call {
1156+
// TODO(mvzink): support COLLATE for upper and lower. nom-sql doesn't seem to parse
1157+
// collation here, and in the case of sqlparser-rs we would have to pull it out of the
1158+
// inner expression
1159+
"lower" => Self::Call(FunctionExpr::Lower {
1160+
expr: Box::new(exprs[0].clone()),
1161+
collation: None,
1162+
}),
1163+
"upper" => Self::Call(FunctionExpr::Upper {
1164+
expr: Box::new(exprs[0].clone()),
1165+
collation: None,
1166+
}),
1167+
_ => Self::Call(FunctionExpr::Call {
11571168
name: name.into_dialect(dialect),
11581169
arguments: exprs,
11591170
}),

0 commit comments

Comments
 (0)