Skip to content

Commit aad3a4e

Browse files
committed
readyset-sql: Convert SUBSTRING function
That's all the functions we support right now. Change-Id: I8e2e10c17bc598d1d65e6b245a2cde97dcf919ee
1 parent 71105cd commit aad3a4e

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

readyset-sql/src/ast/expression.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -989,11 +989,19 @@ impl TryFromDialect<sqlparser::ast::Expr> for Expr {
989989
} => unsupported!("STRUCT"),
990990
Subquery(_query) => not_yet_implemented!("subquery"),
991991
Substring {
992-
expr: _,
993-
substring_from: _,
994-
substring_for: _,
992+
expr,
993+
substring_from,
994+
substring_for,
995995
special: _,
996-
} => not_yet_implemented!("SUBSTRING"),
996+
} => Ok(Self::Call(FunctionExpr::Substring {
997+
string: expr.try_into_dialect(dialect)?,
998+
pos: substring_from
999+
.map(|expr| expr.try_into_dialect(dialect))
1000+
.transpose()?,
1001+
len: substring_for
1002+
.map(|expr| expr.try_into_dialect(dialect))
1003+
.transpose()?,
1004+
})),
9971005
Trim {
9981006
expr: _,
9991007
trim_where: _,
@@ -1152,7 +1160,6 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
11521160
ty: crate::ast::SqlType::Date,
11531161
postgres_style: false,
11541162
},
1155-
"extract" | "substring" => todo!(),
11561163
// TODO(mvzink): support COLLATE for upper and lower. nom-sql doesn't seem to parse
11571164
// collation here, and in the case of sqlparser-rs we would have to pull it out of the
11581165
// inner expression
@@ -1164,6 +1171,9 @@ impl TryFromDialect<sqlparser::ast::Function> for Expr {
11641171
expr: Box::new(exprs[0].clone()),
11651172
collation: None,
11661173
}),
1174+
name @ ("extract" | "substring") => {
1175+
return failed!("{name} should have been converted earlier")
1176+
}
11671177
_ => Self::Call(FunctionExpr::Call {
11681178
name: name.into_dialect(dialect),
11691179
arguments: exprs,

0 commit comments

Comments
 (0)