1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::rc::Rc;
use super::super::api::*;
use super::super::rel::*;
use super::super::exec::*;
pub struct SqrtFunction {
}
impl ScalarFunction for SqrtFunction {
fn name(&self) -> String {
"sqrt".to_string()
}
fn execute(&self, args: Vec<Rc<ColumnData>>) -> Result<Rc<ColumnData>,Box<String>> {
match args[0].as_ref() {
&ColumnData::Float(ref v) => Ok(Rc::new(ColumnData::Float(v.iter().map(|v| v.sqrt()).collect()))),
&ColumnData::Double(ref v) => Ok(Rc::new(ColumnData::Double(v.iter().map(|v| v.sqrt()).collect()))),
_ => Err(Box::new("Unsupported arg type for sqrt".to_string()))
}
}
fn args(&self) -> Vec<Field> {
vec![
Field::new("x", DataType::Double, false),
Field::new("y", DataType::Double, false)
]
}
fn return_type(&self) -> DataType {
DataType::Double
}
}