Skip to content

Commit 0441a2b

Browse files
committed
readyset-sql: Update expression conversion with MySQL CAST support
See relevant sqlparser [PR]. [PR]: apache/datafusion-sqlparser-rs#1739 Change-Id: I11a01b48f1649c6530cdbe7bd23c158e9fe4f888
1 parent ca3070b commit 0441a2b

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

readyset-sql/src/ast/expression.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,25 @@ impl From<sqlparser::ast::BinaryOperator> for BinaryOperator {
443443
BinOp::Question => todo!(),
444444
BinOp::QuestionAnd => Self::QuestionMarkAnd,
445445
BinOp::QuestionPipe => Self::QuestionMarkPipe,
446-
BinOp::Spaceship => unimplemented!("<=> {value:?}"),
446+
BinOp::Spaceship => todo!(),
447447
BinOp::StringConcat => todo!(),
448448
BinOp::Xor => todo!(),
449+
BinOp::DoubleHash => todo!(),
450+
BinOp::LtDashGt => todo!(),
451+
BinOp::AndLt => todo!(),
452+
BinOp::AndGt => todo!(),
453+
BinOp::LtLtPipe => todo!(),
454+
BinOp::PipeGtGt => todo!(),
455+
BinOp::AndLtPipe => todo!(),
456+
BinOp::PipeAndGt => todo!(),
457+
BinOp::LtCaret => todo!(),
458+
BinOp::GtCaret => todo!(),
459+
BinOp::QuestionHash => todo!(),
460+
BinOp::QuestionDash => todo!(),
461+
BinOp::QuestionDashPipe => todo!(),
462+
BinOp::QuestionDoublePipe => todo!(),
463+
BinOp::At => todo!(),
464+
BinOp::TildeEq => todo!(),
449465
}
450466
}
451467
}
@@ -496,20 +512,27 @@ pub enum UnaryOperator {
496512
Not,
497513
}
498514

499-
impl From<sqlparser::ast::UnaryOperator> for UnaryOperator {
500-
fn from(value: sqlparser::ast::UnaryOperator) -> Self {
515+
impl TryFrom<sqlparser::ast::UnaryOperator> for UnaryOperator {
516+
type Error = AstConversionError;
517+
518+
fn try_from(value: sqlparser::ast::UnaryOperator) -> Result<Self, Self::Error> {
501519
use sqlparser::ast::UnaryOperator as UnOp;
502520
match value {
503-
UnOp::Plus => todo!(),
504-
UnOp::Minus => Self::Neg,
505-
UnOp::Not => Self::Not,
521+
UnOp::Plus => not_yet_implemented!("Unary + operator"),
522+
UnOp::Minus => Ok(Self::Neg),
523+
UnOp::Not => Ok(Self::Not),
506524
UnOp::PGBitwiseNot
507525
| UnOp::PGSquareRoot
508526
| UnOp::PGCubeRoot
509527
| UnOp::PGPostfixFactorial
510528
| UnOp::PGPrefixFactorial
511-
| UnOp::PGAbs => unimplemented!("unsupported postgres unary operator"),
512-
UnOp::BangNot => unimplemented!("unsupported bang not (!)"),
529+
| UnOp::PGAbs => unsupported!("unsupported postgres unary operator"),
530+
UnOp::BangNot
531+
| UnOp::Hash
532+
| UnOp::AtDashAt
533+
| UnOp::DoubleAt
534+
| UnOp::QuestionDash
535+
| UnOp::QuestionPipe => unsupported!("unsupported unary operator {value}"),
513536
}
514537
}
515538
}
@@ -796,6 +819,7 @@ impl TryFromDialect<sqlparser::ast::Expr> for Expr {
796819
expr,
797820
data_type,
798821
format: _, // TODO: I think this is where we would support `AT TIMEZONE` syntax
822+
mysql_style_int: _, // TODO: We render this incorrectly
799823
} => Ok(Self::Cast {
800824
expr: expr.try_into_dialect(dialect)?,
801825
ty: data_type.try_into_dialect(dialect)?,
@@ -1002,7 +1026,7 @@ impl TryFromDialect<sqlparser::ast::Expr> for Expr {
10021026
}),
10031027
},
10041028
UnaryOp { op, expr } => Ok(Self::UnaryOp {
1005-
op: op.into(),
1029+
op: op.try_into()?,
10061030
rhs: expr.try_into_dialect(dialect)?,
10071031
}),
10081032
Value(value) => Ok(Self::Literal(value.try_into()?)),

readyset-sql/src/ast/sql_type.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ impl TryFromDialect<sqlparser::ast::DataType> for crate::ast::SqlType {
262262
Trigger => skipped!("TRIGGER"),
263263
AnyType => unsupported!("ANY TYPE"),
264264
Table(_column_definition_list) => unsupported!("TABLE type"),
265+
GeometricType(geometric_type_kind) => {
266+
unsupported!("geometric type {geometric_type_kind}")
267+
}
265268
}
266269
}
267270
}

0 commit comments

Comments
 (0)