use crate::Result;
use crate::arena::DataValue;
use crate::operators::eager::Cx;
pub(crate) fn type_of_nothing() -> &'static DataValue<'static> {
crate::arena::singletons::singleton_type_name("null")
}
#[inline]
pub(crate) fn type_<'a>(_cx: &mut Cx<'_, 'a>, av: &'a DataValue<'a>) -> Result<&'a DataValue<'a>> {
#[cfg(feature = "datetime")]
{
use crate::operators::datetime::sentinel_str;
if sentinel_str(av, "datetime").is_some() {
return Ok(crate::arena::singletons::singleton_type_name("datetime"));
}
if sentinel_str(av, "timestamp").is_some() {
return Ok(crate::arena::singletons::singleton_type_name("duration"));
}
}
let type_str: &'static str = match av {
DataValue::String(s) => classify_string(s),
other => super::type_name(other),
};
Ok(crate::arena::singletons::singleton_type_name(type_str))
}
#[inline]
fn classify_string(s: &str) -> &'static str {
#[cfg(feature = "datetime")]
{
if !crate::operators::comparison::could_be_datetime_or_duration(s) {
return "string";
}
let as_value = DataValue::String(s);
match crate::operators::datetime::arith::Temporal::of(&as_value) {
Some(crate::operators::datetime::arith::Temporal::DateTime(_)) => "datetime",
Some(crate::operators::datetime::arith::Temporal::Duration(_)) => "duration",
None => "string",
}
}
#[cfg(not(feature = "datetime"))]
{
let _ = s;
"string"
}
}