Skip to content

Commit

Permalink
use datafusion plan_to_sql function instead of expr_to_sql (#106)
Browse files Browse the repository at this point in the history
* use plan_to_sql within SqlTable and SqlExec

* fix the tests
  • Loading branch information
hozan23 authored Oct 11, 2024
1 parent 0397fed commit dc793b1
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 214 deletions.
30 changes: 9 additions & 21 deletions src/duckdb/sql_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,15 @@ impl<T, P> DuckDBTable<T, P> {

fn create_physical_plan(
&self,
projections: Option<&Vec<usize>>,
projection: Option<&Vec<usize>>,
schema: &SchemaRef,
filters: &[Expr],
limit: Option<usize>,
sql: String,
) -> DataFusionResult<Arc<dyn ExecutionPlan>> {
Ok(Arc::new(DuckSqlExec::new(
projections,
projection,
schema,
&self.base_table.table_reference,
self.base_table.clone_pool(),
filters,
limit,
sql,
self.table_functions.clone(),
)?))
}
Expand Down Expand Up @@ -98,7 +95,8 @@ impl<T, P> TableProvider for DuckDBTable<T, P> {
filters: &[Expr],
limit: Option<usize>,
) -> DataFusionResult<Arc<dyn ExecutionPlan>> {
return self.create_physical_plan(projection, &self.schema(), filters, limit);
let sql = self.base_table.scan_to_sql(projection, filters, limit)?;
return self.create_physical_plan(projection, &self.schema(), sql);
}
}

Expand All @@ -116,23 +114,13 @@ struct DuckSqlExec<T, P> {

impl<T, P> DuckSqlExec<T, P> {
fn new(
projections: Option<&Vec<usize>>,
projection: Option<&Vec<usize>>,
schema: &SchemaRef,
table_reference: &TableReference,
pool: Arc<dyn DbConnectionPool<T, P> + Send + Sync>,
filters: &[Expr],
limit: Option<usize>,
sql: String,
table_functions: Option<HashMap<String, String>>,
) -> DataFusionResult<Self> {
let base_exec = SqlExec::new(
projections,
schema,
table_reference,
pool,
filters,
limit,
Some(Engine::DuckDB),
)?;
let base_exec = SqlExec::new(projection, schema, pool, sql)?;

Ok(Self {
base_exec,
Expand Down
Loading

0 comments on commit dc793b1

Please sign in to comment.