Skip to content

Commit

Permalink
datafusion-federation: Use the Dialect and Unparser constructor when …
Browse files Browse the repository at this point in the history
…using the plan_to_sql function. (#105)
  • Loading branch information
hozan23 authored Jan 20, 2025
1 parent d52fb9d commit 9150eda
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions datafusion-federation/src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use datafusion::{
SendableRecordBatchStream,
},
sql::{
sqlparser::ast::Statement,
unparser::{plan_to_sql, Unparser},
TableReference,
},
Expand Down Expand Up @@ -698,15 +699,19 @@ impl VirtualExecutionPlan {
fn sql(&self) -> Result<String> {
// Find all table scans, recover the SQLTableSource, find the remote table name and replace the name of the TableScan table.
let mut known_rewrites = HashMap::new();
let mut ast = Unparser::new(self.executor.dialect().as_ref())
.plan_to_sql(&rewrite_table_scans(&self.plan, &mut known_rewrites)?)?;
let plan = &rewrite_table_scans(&self.plan, &mut known_rewrites)?;
let mut ast = self.plan_to_sql(plan)?;

if let Some(analyzer) = self.executor.ast_analyzer() {
ast = analyzer(ast)?;
}

Ok(format!("{ast}"))
}

fn plan_to_sql(&self, plan: &LogicalPlan) -> Result<Statement> {
Unparser::new(self.executor.dialect().as_ref()).plan_to_sql(plan)
}
}

impl DisplayAs for VirtualExecutionPlan {
Expand Down Expand Up @@ -758,9 +763,7 @@ impl ExecutionPlan for VirtualExecutionPlan {
_partition: usize,
_context: Arc<TaskContext>,
) -> Result<SendableRecordBatchStream> {
let ast = plan_to_sql(&self.plan)?;
let query = format!("{ast}");

let query = self.plan_to_sql(&self.plan)?.to_string();
self.executor.execute(query.as_str(), self.schema())
}

Expand Down

0 comments on commit 9150eda

Please sign in to comment.