datafusion-match-recognize 0.55.0

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.

//! Whole-expression direct admission; unsupported expressions retain PhysicalExpr.

mod compile;
mod ir;
pub use compile::*;
pub use ir::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct VmCompileLimits {
    pub max_ir_nodes: usize,
    pub max_constants: usize,
}

impl VmCompileLimits {
    pub const MAX: Self = Self {
        max_ir_nodes: 512,
        max_constants: 256,
    };

    pub(crate) fn bounded(self) -> Self {
        Self {
            max_ir_nodes: self.max_ir_nodes.min(Self::MAX.max_ir_nodes),
            max_constants: self.max_constants.min(Self::MAX.max_constants),
        }
    }
}

impl Default for VmCompileLimits {
    fn default() -> Self {
        Self::MAX
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct PredicateProgramLimits {
    pub max_operations: usize,
    pub max_eval_stack: usize,
}

impl PredicateProgramLimits {
    pub const MAX: Self = Self {
        max_operations: 768,
        max_eval_stack: 64,
    };

    #[cfg(test)]
    pub(crate) fn bounded(self) -> Self {
        Self {
            max_operations: self.max_operations.min(Self::MAX.max_operations),
            max_eval_stack: self.max_eval_stack.min(Self::MAX.max_eval_stack),
        }
    }
}

impl Default for PredicateProgramLimits {
    fn default() -> Self {
        Self::MAX
    }
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum VmCompileError {
    TypeResolutionFailure,
    UnsupportedFunctionSignature,
    UnsupportedCast,
    UnsupportedSourceDomain,
    UnsupportedNumericTypeCombination,
    ExpressionTooLarge,
    ProgramTooLarge,
    StackDepthExceeded,
    EmissionFailure,
    BindingFailure,
}

pub(crate) fn direct_column_name(
    mut expr: &datafusion::logical_expr::Expr,
) -> Option<&str> {
    while let datafusion::logical_expr::Expr::Alias(alias) = expr {
        expr = &alias.expr;
    }
    if let datafusion::logical_expr::Expr::Column(column) = expr {
        Some(&column.name)
    } else {
        None
    }
}
#[cfg(test)]
mod tests;