Skip to content

Commit

Permalink
replace sateful -> unimplemented
Browse files Browse the repository at this point in the history
  • Loading branch information
victoria de sainte agathe committed Nov 28, 2023
1 parent 809d5c7 commit 8a3d6e4
Showing 1 changed file with 30 additions and 68 deletions.
98 changes: 30 additions & 68 deletions src/data_type/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,40 +152,40 @@ where
/// In particular, no range computation is done
/// Note that stateful computations should be avoided and reserved to pseudorandom functions//TODO remove this feature?
#[derive(Clone)]
pub struct Stateful {
pub struct Unimplemented {
domain: DataType,
co_domain: DataType,
value: Arc<Mutex<RefCell<dyn FnMut(Value) -> Value + Send>>>,
}

impl Stateful {
impl Unimplemented {
/// Constructor for Generic
pub fn new(
domain: DataType,
co_domain: DataType,
value: Arc<Mutex<RefCell<dyn FnMut(Value) -> Value + Send>>>,
) -> Self {
Stateful {
Unimplemented {
domain,
co_domain,
value,
}
}
}

impl fmt::Debug for Stateful {
impl fmt::Debug for Unimplemented {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "simple{{{} -> {}}}", self.domain(), self.co_domain())
}
}

impl fmt::Display for Stateful {
impl fmt::Display for Unimplemented {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "simple{{{} -> {}}}", self.domain(), self.co_domain())
}
}

impl Function for Stateful {
impl Function for Unimplemented {
fn domain(&self) -> DataType {
self.domain.clone()
}
Expand Down Expand Up @@ -1027,44 +1027,6 @@ impl Function for Case {
}
}

// TODO
#[derive(Clone, Debug)]
pub struct UserDefineFunction {
name: String,
domain: DataType,
co_domain: DataType
}

impl fmt::Display for UserDefineFunction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.name)
}
}

impl Function for UserDefineFunction {
fn domain(&self) -> DataType {
self.domain.clone()
}

fn super_image(&self, set: &DataType) -> Result<DataType> {
if !set.is_subset_of(&self.domain()) {
Err(Error::set_out_of_range(set, self.domain()))
} else {
Ok(self.co_domain.clone())
}
}

fn value(&self, arg: &Value) -> Result<Value> {
todo!()
}
}

impl UserDefineFunction {
pub fn new(name: String, domain: DataType, co_domain: DataType) -> UserDefineFunction {
UserDefineFunction {name, domain, co_domain}
}
}

// IN (..)
#[derive(Clone, Debug)]
pub struct InList(DataType);
Expand Down Expand Up @@ -1474,7 +1436,7 @@ pub fn concat(n: usize) -> impl Function {
}

pub fn md5() -> impl Function {
Stateful::new(
Unimplemented::new(
DataType::text(),
DataType::text(),
Arc::new(Mutex::new(RefCell::new(|v| {
Expand All @@ -1486,7 +1448,7 @@ pub fn md5() -> impl Function {
}

pub fn random<R: rand::Rng + Send + 'static>(mut rng: Mutex<R>) -> impl Function {
Stateful::new(
Unimplemented::new(
DataType::unit(),
DataType::float_interval(0., 1.),
Arc::new(Mutex::new(RefCell::new(move |v| {
Expand All @@ -1496,7 +1458,7 @@ pub fn random<R: rand::Rng + Send + 'static>(mut rng: Mutex<R>) -> impl Function
}

pub fn pi() -> impl Function {
Stateful::new(
Unimplemented::new(
DataType::unit(),
DataType::float_value(3.141592653589793),
Arc::new(Mutex::new(RefCell::new(move |_| 3.141592653589793.into()))),
Expand Down Expand Up @@ -1824,64 +1786,64 @@ pub fn position() -> impl Function {

/// Regexp contains
pub fn regexp_contains() -> impl Function {
UserDefineFunction::new(
"regexp_contains".to_string(),
Unimplemented::new(
DataType::structured_from_data_types([DataType::text(), DataType::text()]),
DataType::boolean()
DataType::boolean(),
Arc::new(Mutex::new(RefCell::new(|v| todo!())))
)
}

/// Regexp extract
pub fn regexp_extract() -> impl Function {
UserDefineFunction::new(
"regexp_extract".to_string(),
Unimplemented::new(
DataType::structured_from_data_types([DataType::text(), DataType::text(), DataType::integer(), DataType::integer()]),
DataType::optional(DataType::text())
DataType::optional(DataType::text()),
Arc::new(Mutex::new(RefCell::new(|v| todo!())))
)
}

/// Regexp replace
pub fn regexp_replace() -> impl Function {
UserDefineFunction::new(
"regexp_replace".to_string(),
Unimplemented::new(
DataType::structured_from_data_types([DataType::text(), DataType::text(), DataType::text()]),
DataType::text()
DataType::text(),
Arc::new(Mutex::new(RefCell::new(|v| todo!())))
)
}

/// Transact newid
pub fn newid() -> impl Function {
UserDefineFunction::new(
"newid".to_string(),
Unimplemented::new(
DataType::unit(),
DataType::text()
DataType::text(),
Arc::new(Mutex::new(RefCell::new(|v| todo!())))
)
}

/// MySQL encode
pub fn encode() -> impl Function {
UserDefineFunction::new(
"encode".to_string(),
Unimplemented::new(
DataType::structured_from_data_types([DataType::text(), DataType::text()]),
DataType::text()
DataType::text(),
Arc::new(Mutex::new(RefCell::new(|v| todo!())))
)
}

/// MySQL decode
pub fn decode() -> impl Function {
UserDefineFunction::new(
"decode".to_string(),
Unimplemented::new(
DataType::structured_from_data_types([DataType::text(), DataType::text()]),
DataType::text()
DataType::text(),
Arc::new(Mutex::new(RefCell::new(|v| todo!())))
)
}

/// MySQL unhex
pub fn unhex() -> impl Function {
UserDefineFunction::new(
"unhex".to_string(),
Unimplemented::new(
DataType::text(),
DataType::text(),
DataType::text()
Arc::new(Mutex::new(RefCell::new(|v| todo!())))
)
}

Expand Down

0 comments on commit 8a3d6e4

Please sign in to comment.