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 crate::core::AbsoluteRow;
use crate::execution::matching::path::{PathNode, Sym};

fn path_node(row: u64, prev: Option<u32>, depth: u32) -> PathNode {
    PathNode {
        step: PathStep {
            row: AbsoluteRow::new(row),
            sym: Sym::User(0),
            excluded: false,
        },
        prev,
        depth,
    }
}
#[test]
fn deferred_projection_ignores_unobserved_labels_but_preserves_positions() {
    let mut arena = vec![path_node(0, None, 1), path_node(1, Some(0), 2)];
    let mut alternative = arena[1];
    alternative.step.sym = Sym::from_index(2);
    arena.push(alternative);
    let mut projection = DeferredHistoryProjection::default();
    projection.symbols.insert(3);
    assert!(projection.equivalent_steps(&arena[1].step, &arena[2].step));
    assert_eq!(projection.append_fingerprint(7, &arena[1].step), 7);
    projection.symbols.insert(2);
    assert!(!projection.equivalent_steps(&arena[1].step, &arena[2].step));
    projection.symbols.clear();
    projection.exclusions = true;
    arena[2].step.excluded = true;
    assert!(!projection.equivalent_steps(&arena[1].step, &arena[2].step));
    projection.exclusions = false;
    projection.all_labels = true;
    assert!(!projection.equivalent_steps(&arena[1].step, &arena[2].step));
    arena[2].step = arena[1].step;
    arena[2].step.row = AbsoluteRow::new(2);
    assert_ne!(
        projection.append_fingerprint(7, &arena[1].step),
        projection.append_fingerprint(7, &arena[2].step)
    );
    assert!(!projection.equivalent_steps(&arena[1].step, &arena[2].step));
}

#[test]
fn volatile_history_does_not_equate_distinct_occurrences_with_equal_values() {
    let step = path_node(0, None, 1).step;
    let mut projection = DeferredHistoryProjection::default();
    assert!(projection.is_empty());
    assert!(projection.equivalent_steps(&step, &step));
    projection.extend(&DeferredHistoryProjection {
        has_volatile_operations: true,
        ..Default::default()
    });
    assert!(!projection.is_empty());
    assert!(!projection.equivalent_steps(&step, &step));
}