datafusion_federation/sql/
executor.rs1use async_trait::async_trait;
2use core::fmt;
3use datafusion::{
4 arrow::datatypes::SchemaRef, error::Result, physical_plan::SendableRecordBatchStream,
5 sql::sqlparser::ast, sql::unparser::dialect::Dialect,
6};
7use std::sync::Arc;
8
9pub type SQLExecutorRef = Arc<dyn SQLExecutor>;
10pub type AstAnalyzer = Box<dyn Fn(ast::Statement) -> Result<ast::Statement>>;
11
12#[async_trait]
13pub trait SQLExecutor: Sync + Send {
14 fn name(&self) -> &str;
16
17 fn compute_context(&self) -> Option<String>;
25
26 fn dialect(&self) -> Arc<dyn Dialect>;
28
29 fn ast_analyzer(&self) -> Option<AstAnalyzer> {
31 None
32 }
33
34 fn execute(&self, query: &str, schema: SchemaRef) -> Result<SendableRecordBatchStream>;
36
37 async fn table_names(&self) -> Result<Vec<String>>;
39
40 async fn get_table_schema(&self, table_name: &str) -> Result<SchemaRef>;
42}
43
44impl fmt::Debug for dyn SQLExecutor {
45 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
46 write!(f, "{} {:?}", self.name(), self.compute_context())
47 }
48}
49
50impl fmt::Display for dyn SQLExecutor {
51 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
52 write!(f, "{} {:?}", self.name(), self.compute_context())
53 }
54}