datafusion-match-recognize 0.56.1

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.

use super::*;
use datafusion::arrow::datatypes::DataType;
use datafusion::common::ScalarValue;
use datafusion::logical_expr::{Expr, col, lit};
#[test]
fn unsupported_domains_and_operations_fall_back_as_whole_expressions() {
    let decimal = lit(ScalarValue::Decimal128(Some(100), 10, 2));
    let wide_decimal = lit(ScalarValue::Decimal128(Some(1_000_000), 30, 20));
    for expr in [
        (lit(1_i64) / lit(0_i64)).is_null(),
        (lit(1_i64) % lit(2_i64)).is_null(),
        (lit(1_f32) + lit(2_f32)).is_null(),
        (decimal.clone() / decimal.clone()).is_null(),
        (wide_decimal.clone() * wide_decimal).is_null(),
        decimal.clone().eq(lit(1_i64)),
        lit(ScalarValue::Decimal256(
            Some(datafusion::arrow::datatypes::i256::ONE),
            40,
            0,
        ))
        .is_null(),
        lit(ScalarValue::FixedSizeBinary(1, Some(vec![1]))).is_null(),
        lit(1_i64).between(lit(0_i64), lit(2_i64)),
        lit(1_i64).in_list(vec![lit(1_i64)], false),
    ] {
        assert!(
            compile_direct_predicate(&expr, &VmCompileContext::default()).is_err(),
            "{expr}"
        );
        assert!(
            compile_direct_predicate(&lit(false).and(expr), &VmCompileContext::default())
                .is_err()
        );
    }
    let cast = Expr::Cast(datafusion::logical_expr::expr::Cast::new(
        Box::new(decimal),
        DataType::Decimal128(10, 1),
    ));
    assert!(
        compile_direct_predicate(&cast.is_null(), &VmCompileContext::default()).is_err()
    );
}
#[test]
fn budgets_bound_source_nodes_and_live_stack_without_reordering() {
    let expr = (lit(1_i64) - lit(2_i64)).gt(lit(0_i64));
    let plan = compile_direct_predicate(&expr, &VmCompileContext::default()).unwrap();
    assert_eq!(plan.value_slots(), 2);
    for (limits, error) in [
        (
            PredicateProgramLimits {
                max_operations: 5,
                max_eval_stack: 64,
            },
            VmCompileError::ProgramTooLarge,
        ),
        (
            PredicateProgramLimits {
                max_operations: 768,
                max_eval_stack: 1,
            },
            VmCompileError::StackDepthExceeded,
        ),
    ] {
        assert_eq!(
            compile_direct_predicate(
                &expr,
                &VmCompileContext::default().with_program_limits(limits)
            ),
            Err(error)
        );
    }
    let context = VmCompileContext::try_new(
        vec![],
        vec![],
        VmCompileLimits {
            max_ir_nodes: 4,
            max_constants: 256,
        },
    )
    .unwrap();
    assert_eq!(
        compile_direct_predicate(&expr, &context),
        Err(VmCompileError::ExpressionTooLarge)
    );
    let missing =
        compile_direct_predicate(&col("absent").is_null(), &VmCompileContext::default());
    assert_eq!(missing, Err(VmCompileError::BindingFailure));
}