Skip to content

Commit

Permalink
Use Slice rather than Vec to access expr planners
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Jul 16, 2024
1 parent 47d090a commit 38b3ff4
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 29 deletions.
4 changes: 0 additions & 4 deletions datafusion-examples/examples/sql_frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ struct MyContextProvider {
}

impl ContextProvider for MyContextProvider {
fn get_expr_planners(&self) -> Vec<Arc<dyn datafusion_expr::planner::ExprPlanner>> {
vec![]
}

fn get_table_source(&self, name: TableReference) -> Result<Arc<dyn TableSource>> {
if name.table() == "person" {
Ok(Arc::new(MyTableSource {
Expand Down
7 changes: 5 additions & 2 deletions datafusion/core/src/execution/session_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ impl SessionState {
let mut provider = SessionContextProvider {
state: self,
tables: HashMap::with_capacity(references.len()),
expr_planners: self.expr_planners(),
};

for reference in references {
Expand Down Expand Up @@ -567,6 +568,7 @@ impl SessionState {
let provider = SessionContextProvider {
state: self,
tables: HashMap::new(),
expr_planners: self.expr_planners(),
};

let query = SqlToRel::new_with_options(&provider, self.get_parser_options());
Expand Down Expand Up @@ -1590,11 +1592,12 @@ impl SessionStateDefaults {
struct SessionContextProvider<'a> {
state: &'a SessionState,
tables: HashMap<String, Arc<dyn TableSource>>,
expr_planners: Vec<Arc<dyn ExprPlanner>>,
}

impl<'a> ContextProvider for SessionContextProvider<'a> {
fn get_expr_planners(&self) -> Vec<Arc<dyn ExprPlanner>> {
self.state.expr_planners()
fn get_expr_planners(&self) -> &[Arc<dyn ExprPlanner>] {
&self.expr_planners
}

fn get_table_source(
Expand Down
4 changes: 0 additions & 4 deletions datafusion/core/tests/optimizer_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ impl MyContextProvider {
}

impl ContextProvider for MyContextProvider {
fn get_expr_planners(&self) -> Vec<Arc<dyn datafusion_expr::planner::ExprPlanner>> {
vec![]
}

fn get_table_source(&self, name: TableReference) -> Result<Arc<dyn TableSource>> {
let table_name = name.table();
if table_name.starts_with("test") {
Expand Down
4 changes: 3 additions & 1 deletion datafusion/expr/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ pub trait ContextProvider {
}

/// Getter for expr planners
fn get_expr_planners(&self) -> Vec<Arc<dyn ExprPlanner>>;
fn get_expr_planners(&self) -> &[Arc<dyn ExprPlanner>] {
&[]
}

/// Getter for a UDF description
fn get_function_meta(&self, name: &str) -> Option<Arc<ScalarUDF>>;
Expand Down
4 changes: 0 additions & 4 deletions datafusion/optimizer/tests/optimizer_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,6 @@ impl MyContextProvider {
}

impl ContextProvider for MyContextProvider {
fn get_expr_planners(&self) -> Vec<Arc<dyn datafusion_expr::planner::ExprPlanner>> {
vec![]
}

fn get_table_source(&self, name: TableReference) -> Result<Arc<dyn TableSource>> {
let table_name = name.table();
if table_name.starts_with("test") {
Expand Down
4 changes: 0 additions & 4 deletions datafusion/sql/examples/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ fn create_table_source(fields: Vec<Field>) -> Arc<dyn TableSource> {
}

impl ContextProvider for MyContextProvider {
fn get_expr_planners(&self) -> Vec<Arc<dyn datafusion_expr::planner::ExprPlanner>> {
vec![]
}

fn get_table_source(&self, name: TableReference) -> Result<Arc<dyn TableSource>> {
match self.tables.get(name.table()) {
Some(table) => Ok(Arc::clone(table)),
Expand Down
6 changes: 0 additions & 6 deletions datafusion/sql/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,12 +979,6 @@ mod tests {
}

impl ContextProvider for TestContextProvider {
fn get_expr_planners(
&self,
) -> Vec<Arc<dyn datafusion_expr::planner::ExprPlanner>> {
vec![]
}

fn get_table_source(&self, name: TableReference) -> Result<Arc<dyn TableSource>> {
match self.tables.get(name.table()) {
Some(table) => Ok(Arc::clone(table)),
Expand Down
4 changes: 0 additions & 4 deletions datafusion/sql/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ impl MockContextProvider {
}

impl ContextProvider for MockContextProvider {
fn get_expr_planners(&self) -> Vec<Arc<dyn datafusion_expr::planner::ExprPlanner>> {
vec![]
}

fn get_table_source(&self, name: TableReference) -> Result<Arc<dyn TableSource>> {
let schema = match name.table() {
"test" => Ok(Schema::new(vec![
Expand Down

0 comments on commit 38b3ff4

Please sign in to comment.