use std::collections::HashMap;
use datafusion::arrow::datatypes::DataType;
use pyo3::prelude::*;
use super::data_type::PyDataType;
#[pyclass(
from_py_object,
frozen,
name = "SqlFunction",
module = "datafusion.common",
subclass
)]
#[derive(Debug, Clone)]
pub struct SqlFunction {
pub name: String,
pub return_types: HashMap<Vec<DataType>, DataType>,
pub aggregation: bool,
}
impl SqlFunction {
pub fn new(
function_name: String,
input_types: Vec<PyDataType>,
return_type: PyDataType,
aggregation_bool: bool,
) -> Self {
let mut func = Self {
name: function_name,
return_types: HashMap::new(),
aggregation: aggregation_bool,
};
func.add_type_mapping(input_types, return_type);
func
}
pub fn add_type_mapping(&mut self, input_types: Vec<PyDataType>, return_type: PyDataType) {
self.return_types.insert(
input_types.iter().map(|t| t.clone().into()).collect(),
return_type.into(),
);
}
}