datafusion-match-recognize 0.56.1

SQL MATCH_RECOGNIZE row-pattern matching for Apache DataFusion
Documentation
// Licensed under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.
//
// This product includes software developed at Datadog (https://www.datadoghq.com/) Copyright 2025-Present Datadog, Inc.

//! Symbol-level DEFINE evaluation modes.
//!
//! Planning assigns one mode to each pattern symbol. The mode tells execution
//! when to evaluate that symbol's `DEFINE` predicate.

/// Per-symbol DEFINE evaluation mode.
///
/// Modes are aligned with the logical match program's dense symbol ordering.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum SymbolEvalMode {
    /// Evaluate the predicate before matching and read the resulting `__mr_symbol_*` column.
    #[default]
    Static,
    /// Evaluate while matching, updating local register or accumulator state.
    Incremental,
    /// Evaluate synchronously against the candidate's history and bounded lookahead.
    Deferred,
    /// Try a local guard before evaluating against candidate history.
    Hybrid,
}

impl SymbolEvalMode {
    /// Returns true when the DEFINE may need history evaluation.
    pub fn requires_deferred(self) -> bool {
        matches!(self, Self::Deferred | Self::Hybrid)
    }

    /// Returns true when the symbol has a local predicate or guard.
    pub fn uses_incremental(self) -> bool {
        matches!(self, Self::Incremental | Self::Hybrid)
    }
}

impl std::fmt::Display for SymbolEvalMode {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Static => write!(f, "Static"),
            Self::Incremental => write!(f, "Incremental"),
            Self::Deferred => write!(f, "Deferred"),
            Self::Hybrid => write!(f, "Hybrid"),
        }
    }
}