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.
910use mz_repr::{Datum, DatumList};
1112use crate::EvalError;
1314sqlfunc!(
15#[sqlname = "isnull"]
16 #[is_monotone = true]
17fn is_null<'a>(a: Datum<'a>) -> bool {
18 a.is_null()
19 }
20);
2122sqlfunc!(
23#[sqlname = "istrue"]
24fn is_true<'a>(a: Datum<'a>) -> bool {
25 a == Datum::True
26 }
27);
2829sqlfunc!(
30#[sqlname = "isfalse"]
31fn is_false<'a>(a: Datum<'a>) -> bool {
32 a == Datum::False
33 }
34);
3536sqlfunc!(
37fn pg_column_size<'a>(a: Datum<'a>) -> Result<Option<i32>, EvalError> {
38match a {
39 Datum::Null => Ok(None),
40 datum => {
41let sz = mz_repr::datum_size(&datum);
42 i32::try_from(sz)
43 .map(Some)
44 .or_else(|_| Err(EvalError::Int32OutOfRange(sz.to_string().into())))
45 }
46 }
47 }
48);
4950sqlfunc!(
51// TODO[btv] - if we plan to keep changing row format,
52 // should we make this unmaterializable?
53fn mz_row_size<'a>(a: DatumList<'a>) -> Result<i32, EvalError> {
54let sz = mz_repr::row_size(a.iter());
55 i32::try_from(sz).or_else(|_| Err(EvalError::Int32OutOfRange(sz.to_string().into())))
56 }
57);