mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-13 16:52:56 +00:00
TableEngine and SqlHandler impl (#45)
* Impl TableEngine, bridge to storage * Impl sql handler to process insert sql * fix: minor changes and typo * test: add datanode test * test: add table-engine test * fix: code style * refactor: split out insert mod from sql and minor changes by CR * refactor: replace with_context with context
This commit is contained in:
@@ -1 +1,2 @@
|
||||
|
||||
pub use sqlparser::ast::Expr;
|
||||
pub use sqlparser::ast::Value;
|
||||
|
||||
@@ -1,12 +1,56 @@
|
||||
use sqlparser::ast::Statement;
|
||||
use sqlparser::ast::{SetExpr, Statement, Values};
|
||||
use sqlparser::parser::ParserError;
|
||||
|
||||
use crate::ast::{Expr, Value};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Insert {
|
||||
// Can only be sqlparser::ast::Statement::Insert variant
|
||||
pub inner: Statement,
|
||||
}
|
||||
|
||||
impl Insert {
|
||||
pub fn table_name(&self) -> String {
|
||||
match &self.inner {
|
||||
Statement::Insert { table_name, .. } => {
|
||||
// FIXME(dennis): table_name may be in the form of "catalog.schema.table"
|
||||
table_name.to_string()
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn columns(&self) -> Vec<&String> {
|
||||
match &self.inner {
|
||||
Statement::Insert { columns, .. } => columns.iter().map(|ident| &ident.value).collect(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn values(&self) -> Vec<Vec<Value>> {
|
||||
match &self.inner {
|
||||
Statement::Insert { source, .. } => match &source.body {
|
||||
SetExpr::Values(Values(values)) => values
|
||||
.iter()
|
||||
.map(|v| {
|
||||
v.iter()
|
||||
.map(|expr| match expr {
|
||||
Expr::Value(v) => v.clone(),
|
||||
Expr::Identifier(ident) => {
|
||||
Value::SingleQuotedString(ident.value.clone())
|
||||
}
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.collect::<Vec<Value>>()
|
||||
})
|
||||
.collect(),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Statement> for Insert {
|
||||
type Error = ParserError;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user