Apache DataFusion SQL Query Engine
ARROW-9835: [Rust][DataFusion] Removed FunctionMeta and FunctionType
Jorge C. Leitao83c04828a12d
diff --git a/rust/datafusion/src/execution/context.rs b/rust/datafusion/src/execution/context.rsindex c6e8c05f3b..9fbc5c63b2 100644--- a/rust/datafusion/src/execution/context.rs+++ b/rust/datafusion/src/execution/context.rs@@ -42,7 +42,7 @@ use crate::execution::physical_plan::scalar_functions;use crate::execution::physical_plan::udf::ScalarFunction;use crate::execution::physical_plan::ExecutionPlan;use crate::execution::physical_plan::PhysicalPlanner;-use crate::logicalplan::{FunctionMeta, FunctionType, LogicalPlan, LogicalPlanBuilder};+use crate::logicalplan::{LogicalPlan, LogicalPlanBuilder};use crate::optimizer::optimizer::OptimizerRule;use crate::optimizer::projection_push_down::ProjectionPushDown;use crate::optimizer::{@@ -481,15 +481,10 @@ impl SchemaProvider for ExecutionContextState {self.datasources.get(name).map(|ds| ds.schema().clone())}- fn get_function_meta(&self, name: &str) -> Option<Arc<FunctionMeta>> {- self.scalar_functions.get(name).map(|f| {- Arc::new(FunctionMeta::new(- name.to_owned(),- f.args.clone(),- f.return_type.clone(),- FunctionType::Scalar,- ))- })+ fn get_function_meta(&self, name: &str) -> Option<Arc<ScalarFunction>> {+ self.scalar_functions+ .get(name)+ .and_then(|func| Some(Arc::new(func.as_ref().clone())))}}diff --git a/rust/datafusion/src/logicalplan.rs b/rust/datafusion/src/logicalplan.rsindex 0c8289484c..1f70353902 100644--- a/rust/datafusion/src/logicalplan.rs+++ b/rust/datafusion/src/logicalplan.rs@@ -35,61 +35,6 @@ use crate::{};use arrow::record_batch::RecordBatch;-/// Enumeration of supported function types (Scalar and Aggregate)-#[derive(Debug, Clone)]-pub enum FunctionType {- /// Simple function returning a value per DataFrame- Scalar,- /// Aggregate functions produce a value by sampling multiple DataFrames- Aggregate,-}--/// Logical representation of a UDF (user-defined function)-#[derive(Debug, Clone)]-pub struct FunctionMeta {- /// Function name- name: String,- /// Function arguments- args: Vec<Field>,- /// Function return type- return_type: DataType,- /// Function type (Scalar or Aggregate)- function_type: FunctionType,-}--impl FunctionMeta {- #[allow(missing_docs)]- pub fn new(- name: String,- args: Vec<Field>,- return_type: DataType,- function_type: FunctionType,- ) -> Self {- FunctionMeta {- name,- args,- return_type,- function_type,- }- }- /// Getter for the function name- pub fn name(&self) -> &String {- &self.name- }- /// Getter for the arg list- pub fn args(&self) -> &Vec<Field> {- &self.args- }- /// Getter for the `DataType` the function returns- pub fn return_type(&self) -> &DataType {- &self.return_type- }- /// Getter for the `FunctionType`- pub fn function_type(&self) -> &FunctionType {- &self.function_type- }-}-/// Operators applied to expressions#[derive(Debug, Clone, PartialEq, Eq)]pub enum Operator {diff --git a/rust/datafusion/src/sql/planner.rs b/rust/datafusion/src/sql/planner.rsindex 1735710d3f..8f366de0a4 100644--- a/rust/datafusion/src/sql/planner.rs+++ b/rust/datafusion/src/sql/planner.rs@@ -22,10 +22,13 @@ use std::sync::Arc;use crate::error::{ExecutionError, Result};use crate::logicalplan::Expr::Alias;use crate::logicalplan::{- lit, Expr, FunctionMeta, LogicalPlan, LogicalPlanBuilder, Operator, PlanType,- ScalarValue, StringifiedPlan,+ lit, Expr, LogicalPlan, LogicalPlanBuilder, Operator, PlanType, ScalarValue,+ StringifiedPlan,+};+use crate::{+ execution::physical_plan::udf::ScalarFunction,+ sql::parser::{CreateExternalTable, FileType, Statement as DFStatement},};-use crate::sql::parser::{CreateExternalTable, FileType, Statement as DFStatement};use arrow::datatypes::*;@@ -43,7 +46,7 @@ pub trait SchemaProvider {/// Getter for a field descriptionfn get_table_meta(&self, name: &str) -> Option<SchemaRef>;/// Getter for a UDF description- fn get_function_meta(&self, name: &str) -> Option<Arc<FunctionMeta>>;+ fn get_function_meta(&self, name: &str) -> Option<Arc<ScalarFunction>>;}/// SQL query planner@@ -519,14 +522,14 @@ impl<'a, S: SchemaProvider> SqlToRel<'a, S> {for i in 0..rex_args.len() {safe_args.push(rex_args[i]- .cast_to(fm.args()[i].data_type(), schema)?,+ .cast_to(fm.args[i].data_type(), schema)?,);}Ok(Expr::ScalarFunction {name: name.clone(),args: safe_args,- return_type: fm.return_type().clone(),+ return_type: fm.return_type.clone(),})}_ => Err(ExecutionError::General(format!(@@ -576,7 +579,6 @@ pub fn convert_data_type(sql: &SQLDataType) -> Result<DataType> {#[cfg(test)]mod tests {use super::*;- use crate::logicalplan::FunctionType;use crate::sql::parser::DFParser;#[test]@@ -902,13 +904,13 @@ mod tests {}}- fn get_function_meta(&self, name: &str) -> Option<Arc<FunctionMeta>> {+ fn get_function_meta(&self, name: &str) -> Option<Arc<ScalarFunction>> {match name {- "sqrt" => Some(Arc::new(FunctionMeta::new(- "sqrt".to_string(),+ "sqrt" => Some(Arc::new(ScalarFunction::new(+ "sqrt",vec![Field::new("n", DataType::Float64, false)],DataType::Float64,- FunctionType::Scalar,+ Arc::new(|_| Err(ExecutionError::NotImplemented("".to_string()))),))),_ => None,}