mz_expr/scalar/func/impls/
int2vector.rs1use std::fmt;
11
12use mz_lowertest::MzReflect;
13use mz_repr::{Datum, RowArena, SqlColumnType, SqlScalarType};
14use serde::{Deserialize, Serialize};
15
16use crate::scalar::func::{LazyUnaryFunc, stringify_datum};
17use crate::{EvalError, MirScalarExpr};
18
19#[derive(Ord, PartialOrd, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Hash, MzReflect)]
20pub struct CastInt2VectorToArray;
21
22impl LazyUnaryFunc for CastInt2VectorToArray {
25 fn eval<'a>(
26 &'a self,
27 datums: &[Datum<'a>],
28 temp_storage: &'a RowArena,
29 a: &'a MirScalarExpr,
30 ) -> Result<Datum<'a>, EvalError> {
31 a.eval(datums, temp_storage)
32 }
33
34 fn output_type(&self, input_type: SqlColumnType) -> SqlColumnType {
36 SqlScalarType::Array(Box::from(SqlScalarType::Int16)).nullable(input_type.nullable)
37 }
38
39 fn propagates_nulls(&self) -> bool {
41 true
42 }
43
44 fn introduces_nulls(&self) -> bool {
46 false
47 }
48
49 fn preserves_uniqueness(&self) -> bool {
51 false
52 }
53
54 fn inverse(&self) -> Option<crate::UnaryFunc> {
55 None
56 }
57
58 fn is_monotone(&self) -> bool {
59 true }
61}
62
63impl fmt::Display for CastInt2VectorToArray {
64 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
65 f.write_str("int2vectortoarray")
66 }
67}
68
69#[derive(Ord, PartialOrd, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Hash, MzReflect)]
70pub struct CastInt2VectorToString;
71
72impl LazyUnaryFunc for CastInt2VectorToString {
73 fn eval<'a>(
74 &'a self,
75 datums: &[Datum<'a>],
76 temp_storage: &'a RowArena,
77 a: &'a MirScalarExpr,
78 ) -> Result<Datum<'a>, EvalError> {
79 let a = a.eval(datums, temp_storage)?;
80 if a.is_null() {
81 return Ok(Datum::Null);
82 }
83 let mut buf = String::new();
84 stringify_datum(&mut buf, a, &SqlScalarType::Int2Vector)?;
85 Ok(Datum::String(temp_storage.push_string(buf)))
86 }
87
88 fn output_type(&self, input_type: SqlColumnType) -> SqlColumnType {
89 SqlScalarType::String.nullable(input_type.nullable)
90 }
91
92 fn propagates_nulls(&self) -> bool {
93 true
94 }
95
96 fn introduces_nulls(&self) -> bool {
97 false
98 }
99
100 fn preserves_uniqueness(&self) -> bool {
101 true
102 }
103
104 fn inverse(&self) -> Option<crate::UnaryFunc> {
105 to_unary!(super::CastStringToInt2Vector)
106 }
107
108 fn is_monotone(&self) -> bool {
109 false
110 }
111}
112
113impl fmt::Display for CastInt2VectorToString {
114 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
115 f.write_str("int2vectortostr")
116 }
117}