Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump up sqlparser crate version from 0.11 to 0.13 #479

Merged
merged 4 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ iter-enum = "1"
itertools = "0.10"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sqlparser = { version = "0.11", features = ["serde", "bigdecimal"] }
sqlparser = { version = "0.13", features = ["serde", "bigdecimal"] }
thiserror = "1.0"
strum_macros = "0.23"
uuid = { version = "0.8", features = ["v4"] }
Expand Down
12 changes: 12 additions & 0 deletions core/src/translate/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ pub enum TranslateError {
#[error("unimplemented - composite index is not supported")]
CompositeIndexNotSupported,

#[error("unimplemented - join on update not supported")]
JoinOnUpdateNotSupported,

#[error("unimplemented - compound identifier on update not supported: {0}")]
CompoundIdentOnUpdateNotSupported(String),

#[error("too many params in drop index")]
TooManyParamsInDropIndex,

Expand Down Expand Up @@ -59,6 +65,9 @@ pub enum TranslateError {
#[error("unreachable unary operator: {0}")]
UnreachableUnaryOperator(String),

#[error("unreachable empty ident")]
UnreachableEmptyIdent,

#[error("unsupported binary operator: {0}")]
UnsupportedBinaryOperator(String),

Expand All @@ -79,4 +88,7 @@ pub enum TranslateError {

#[error("unsupported alter table operation: {0}")]
UnsupportedAlterTableOperation(String),

#[error("unsupported table factor: {0}")]
UnsupportedTableFactor(String),
}
27 changes: 24 additions & 3 deletions core/src/translate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use self::{

#[cfg(feature = "alter-table")]
use ddl::translate_alter_table_operation;
use sqlparser::ast::{TableFactor, TableWithJoins};

#[cfg(feature = "metadata")]
use crate::ast::Variable;
Expand Down Expand Up @@ -44,12 +45,12 @@ pub fn translate(sql_statement: &SqlStatement) -> Result<Statement> {
source: translate_query(source).map(Box::new)?,
}),
SqlStatement::Update {
table_name,
table,
assignments,
selection,
..
} => Ok(Statement::Update {
table_name: translate_object_name(table_name),
table_name: translate_table_with_join(table)?,
assignments: assignments
.iter()
.map(translate_assignment)
Expand Down Expand Up @@ -155,12 +156,32 @@ pub fn translate(sql_statement: &SqlStatement) -> Result<Statement> {
fn translate_assignment(sql_assignment: &SqlAssignment) -> Result<Assignment> {
let SqlAssignment { id, value } = sql_assignment;

if id.len() > 1 {
return Err(
TranslateError::CompoundIdentOnUpdateNotSupported(sql_assignment.to_string()).into(),
);
}

Ok(Assignment {
id: id.value.to_owned(),
id: id
.get(0)
.ok_or(TranslateError::UnreachableEmptyIdent)?
.value
.to_owned(),
value: translate_expr(value)?,
})
}

fn translate_table_with_join(table: &TableWithJoins) -> Result<ObjectName> {
if !table.joins.is_empty() {
return Err(TranslateError::JoinOnUpdateNotSupported.into());
}
match &table.relation {
TableFactor::Table { name, .. } => Ok(translate_object_name(name)),
t => Err(TranslateError::UnsupportedTableFactor(t.to_string()).into()),
}
}

fn translate_object_name(sql_object_name: &SqlObjectName) -> ObjectName {
ObjectName(translate_idents(&sql_object_name.0))
}
Expand Down
12 changes: 12 additions & 0 deletions test-suite/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ test_case!(error, async move {
TranslateError::UnsupportedJoinOperator("CrossJoin".to_owned()).into(),
"SELECT * FROM TableA CROSS JOIN TableA as A;",
),
(
TranslateError::JoinOnUpdateNotSupported.into(),
"UPDATE TableA INNER JOIN TableA ON 1 = 1 SET 1 = 1",
),
(
TranslateError::UnsupportedTableFactor("(SELECT * FROM TableA)".to_owned()).into(),
"UPDATE (SELECT * FROM TableA) SET 1 = 1",
),
(
TranslateError::CompoundIdentOnUpdateNotSupported("TableA.id = 1".to_owned()).into(),
"UPDATE TableA SET TableA.id = 1 WHERE id = 1",
),
(
EvaluateError::NestedSelectRowNotFound.into(),
"SELECT * FROM TableA WHERE id = (SELECT id FROM TableA WHERE id = 2);",
Expand Down