mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-26 09:50:40 +00:00
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:
@@ -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(),
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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:?}"),
|
||||
|
||||
Reference in New Issue
Block a user