mz_expr/scalar/func/impls/
int2vector.rsuse std::fmt;
use mz_lowertest::MzReflect;
use mz_repr::{ColumnType, Datum, RowArena, ScalarType};
use proptest_derive::Arbitrary;
use serde::{Deserialize, Serialize};
use crate::scalar::func::{stringify_datum, LazyUnaryFunc};
use crate::{EvalError, MirScalarExpr};
#[derive(
Arbitrary, Ord, PartialOrd, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Hash, MzReflect,
)]
pub struct CastInt2VectorToArray;
impl LazyUnaryFunc for CastInt2VectorToArray {
fn eval<'a>(
&'a self,
datums: &[Datum<'a>],
temp_storage: &'a RowArena,
a: &'a MirScalarExpr,
) -> Result<Datum<'a>, EvalError> {
a.eval(datums, temp_storage)
}
fn output_type(&self, input_type: ColumnType) -> ColumnType {
ScalarType::Array(Box::from(ScalarType::Int16)).nullable(input_type.nullable)
}
fn propagates_nulls(&self) -> bool {
true
}
fn introduces_nulls(&self) -> bool {
false
}
fn preserves_uniqueness(&self) -> bool {
false
}
fn inverse(&self) -> Option<crate::UnaryFunc> {
None
}
fn is_monotone(&self) -> bool {
true }
}
impl fmt::Display for CastInt2VectorToArray {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("int2vectortoarray")
}
}
#[derive(
Arbitrary, Ord, PartialOrd, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Hash, MzReflect,
)]
pub struct CastInt2VectorToString;
impl LazyUnaryFunc for CastInt2VectorToString {
fn eval<'a>(
&'a self,
datums: &[Datum<'a>],
temp_storage: &'a RowArena,
a: &'a MirScalarExpr,
) -> Result<Datum<'a>, EvalError> {
let a = a.eval(datums, temp_storage)?;
if a.is_null() {
return Ok(Datum::Null);
}
let mut buf = String::new();
stringify_datum(&mut buf, a, &ScalarType::Int2Vector)?;
Ok(Datum::String(temp_storage.push_string(buf)))
}
fn output_type(&self, input_type: ColumnType) -> ColumnType {
ScalarType::String.nullable(input_type.nullable)
}
fn propagates_nulls(&self) -> bool {
true
}
fn introduces_nulls(&self) -> bool {
false
}
fn preserves_uniqueness(&self) -> bool {
true
}
fn inverse(&self) -> Option<crate::UnaryFunc> {
to_unary!(super::CastStringToInt2Vector)
}
fn is_monotone(&self) -> bool {
false
}
}
impl fmt::Display for CastInt2VectorToString {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("int2vectortostr")
}
}