feat: execute "delete" in query engine (in the form of "LogicalPlan") (#1222)

fix: execute "delete" in query engine (in the form of "LogicalPlan")
This commit is contained in:
LFC
2023-03-24 12:11:58 +08:00
committed by GitHub
parent f1139fba59
commit 92963b9614
16 changed files with 179 additions and 336 deletions

View File

@@ -31,7 +31,7 @@ impl<'a> ParserContext<'a> {
match spstatement {
SpStatement::Delete { .. } => {
Ok(Statement::Delete(Box::new(Delete::try_from(spstatement)?)))
Ok(Statement::Delete(Box::new(Delete { inner: spstatement })))
}
unexp => error::UnsupportedSnafu {
sql: self.sql.to_string(),

View File

@@ -12,58 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use sqlparser::ast::{Expr, ObjectName, Statement, TableFactor};
use crate::error::{Error, InvalidSqlSnafu, Result};
use sqlparser::ast::Statement;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Delete {
table_name: ObjectName,
selection: Option<Expr>,
}
impl Delete {
pub fn table_name(&self) -> &ObjectName {
&self.table_name
}
pub fn selection(&self) -> &Option<Expr> {
&self.selection
}
}
impl TryFrom<Statement> for Delete {
type Error = Error;
fn try_from(stmt: Statement) -> Result<Self> {
match stmt {
Statement::Delete {
table_name,
using,
selection,
returning,
} => {
if using.is_some() || returning.is_some() {
return InvalidSqlSnafu {
msg: "delete sql isn't support using and returning.".to_string(),
}
.fail();
}
match table_name {
TableFactor::Table { name, .. } => Ok(Delete {
table_name: name,
selection,
}),
_ => InvalidSqlSnafu {
msg: "can't find table name, tableFactor is not Table type".to_string(),
}
.fail(),
}
}
unexp => InvalidSqlSnafu {
msg: format!("Not expected to be {unexp}"),
}
.fail(),
}
}
pub inner: Statement,
}

View File

@@ -80,6 +80,7 @@ impl TryFrom<&Statement> for DfStatement {
Statement::Query(query) => SpStatement::Query(Box::new(query.inner.clone())),
Statement::Explain(explain) => explain.inner.clone(),
Statement::Insert(insert) => insert.inner.clone(),
Statement::Delete(delete) => delete.inner.clone(),
_ => {
return ConvertToDfStatementSnafu {
statement: format!("{s:?}"),