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.

use super::*;
use datafusion::arrow::datatypes::{DataType, Field};
use datafusion::common::{ScalarValue, config::ConfigOptions};
use datafusion::logical_expr::{Operator, create_udf};
use datafusion::physical_expr::expressions::{BinaryExpr, Column, Literal};

#[test]
fn immutable_roots_checks_nested_function_capabilities() {
    for volatility in [
        Volatility::Immutable,
        Volatility::Stable,
        Volatility::Volatile,
    ] {
        let function = create_udf(
            "identity",
            vec![DataType::Boolean],
            DataType::Boolean,
            volatility,
            Arc::new(|args| Ok(args[0].clone())),
        );
        let call = Arc::new(ScalarFunctionExpr::new(
            "identity",
            Arc::new(function),
            vec![Arc::new(Column::new("value", 0))],
            Arc::new(Field::new("value", DataType::Boolean, false)),
            Arc::new(ConfigOptions::new()),
        ));
        let root = Arc::new(BinaryExpr::new(
            call,
            Operator::Eq,
            Arc::new(Literal::new(ScalarValue::Boolean(Some(true)))),
        )) as Arc<dyn PhysicalExpr>;
        assert_eq!(
            DeferredEvaluatorFactory::immutable_roots(&[root]),
            volatility == Volatility::Immutable
        );
    }
}