Skip to content

Commit

Permalink
Improve ContextProvider (#10577)
Browse files Browse the repository at this point in the history
  • Loading branch information
lewiszlw authored May 21, 2024
1 parent f807947 commit aab40e1
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 32 deletions.
6 changes: 3 additions & 3 deletions datafusion-examples/examples/rewrite_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ impl ContextProvider for MyContextProvider {
&self.options
}

fn udfs_names(&self) -> Vec<String> {
fn udf_names(&self) -> Vec<String> {
Vec::new()
}

fn udafs_names(&self) -> Vec<String> {
fn udaf_names(&self) -> Vec<String> {
Vec::new()
}

fn udwfs_names(&self) -> Vec<String> {
fn udwf_names(&self) -> Vec<String> {
Vec::new()
}
}
Expand Down
6 changes: 3 additions & 3 deletions datafusion/core/src/execution/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2209,15 +2209,15 @@ impl<'a> ContextProvider for SessionContextProvider<'a> {
self.state.config_options()
}

fn udfs_names(&self) -> Vec<String> {
fn udf_names(&self) -> Vec<String> {
self.state.scalar_functions().keys().cloned().collect()
}

fn udafs_names(&self) -> Vec<String> {
fn udaf_names(&self) -> Vec<String> {
self.state.aggregate_functions().keys().cloned().collect()
}

fn udwfs_names(&self) -> Vec<String> {
fn udwf_names(&self) -> Vec<String> {
self.state.window_functions().keys().cloned().collect()
}
}
Expand Down
6 changes: 3 additions & 3 deletions datafusion/core/tests/optimizer_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ impl ContextProvider for MyContextProvider {
&self.options
}

fn udfs_names(&self) -> Vec<String> {
fn udf_names(&self) -> Vec<String> {
Vec::new()
}

fn udafs_names(&self) -> Vec<String> {
fn udaf_names(&self) -> Vec<String> {
Vec::new()
}

fn udwfs_names(&self) -> Vec<String> {
fn udwf_names(&self) -> Vec<String> {
Vec::new()
}
}
Expand Down
6 changes: 3 additions & 3 deletions datafusion/optimizer/tests/optimizer_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,15 @@ impl ContextProvider for MyContextProvider {
&self.options
}

fn udfs_names(&self) -> Vec<String> {
fn udf_names(&self) -> Vec<String> {
Vec::new()
}

fn udafs_names(&self) -> Vec<String> {
fn udaf_names(&self) -> Vec<String> {
Vec::new()
}

fn udwfs_names(&self) -> Vec<String> {
fn udwf_names(&self) -> Vec<String> {
Vec::new()
}
}
Expand Down
6 changes: 3 additions & 3 deletions datafusion/sql/examples/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ impl ContextProvider for MyContextProvider {
&self.options
}

fn udfs_names(&self) -> Vec<String> {
fn udf_names(&self) -> Vec<String> {
Vec::new()
}

fn udafs_names(&self) -> Vec<String> {
fn udaf_names(&self) -> Vec<String> {
Vec::new()
}

fn udwfs_names(&self) -> Vec<String> {
fn udwf_names(&self) -> Vec<String> {
Vec::new()
}
}
8 changes: 4 additions & 4 deletions datafusion/sql/src/expr/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ pub fn suggest_valid_function(
let mut funcs = Vec::new();

funcs.extend(AggregateFunction::iter().map(|func| func.to_string()));
funcs.extend(ctx.udafs_names());
funcs.extend(ctx.udaf_names());
funcs.extend(BuiltInWindowFunction::iter().map(|func| func.to_string()));
funcs.extend(ctx.udwfs_names());
funcs.extend(ctx.udwf_names());

funcs
} else {
// All scalar functions and aggregate functions
let mut funcs = Vec::new();

funcs.extend(ctx.udfs_names());
funcs.extend(ctx.udf_names());
funcs.extend(AggregateFunction::iter().map(|func| func.to_string()));
funcs.extend(ctx.udafs_names());
funcs.extend(ctx.udaf_names());

funcs
};
Expand Down
6 changes: 3 additions & 3 deletions datafusion/sql/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,15 +1133,15 @@ mod tests {
None
}

fn udfs_names(&self) -> Vec<String> {
fn udf_names(&self) -> Vec<String> {
Vec::new()
}

fn udafs_names(&self) -> Vec<String> {
fn udaf_names(&self) -> Vec<String> {
Vec::new()
}

fn udwfs_names(&self) -> Vec<String> {
fn udwf_names(&self) -> Vec<String> {
Vec::new()
}
}
Expand Down
15 changes: 8 additions & 7 deletions datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ use crate::utils::make_decimal_type;
/// The ContextProvider trait allows the query planner to obtain meta-data about tables and
/// functions referenced in SQL statements
pub trait ContextProvider {
#[deprecated(since = "32.0.0", note = "please use `get_table_source` instead")]
fn get_table_provider(&self, name: TableReference) -> Result<Arc<dyn TableSource>> {
self.get_table_source(name)
}
/// Getter for a datasource
fn get_table_source(&self, name: TableReference) -> Result<Arc<dyn TableSource>>;
/// Getter for a table function
Expand Down Expand Up @@ -86,9 +82,14 @@ pub trait ContextProvider {
/// Get configuration options
fn options(&self) -> &ConfigOptions;

fn udfs_names(&self) -> Vec<String>;
fn udafs_names(&self) -> Vec<String>;
fn udwfs_names(&self) -> Vec<String>;
/// Get all user defined scalar function names
fn udf_names(&self) -> Vec<String>;

/// Get all user defined aggregate function names
fn udaf_names(&self) -> Vec<String>;

/// Get all user defined window function names
fn udwf_names(&self) -> Vec<String>;
}

/// SQL parser options
Expand Down
6 changes: 3 additions & 3 deletions datafusion/sql/tests/sql_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2942,15 +2942,15 @@ impl ContextProvider for MockContextProvider {
Ok(Arc::new(EmptyTable::new(schema)))
}

fn udfs_names(&self) -> Vec<String> {
fn udf_names(&self) -> Vec<String> {
self.udfs.keys().cloned().collect()
}

fn udafs_names(&self) -> Vec<String> {
fn udaf_names(&self) -> Vec<String> {
self.udafs.keys().cloned().collect()
}

fn udwfs_names(&self) -> Vec<String> {
fn udwf_names(&self) -> Vec<String> {
Vec::new()
}
}
Expand Down

0 comments on commit aab40e1

Please sign in to comment.