Skip to main content

mz_expr/scalar/func/impls/
int2vector.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10use mz_expr_derive::sqlfunc;
11use mz_repr::adt::array::Array;
12use mz_repr::{Datum, Int2Vector, SqlScalarType};
13
14use crate::EvalError;
15use crate::scalar::func::stringify_datum;
16
17#[sqlfunc(
18    sqlname = "int2vectortoarray",
19    is_monotone = true,
20    introduces_nulls = false,
21    output_type_expr = SqlScalarType::Array(Box::from(SqlScalarType::Int16))
22        .nullable(input_type.nullable)
23)]
24fn cast_int2_vector_to_array<'a>(a: Int2Vector<'a>) -> Array<'a> {
25    a.0
26}
27
28#[sqlfunc(
29    sqlname = "int2vectortostr",
30    preserves_uniqueness = true,
31    inverse = to_unary!(super::CastStringToInt2Vector)
32)]
33fn cast_int2_vector_to_string<'a>(a: Int2Vector<'a>) -> Result<String, EvalError> {
34    let mut buf = String::new();
35    stringify_datum(&mut buf, Datum::Array(a.0), &SqlScalarType::Int2Vector)?;
36    Ok(buf)
37}