Skip to content

Commit

Permalink
rename to OptdContext
Browse files Browse the repository at this point in the history
  • Loading branch information
connortsui20 committed Mar 2, 2025
1 parent b333d4b commit e321bd5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
6 changes: 3 additions & 3 deletions optd-datafusion/src/converter/from_optd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use optd_core::{
};
use std::{collections::HashMap, str::FromStr, sync::Arc};

use super::OptdDataFusionContext;
use super::OptdContext;

impl OptdDataFusionContext<'_> {
impl OptdContext {
#[async_recursion]
pub(crate) async fn optd_to_df_relational(
&self,
Expand All @@ -44,7 +44,7 @@ impl OptdDataFusionContext<'_> {
// TODO(yuchen): support filters inside table scan.
let filters = vec![];
let plan = provider
.scan(self.session_state, None, &filters, None)
.scan(&self.session_state, None, &filters, None)
.await?;

Ok(plan)
Expand Down
4 changes: 2 additions & 2 deletions optd-datafusion/src/converter/into_optd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use optd_core::{
};
use std::sync::Arc;

use super::OptdDataFusionContext;
use super::OptdContext;

impl OptdDataFusionContext<'_> {
impl OptdContext {
/// Given a DataFusion logical plan, returns an `optd` [`LogicalPlan`].
pub(crate) fn df_to_optd_relational(
&mut self,
Expand Down
27 changes: 19 additions & 8 deletions optd-datafusion/src/converter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
use datafusion::{execution::SessionState, logical_expr::TableSource};
use std::fmt::Debug;
use std::{collections::HashMap, sync::Arc};

pub mod from_optd;
pub mod into_optd;

/// A context for converting between optd and datafusion.
/// The map is used to lookup table sources when converting TableScan operators from optd to datafusion.
pub(crate) struct OptdDataFusionContext<'a> {
/// The map is used to lookup table sources when converting TableScan operators from optd to
/// datafusion.
pub(crate) struct OptdContext {
/// Maps table names to table sources.
pub tables: HashMap<String, Arc<dyn TableSource>>,
tables: HashMap<String, Arc<dyn TableSource>>,
/// DataFusion session state.
pub session_state: &'a SessionState,
session_state: SessionState,
}

impl OptdDataFusionContext<'_> {
impl OptdContext {
/// Creates a new empty `OptdDataFusionContext` with the provided session state.
pub(crate) fn new(session_state: &SessionState) -> OptdDataFusionContext {
OptdDataFusionContext {
pub(crate) fn new(session_state: &SessionState) -> OptdContext {
OptdContext {
tables: HashMap::new(),
session_state,
session_state: session_state.clone(),
}
}
}

impl Debug for OptdContext {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("OptdContext")
.field("tables", &self.tables.keys())
.field("session_state", &self.session_state)
.finish()
}
}
8 changes: 4 additions & 4 deletions optd-datafusion/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::converter::OptdDataFusionContext;
use crate::converter::OptdContext;
use async_trait::async_trait;
use datafusion::{
common::Result as DataFusionResult,
Expand Down Expand Up @@ -111,10 +111,10 @@ impl QueryPlanner for MockOptdOptimizer {
));
}

let mut converter = OptdDataFusionContext::new(session_state);
let mut optd_ctx = OptdContext::new(session_state);

// convert the DataFusion logical plan to `optd`'s version of a `LogicalPlan`.
let logical_plan = converter
let logical_plan = optd_ctx
.df_to_optd_relational(datafusion_logical_plan)
.expect("TODO FIX ERROR HANDLING");

Expand All @@ -125,7 +125,7 @@ impl QueryPlanner for MockOptdOptimizer {
.expect("TODO FIX ERROR HANDLING");

// Convert the output `optd` `PhysicalPlan` to DataFusion's `ExecutionPlan`.
let physical_plan = converter
let physical_plan = optd_ctx
.optd_to_df_relational(&optd_optimized_physical_plan)
.await
.expect("TODO FIX ERROR HANDLING");
Expand Down

0 comments on commit e321bd5

Please sign in to comment.