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.

//! Metadata placeholder scalar UDFs for `MATCH_RECOGNIZE`.
//!
//! DataFusion registers `match_number`, `match_sequence_number`, `classifier`,
//! and `excluded` so it can check their arguments and types. Planning replaces
//! these calls with internal metadata-column references before execution.

use std::sync::{Arc, LazyLock};

use datafusion::logical_expr::ScalarUDF;

pub mod metadata;

/// Returns a [`ScalarUDF`] implementation of `match_number`.
pub fn match_number() -> Arc<ScalarUDF> {
    static INSTANCE: LazyLock<Arc<ScalarUDF>> = LazyLock::new(|| {
        Arc::new(ScalarUDF::new_from_impl(metadata::MatchNumberUdf::new()))
    });
    Arc::clone(&INSTANCE)
}

/// Returns a [`ScalarUDF`] implementation of `match_sequence_number`.
pub fn match_sequence_number() -> Arc<ScalarUDF> {
    static INSTANCE: LazyLock<Arc<ScalarUDF>> = LazyLock::new(|| {
        Arc::new(ScalarUDF::new_from_impl(
            metadata::MatchSequenceNumberUdf::new(),
        ))
    });
    Arc::clone(&INSTANCE)
}

/// Returns a [`ScalarUDF`] implementation of `classifier`.
pub fn classifier() -> Arc<ScalarUDF> {
    static INSTANCE: LazyLock<Arc<ScalarUDF>> = LazyLock::new(|| {
        Arc::new(ScalarUDF::new_from_impl(metadata::ClassifierUdf::new()))
    });
    Arc::clone(&INSTANCE)
}

/// Returns a [`ScalarUDF`] implementation of `excluded`.
pub fn excluded() -> Arc<ScalarUDF> {
    static INSTANCE: LazyLock<Arc<ScalarUDF>> = LazyLock::new(|| {
        Arc::new(ScalarUDF::new_from_impl(metadata::ExcludedUdf::new()))
    });
    Arc::clone(&INSTANCE)
}

/// Returns all metadata scalar UDF registrations in registration order.
pub fn functions() -> Vec<Arc<ScalarUDF>> {
    vec![
        match_number(),
        match_sequence_number(),
        classifier(),
        excluded(),
    ]
}