Skip to main content

mz_expr/scalar/
eval.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//
10// Portions of this file are derived from the PostgreSQL project. The original
11// source code is subject to the terms of the PostgreSQL license, a copy of
12// which can be found in the LICENSE file at the root of this repository.
13
14//! A trait for things that can evaluate (`MirScalarExpr`, but eventually `LirScalarExpr`).
15
16use mz_repr::{Datum, RowArena};
17
18use crate::EvalError;
19
20pub trait Eval {
21    /// Evaluates, where `datums` are column references and `temp_storage` is used for allocation.
22    ///
23    /// Should not panic, but instead return an appropriate `EvalError`.
24    fn eval<'a>(
25        &'a self,
26        datums: &[Datum<'a>],
27        temp_storage: &'a RowArena,
28    ) -> Result<Datum<'a>, EvalError>;
29
30    /// True iff evaluation could possibly error on non-error input `Datum`.
31    fn could_error(&self) -> bool;
32}