mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-19 06:20:38 +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:
@@ -13,6 +13,7 @@ use common_query::prelude::ScalarUdf;
|
||||
use common_recordbatch::{EmptyRecordBatchStream, SendableRecordBatchStream};
|
||||
use common_telemetry::timer;
|
||||
use snafu::{OptionExt, ResultExt};
|
||||
use sql::statements::statement::Statement;
|
||||
use sql::{dialect::GenericDialect, parser::ParserContext};
|
||||
|
||||
pub use crate::datafusion::catalog_adapter::DfCatalogListAdapter;
|
||||
@@ -50,15 +51,25 @@ impl QueryEngine for DatafusionQueryEngine {
|
||||
"datafusion"
|
||||
}
|
||||
|
||||
fn sql_to_plan(&self, sql: &str) -> Result<LogicalPlan> {
|
||||
let _timer = timer!(metric::METRIC_PARSE_SQL_ELAPSED);
|
||||
let context_provider = DfContextProviderAdapter::new(self.state.clone());
|
||||
let planner = DfPlanner::new(&context_provider);
|
||||
fn sql_to_statement(&self, sql: &str) -> Result<Statement> {
|
||||
let mut statement = ParserContext::create_with_dialect(sql, &GenericDialect {})
|
||||
.context(error::ParseSqlSnafu)?;
|
||||
// TODO(dennis): supports multi statement in one sql?
|
||||
assert!(1 == statement.len());
|
||||
planner.statement_to_plan(statement.remove(0))
|
||||
Ok(statement.remove(0))
|
||||
}
|
||||
|
||||
fn statement_to_plan(&self, stmt: Statement) -> Result<LogicalPlan> {
|
||||
let context_provider = DfContextProviderAdapter::new(self.state.clone());
|
||||
let planner = DfPlanner::new(&context_provider);
|
||||
|
||||
planner.statement_to_plan(stmt)
|
||||
}
|
||||
|
||||
fn sql_to_plan(&self, sql: &str) -> Result<LogicalPlan> {
|
||||
let _timer = timer!(metric::METRIC_PARSE_SQL_ELAPSED);
|
||||
let stmt = self.sql_to_statement(sql)?;
|
||||
self.statement_to_plan(stmt)
|
||||
}
|
||||
|
||||
async fn execute(&self, plan: &LogicalPlan) -> Result<Output> {
|
||||
|
||||
@@ -48,9 +48,7 @@ where
|
||||
todo!("Currently not supported")
|
||||
}
|
||||
Statement::Query(qb) => self.query_to_plan(qb),
|
||||
Statement::Insert(_) => {
|
||||
todo!()
|
||||
}
|
||||
Statement::Insert(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use std::sync::Arc;
|
||||
use common_function::scalars::{FunctionRef, FUNCTION_REGISTRY};
|
||||
use common_query::prelude::ScalarUdf;
|
||||
use common_recordbatch::SendableRecordBatchStream;
|
||||
use sql::statements::statement::Statement;
|
||||
|
||||
use crate::catalog::CatalogList;
|
||||
use crate::datafusion::DatafusionQueryEngine;
|
||||
@@ -24,6 +25,10 @@ pub enum Output {
|
||||
pub trait QueryEngine: Send + Sync {
|
||||
fn name(&self) -> &str;
|
||||
|
||||
fn sql_to_statement(&self, sql: &str) -> Result<Statement>;
|
||||
|
||||
fn statement_to_plan(&self, stmt: Statement) -> Result<LogicalPlan>;
|
||||
|
||||
fn sql_to_plan(&self, sql: &str) -> Result<LogicalPlan>;
|
||||
|
||||
async fn execute(&self, plan: &LogicalPlan) -> Result<Output>;
|
||||
|
||||
Reference in New Issue
Block a user