use std::io::Error;
use std::rc::Rc;
use arrow::array::Array;
use arrow::datatypes::{DataType, Field};
use super::sqlparser::ParserError;
#[derive(Debug, Clone, PartialEq)]
pub enum ScalarValue {
Null,
Boolean(bool),
Float32(f32),
Float64(f64),
Int8(i8),
Int16(i16),
Int32(i32),
Int64(i64),
UInt8(u8),
UInt16(u16),
UInt32(u32),
UInt64(u64),
Utf8(String),
Struct(Vec<ScalarValue>),
}
#[derive(Clone)]
pub enum Value {
Column(Rc<Array>),
Scalar(Rc<ScalarValue>),
}
pub trait ScalarFunction {
fn name(&self) -> String;
fn args(&self) -> Vec<Field>;
fn return_type(&self) -> DataType;
fn execute(&self, args: Vec<Rc<Value>>) -> Result<Rc<Value>, ExecutionError>;
}
#[derive(Debug)]
pub enum ExecutionError {
IoError(Error),
ParserError(ParserError),
Custom(String),
}
impl From<Error> for ExecutionError {
fn from(e: Error) -> Self {
ExecutionError::IoError(e)
}
}
impl From<String> for ExecutionError {
fn from(e: String) -> Self {
ExecutionError::Custom(e)
}
}
impl From<ParserError> for ExecutionError {
fn from(e: ParserError) -> Self {
ExecutionError::ParserError(e)
}
}