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    output_type_expr = SqlScalarType::Array(Box::from(SqlScalarType::Int16))
21        .nullable(input_type.nullable)
22)]
23fn cast_int2_vector_to_array<'a>(a: Int2Vector<'a>) -> Array<'a> {
24    a.0
25}
26
27#[sqlfunc(
28    sqlname = "int2vectortostr",
29    preserves_uniqueness = true,
30    inverse = super::CastStringToInt2Vector
31)]
32fn cast_int2_vector_to_string<'a>(a: Int2Vector<'a>) -> Result<String, EvalError> {
33    let mut buf = String::new();
34    stringify_datum(&mut buf, Datum::Array(a.0), &SqlScalarType::Int2Vector)?;
35    Ok(buf)
36}