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.

//! Automaton identities for optional execution-owner test_cases.

/// Return a checked state ID for execution-only test_cases.
pub(crate) fn test_automaton_state_id(index: usize) -> crate::nfa::AutomatonStateId {
    use crate::core::{NormalizedPattern, Pattern, RepetitionQuantifier, Symbol};
    use crate::nfa::CompiledAutomaton;

    static SMALL_AUTOMATON: std::sync::OnceLock<CompiledAutomaton> =
        std::sync::OnceLock::new();
    let small = SMALL_AUTOMATON.get_or_init(|| {
        let pattern = NormalizedPattern::Ast(Pattern::Repetition(
            Box::new(Pattern::Symbol(Symbol::Named("A".into()))),
            RepetitionQuantifier::AtMost(32),
        ));
        CompiledAutomaton::compile(&pattern, &["A".into()])
            .expect("the execution test automaton should compile")
    });
    small.nfa().state_id(index).unwrap_or_else(|| {
        panic!("state index {index} exceeds the execution test automaton")
    })
}