datafusion-match-recognize 0.56.0

MATCH_RECOGNIZE extension for 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.

//! Structural minimum and maximum row counts derived from the pattern AST.

use super::Pattern;

impl Pattern {
    /// Return a structural upper bound on matched rows, when representable.
    ///
    /// Returns `None` for unbounded repetitions or when the calculated bound
    /// overflows `usize`.
    ///
    /// This is used to determine eligibility for parallel execution without
    /// PARTITION BY, where bounded patterns allow safe chunk splitting.
    pub fn max_match_rows(&self) -> Option<usize> {
        self.structural_info().max_match_rows()
    }

    /// Returns the minimum number of rows this pattern can match.
    ///
    /// This is a conservative structural property derived from the pattern AST:
    /// - Named symbols consume 1 row
    /// - Anchors (`^`/`$`) consume 0 rows
    /// - Concatenation sums minima
    /// - Alternation takes the minimum across branches
    /// - Repetition uses the lower bound of the quantifier (0 for `*`, `?`, `{,n}`)
    ///
    /// This is useful for determining if a pattern can match the empty string
    /// (`min_match_rows() == 0`).
    pub fn min_match_rows(&self) -> usize {
        self.structural_info().min_match_rows()
    }
}