use super::*;
use crate::execution::matching::build_test_executable;
use crate::execution::matching::path::PathRepresentation;
use crate::execution::physical::planner::bind::MatcherInputBindings;
use crate::execution::physical::{
MatchRecognizePatternExec, MatchRecognizeQueryPlanner, PartitionRetention,
plan_match_recognize_extension as plan_extension,
};
use crate::planning::logical::{
ExtractionKind, InternalSlotOwner, LogicalMatchOutput, LogicalMatchProgramInput,
LogicalSymbolInput, MatchRecognize, StaticExtractionInput,
};
use datafusion::execution::context::QueryPlanner;
use datafusion::logical_expr::{
Expr, Extension, LogicalPlan, LogicalPlanBuilder, col, lit,
physical_planning_context::PhysicalPlanningContext,
};
use datafusion::physical_plan::{ExecutionPlan, empty::EmptyExec};
use datafusion::physical_planner::DefaultPhysicalPlanner;
use datafusion::prelude::SessionContext;
fn build_output_contract_program(
input_schema: Arc<Schema>,
normalized_pattern: NormalizedPattern,
compiled: Arc<CompiledAutomaton>,
output: RowOutputHarness,
after_match_skip: ResolvedAfterMatchSkip,
) -> datafusion_common::Result<ExecutableMatchProgram> {
let symbol_columns =
test_symbol_columns(compiled.as_ref(), &[], input_schema.as_ref(), &[])?;
let mut input = test_executable_input(
input_schema,
normalized_pattern,
compiled,
symbol_columns,
after_match_skip,
);
input.output = output.try_build(
input.input_schema.as_ref(),
input.symbols.automaton.as_ref(),
)?;
ExecutableMatchProgram::try_new(input)
}
#[test]
fn program_construction_preserves_dense_symbols_and_rejects_missing_register_owners() {
let base = make_batch(
&[1, 2],
&[("A", vec![true, false]), ("B", vec![false, true])],
);
let pattern = concat(vec![sym("A"), sym("B")]);
let compiled = compile_test_pattern(pattern.clone(), &["A", "B"]);
let a = SymbolId::try_new(1, compiled.num_symbols()).unwrap();
let b = SymbolId::try_new(2, compiled.num_symbols()).unwrap();
for owner in [0, 1] {
let (batch, aggregate, _) = add_count_register(base.clone(), a);
let programs = SymbolProgramTable::try_new(
vec![
test_user_symbol_program(
a,
SymbolEvalMode::Incremental,
Some(Arc::new(
datafusion_physical_expr::expressions::Literal::new(
datafusion::scalar::ScalarValue::Boolean(Some(true)),
),
)),
None,
vec![RegisterWriter::Count {
aggregate: owner,
input: None,
}],
None,
),
test_user_symbol_program(
b,
SymbolEvalMode::Static,
None,
None,
vec![],
None,
),
],
RegisterLayout::builder(
1,
vec![AggregateLayout {
slot: Some(SlotInfo::int64(0)),
value_source: AggregateValueSource::Register { slot: 0 },
..Default::default()
}],
)
.try_build()
.unwrap(),
)
.unwrap();
let constructed = build_test_executable(
batch.schema(),
NormalizedPattern::Ast(pattern.clone()),
Arc::clone(&compiled),
move |input| {
input.aggregate_programs = vec![aggregate];
input.symbols.symbol_programs = programs;
},
);
if owner == 1 {
let error = constructed.unwrap_err().to_string();
assert!(
error.contains("register writer has no managed aggregate 1"),
"{error}"
);
continue;
}
let mut matcher = PatternMatcher::from_executable(
&constructed.unwrap(),
&MatchRecognizeConfig::default(),
);
assert!(matches!(
matcher.symbol_programs()[0],
ExecutableSymbolProgram::Empty
));
assert_eq!(
(
matcher.symbol_programs().len(),
matcher.symbol_programs()[1].user().unwrap().id().index(),
matcher.symbol_programs()[2].user().unwrap().id().index()
),
(3, 1, 2)
);
let out = run_matcher_to_batch(&mut matcher, &batch);
assert_match_rows(&out, &[1, 2], &[1, 1], &[1, 2], None);
assert_eq!(
output_array::<StringArray>(&out, MatchMetadataColumn::Classifier.as_ref()),
&StringArray::from(vec!["A", "B"])
);
}
let missing = UserSymbolProgram::try_new(
a,
SymbolEvalMode::Incremental,
None,
None,
vec![],
None,
)
.unwrap_err();
assert!(missing.to_string().contains("local predicate ownership"));
let out_of_order =
test_user_symbol_program(b, SymbolEvalMode::Static, None, None, vec![], None);
let error =
SymbolProgramTable::try_new(vec![out_of_order], RegisterLayout::default())
.unwrap_err();
assert!(error.to_string().contains("out of order at dense slot 1"));
}
fn single_symbol_node(
input: LogicalPlan,
symbol: LogicalSymbolInput,
static_extractions: Vec<StaticExtractionInput>,
) -> datafusion_common::Result<MatchRecognize> {
MatchRecognize::try_new(
input,
LogicalMatchProgramInput {
partition_by: vec![],
order_by: vec![],
after_skip: AfterMatchSkip::PastLastRow,
pattern: sym("A"),
symbols: vec![symbol],
match_aware: crate::planning::ExecutableMatchProgramInput::new(
static_extractions,
vec![],
),
output: LogicalMatchOutput::rows(
RowsPerMatch::OneRow,
MatchRecognizeOutputSpec::new(vec![], vec![], vec![]),
),
symbol_relationships: SymbolRelationships::default(),
},
)
}
#[test]
fn physical_binding_rejects_invalid_slots_and_types() -> datafusion_common::Result<()> {
use datafusion_common::DataFusionError;
let input = LogicalPlanBuilder::empty(false)
.project(vec![
lit(1_i64).alias("a"),
lit(true).alias("__mr_static_predicate_and_0"),
lit(true).alias("__mr_symbol_a"),
])?
.build()?;
let predicate = col("a").gt(lit(0_i64));
let mr = single_symbol_node(
input,
LogicalSymbolInput::static_("A", predicate.clone()),
vec![StaticExtractionInput::new(
predicate,
ExtractionKind::BooleanAnd,
vec!["A".into()],
)],
)?;
let extraction_owner =
InternalSlotOwner::StaticExtraction(mr.program().static_extractions()[0].id());
let symbol_owner = InternalSlotOwner::SymbolResult(mr.program().symbols()[0].id());
let extraction_name = mr.program().internal_slot_name(extraction_owner).unwrap();
let value = || Field::new("a", DataType::Int64, false);
let symbol = || Field::new("__mr_symbol_a", DataType::Boolean, false);
let extraction =
|data_type, nullable| Field::new(&extraction_name, data_type, nullable);
let planner = DefaultPhysicalPlanner::default();
let state = SessionContext::new().state();
let planning_ctx = PhysicalPlanningContext::default();
let assert_slot_failure =
|detail: &str, owner, extractions: &[(DataType, bool)], include_symbol| {
let mut fields = vec![value()];
fields.extend(
extractions.iter().map(|(data_type, nullable)| {
extraction(data_type.clone(), *nullable)
}),
);
if include_symbol {
fields.push(symbol());
}
let Err(error) = MatcherInputBindings::bind(&mr, &Schema::new(fields)) else {
panic!("{detail} matcher slot should fail");
};
let message = error.to_string();
assert!(matches!(&error, DataFusionError::Plan(_)), "{error}");
let owner = format!("{owner:?}");
for expected in ["matcher input slot", owner.as_str(), detail] {
assert!(message.contains(expected), "{message}");
}
};
for (detail, owner, columns, include_symbol) in [
("missing", extraction_owner, vec![], true),
(
"ambiguous",
extraction_owner,
vec![(DataType::Boolean, false); 2],
true,
),
(
"type",
extraction_owner,
vec![(DataType::Int64, false)],
true,
),
(
"declared",
symbol_owner,
vec![(DataType::Boolean, false)],
false,
),
] {
assert_slot_failure(detail, owner, &columns, include_symbol);
}
let widened_schema =
Schema::new(vec![value(), extraction(DataType::Boolean, true), symbol()]);
MatcherInputBindings::bind(&mr, &widened_schema)?;
let logical_input = LogicalPlanBuilder::empty(false).build()?;
let child: Arc<dyn ExecutionPlan> =
Arc::new(EmptyExec::new(Arc::new(Schema::empty())));
for symbol in [
LogicalSymbolInput::incremental("A", lit(1_i64)),
LogicalSymbolInput::deferred("A", lit(1_i64)),
] {
let mr = single_symbol_node(logical_input.clone(), symbol, vec![])?;
let error = plan_extension(
&planner,
&mr,
std::slice::from_ref(&child),
&state,
&planning_ctx,
)
.unwrap_err();
assert!(matches!(&error, DataFusionError::Plan(_)), "{error:?}");
let message = error.to_string();
for expected in ["LogicalSymbolId(0)", "Int64", "Boolean"] {
assert!(message.contains(expected), "{message}");
}
}
Ok(())
}
fn deferred_physical_plan(expr: Expr) -> datafusion_common::Result<LogicalPlan> {
let input = LogicalPlanBuilder::empty(false)
.project(vec![lit(1_i64).alias("a")])?
.build()?;
let node =
single_symbol_node(input, LogicalSymbolInput::deferred("A", expr), vec![])?;
Ok(LogicalPlan::Extension(Extension {
node: Arc::new(node),
}))
}
fn deferred_window(next_offset: Option<i64>) -> Expr {
use datafusion::logical_expr::WindowFrameBound::{CurrentRow, Preceding};
use datafusion::logical_expr::expr::WindowFunction;
use datafusion::logical_expr::{
WindowFrame, WindowFrameUnits, WindowFunctionDefinition,
};
use datafusion_common::ScalarValue::UInt64;
let window = if let Some(offset) = next_offset {
WindowFunction::new(
WindowFunctionDefinition::AggregateUDF(crate::functions::udaf::mr_next_udaf()),
vec![col("a"), lit(offset), lit(0_i64), lit(true), lit(true)],
)
} else {
let mut window = WindowFunction::new(
WindowFunctionDefinition::AggregateUDF(
datafusion::functions_aggregate::sum::sum_udaf(),
),
vec![col("a")],
);
window.params.window_frame = WindowFrame::new_bounds(
WindowFrameUnits::Rows,
Preceding(UInt64(None)),
CurrentRow,
);
window
};
Expr::WindowFunction(Box::new(window)).gt(lit(0_i64))
}
#[tokio::test]
async fn physical_deferred_contract_preserves_errors_history_and_lookahead() {
let state = SessionContext::new().state();
let planner = MatchRecognizeQueryPlanner::new();
let missing =
deferred_physical_plan(col("missing_deferred_column").gt(lit(0_i64))).unwrap();
let error = planner
.create_physical_plan(&missing, &state)
.await
.unwrap_err();
assert!(matches!(
error.find_root(),
datafusion_common::DataFusionError::Plan(_)
));
let message = error.to_string();
assert!(message.contains("LogicalSymbolId(0)"), "{message}");
assert!(message.contains("missing_deferred_column"), "{message}");
for (next_offset, expected_lookahead) in [(None, 0), (Some(0), 0), (Some(3), 3)] {
let plan = deferred_physical_plan(deferred_window(next_offset)).unwrap();
let physical = planner.create_physical_plan(&plan, &state).await.unwrap();
let exec = physical
.downcast_ref::<MatchRecognizePatternExec>()
.unwrap();
let optional = exec.program().as_ref();
assert_eq!(
optional.max_define_lookahead_rows().as_usize(),
expected_lookahead
);
assert_eq!(optional.has_lookahead_defines(), expected_lookahead != 0);
assert_eq!(
PartitionRetention::for_program(exec.program()),
PartitionRetention::LogicalPartitionBoundaryOnly
);
if expected_lookahead == 0 {
assert!(
exec.children()[0]
.schema()
.index_of("__mr_path_id")
.is_err()
);
}
}
}
#[test]
fn executable_output_contract_rejects_unfinalizable_metadata_and_passthrough() {
let schema = Arc::new(Schema::new(vec![Field::new(
"__mr_symbol_a",
DataType::Boolean,
false,
)]));
let compiled = compile_single_a_pattern();
let pattern = single_a_normalized_pattern();
for (passthrough, metadata, fragment) in [
(
vec![],
vec![MatchMetadataColumn::PathId],
"internal path ID cannot be selected for final output",
),
(
vec![],
vec![MatchMetadataColumn::MatchNumber; 2],
"output metadata column '__mr_match_number' is selected more than once",
),
(
vec![1],
vec![],
"output passthrough index 1 is out of bounds",
),
] {
let error = build_output_contract_program(
Arc::clone(&schema),
pattern.clone(),
Arc::clone(&compiled),
RowOutputHarness::new(
MatchRecognizeOutputSpec::new(passthrough, metadata, vec![]),
Arc::from([]),
RowsPerMatch::OneRow,
),
ResolvedAfterMatchSkip::PastLastRow,
)
.unwrap_err();
assert!(error.to_string().contains(fragment), "{error}");
}
}
#[test]
fn executable_output_contract_preserves_classifier_order_and_resolves_emission() {
let input_schema = Arc::new(Schema::new(vec![
Field::new("id", DataType::UInt32, false),
Field::new("__mr_symbol_a", DataType::Boolean, false),
Field::new("__mr_symbol_b", DataType::Boolean, false),
Field::new("__mr_symbol_c", DataType::Boolean, false),
]));
let pattern = concat(vec![sym("B"), sym("A")]);
let normalized_pattern = NormalizedPattern::Ast(pattern.clone());
let compiled = compile_test_pattern(pattern, &["A", "B", "C"]);
let spec = MatchRecognizeOutputSpec::new(
vec![0],
vec![
MatchMetadataColumn::Classifier,
MatchMetadataColumn::MatchNumber,
],
vec!["C".into(), "A".into(), "B".into()],
);
let output_schema = spec.build_arrow_schema(input_schema.as_ref());
let id = |index, slots| SymbolId::try_new(index, slots).unwrap();
for (ids, detail) in [
(vec![id(3, 4), id(1, 4)], "has 2 IDs, expected 3"),
(vec![id(3, 4), id(3, 4), id(2, 4)], "duplicates symbol ID"),
(vec![id(4, 5), id(1, 4), id(2, 4)], "invalid symbol ID"),
(vec![id(1, 4), id(3, 4), id(2, 4)], "binds 'C'"),
] {
let output =
RowOutputHarness::new(spec.clone(), ids.into(), RowsPerMatch::OneRow);
let error = output
.try_build(input_schema.as_ref(), compiled.as_ref())
.expect_err(detail);
assert!(
matches!(&error, datafusion_common::DataFusionError::Internal(_)),
"{error}"
);
assert!(error.to_string().contains(detail), "{error}");
}
let output = RowOutputHarness::new(
spec.clone(),
Arc::from([id(3, 4), id(1, 4), id(2, 4)]),
RowsPerMatch::OneRow,
);
let executable = build_output_contract_program(
Arc::clone(&input_schema),
normalized_pattern,
compiled,
output.clone(),
ResolvedAfterMatchSkip::ToLast {
symbol_id: id(1, 4),
name: "A".into(),
},
)
.expect("valid output bindings should seal");
assert_eq!(executable.output_schema(), &output_schema);
let batch = make_batch(
&[1, 2],
&[
("A", vec![false, true]),
("B", vec![true, false]),
("C", vec![false, false]),
],
);
let mut matcher =
PatternMatcher::from_executable(&executable, &MatchRecognizeConfig::default());
let mut driver =
CollectionTestDriver::try_new_with_matcher(batch, 4, output, &mut matcher)
.unwrap();
assert_eq!(
driver
.step(crate::config::YieldPolicy::Disabled, None)
.unwrap(),
MrComputeStep::Complete
);
driver.flush_output(2, true, None).unwrap();
let out = driver.concat_output();
assert_eq!(u32_values(&out, "id"), [1, 2]);
for (column, expected) in [
("__mr_classifier_c", vec![false, false]),
("__mr_classifier_a", vec![false, true]),
("__mr_classifier_b", vec![true, false]),
] {
assert_eq!(
output_array::<BooleanArray>(&out, column),
&BooleanArray::from(expected),
"{column}"
);
}
assert_eq!(
output_array::<StringArray>(&out, MatchMetadataColumn::Classifier.as_ref()),
&StringArray::from(vec!["B", "A"])
);
assert_eq!(
i64_values(&out, MatchMetadataColumn::MatchNumber.as_ref()),
[1, 1]
);
}
#[test]
fn matcher_construction_rejects_missing_or_wrong_domain_sum_input() {
let schema = Arc::new(Schema::new(vec![
Field::new("amount", DataType::Int64, true),
Field::new("__mr_symbol_a", DataType::Boolean, false),
]));
let compiled = compile_single_a_pattern();
for (decimal, name, fragment) in [
(
false,
"missing",
"VM row input column 'missing' is missing from the input schema",
),
(
true,
"amount",
"VM row input column 'amount' has resolved domain Int64, incompatible with Decimal128 accumulation",
),
] {
let count_slot = if decimal { 2 } else { 1 };
let source = if decimal {
AggregateValueSource::RegisterD128 { slot: 0 }
} else {
AggregateValueSource::Register { slot: 0 }
};
let slot = if decimal {
SlotInfo::decimal128(0, 0)
} else {
SlotInfo::int64(0)
};
let layout = RegisterLayout::builder(
count_slot + 1,
vec![AggregateLayout {
slot: Some(slot),
value_source: source,
nonnull_count_slot: Some(count_slot),
}],
)
.row_inputs(vec![name.into()], vec![false])
.try_build()
.unwrap();
let programs = test_symbol_programs_with_vm_for_automaton(
compiled.as_ref(),
&[],
&[],
vec![vec![RegisterWriter::Accumulate {
aggregate: 0,
input: 0,
nullable: true,
}]],
layout,
);
let error = build_test_matcher(
Arc::clone(&schema),
single_a_normalized_pattern(),
Arc::clone(&compiled),
&MatchRecognizeConfig::default(),
move |input| input.symbols.symbol_programs = programs,
)
.err()
.expect("invalid SUM source must reject construction");
assert!(error.to_string().contains(fragment), "{error}");
}
}
#[test]
fn incremental_predicate_without_aggregates_is_evaluated_for_each_candidate() {
let batch = make_batch(&[1, 2], &[("A", vec![true, true])]);
let compiled = compile_single_a_pattern();
let a = SymbolId::try_new(1, compiled.num_symbols()).unwrap();
for accepted in [false, true] {
let calls = Arc::new(AtomicUsize::new(0));
let predicate: Arc<dyn PhysicalExpr> =
Arc::new(CountingBoolExpr::returning(Arc::clone(&calls), accepted));
let programs =
test_symbol_programs_for_automaton(compiled.as_ref(), &[(a, predicate)], 0);
let mut matcher = build_test_matcher(
batch.schema(),
single_a_normalized_pattern(),
Arc::clone(&compiled),
&MatchRecognizeConfig::default(),
move |input| input.symbols.symbol_programs = programs,
)
.unwrap();
let (out, _, _, _, _) =
run_partitioned_matcher_to_batches(&mut matcher, &batch, 0);
assert_eq!(calls.load(Ordering::SeqCst), 2);
if accepted {
assert_eq!(
datafusion::arrow::compute::concat_batches(&out[0].schema(), &out)
.unwrap()
.num_rows(),
2
);
} else {
assert!(out.is_empty());
}
}
}
#[test]
fn executable_base_variant_shares_tables_across_runtime_path_settings() {
let pattern = concat(vec![
sym("A"),
rep(sym("B"), RepetitionQuantifier::ZeroOrMore),
sym("C"),
]);
let automaton = compile_test_pattern(pattern.clone(), &["A", "B", "C"]);
let batch = make_batch(
&[1],
&[("A", vec![true]), ("B", vec![true]), ("C", vec![true])],
);
let mut input = test_executable_input(
batch.schema(),
NormalizedPattern::Ast(pattern),
Arc::clone(&automaton),
test_symbol_columns(&automaton, &[], batch.schema().as_ref(), &[]).unwrap(),
ResolvedAfterMatchSkip::PastLastRow,
);
input.symbols.symbol_programs = compact_symbol_programs(&automaton);
let executable = ExecutableMatchProgram::try_new(input).unwrap();
let base = &executable.base_variant;
assert!(matches!(
base.path_representation(),
PathRepresentation::CompactPrefixSuffix(_)
));
let mut config = MatchRecognizeConfig::default();
let matcher = PatternMatcher::from_executable(&executable, &config);
assert!(Arc::ptr_eq(base, matcher.program.base_variant()));
config.diagnostics.disable_compact_paths = true;
let forced = PatternMatcher::from_executable(&executable, &config);
let forced_base = forced.program.base_variant();
assert!(!Arc::ptr_eq(base, forced_base));
assert!(matches!(
forced_base.path_representation(),
PathRepresentation::ArenaForced
));
assert!(std::ptr::eq(
base.symbol_execution_plan(),
forced_base.symbol_execution_plan(),
));
assert!(std::ptr::eq(
base.start_symbol_plan(),
forced_base.start_symbol_plan(),
));
assert!(Arc::ptr_eq(
base.lane_scan_program().unwrap(),
forced_base.lane_scan_program().unwrap(),
));
assert!(base.path_representation().uses_compact_paths());
}
#[test]
fn qualified_count_accumulator_with_non_primitive_unqualified_accumulator_disables_value_equivalence()
{
use crate::core::{AggregateId, managed_aggregate_col_name};
use crate::execution::matching::ResolvedInputColumn;
use crate::execution::matching::{AggregateProgram, add_count_accumulator};
use crate::planning::{AccumulatorInputMode, ManagedAggregateBackend};
use datafusion::functions_aggregate::first_last::first_value_udaf;
use datafusion::logical_expr::Operator;
use datafusion::logical_expr::expr::{AggregateFunction, AggregateFunctionParams};
use datafusion::physical_expr::aggregate::AggregateExprBuilder;
use datafusion::physical_plan::expressions::{BinaryExpr, Column, Literal};
use datafusion::scalar::ScalarValue;
let pattern = concat(vec![
rep(
alt(vec![sym("A"), sym("B")]),
RepetitionQuantifier::OneOrMore,
),
sym("C"),
]);
let compiled = compile_test_pattern(pattern.clone(), &["A", "B", "C"]);
let a = SymbolId::try_new(1, compiled.num_symbols()).unwrap();
let c = SymbolId::try_new(3, compiled.num_symbols()).unwrap();
for (non_primitive, expect_value_equiv) in [(true, false), (false, true)] {
let base = make_batch(
&[1, 2, 3],
&[
("A", vec![true, true, false]),
("B", vec![false, true, false]),
("C", vec![false, false, false]),
],
);
let mut fields = base.schema().fields().to_vec();
fields.push(Arc::new(Field::new("txt", DataType::Utf8, true)));
let mut columns = base.columns().to_vec();
columns.push(Arc::new(StringArray::from(vec!["x", "y", "z"])) as ArrayRef);
let with_txt =
RecordBatch::try_new(Arc::new(Schema::new(fields)), columns).unwrap();
let txt_idx = with_txt.schema().index_of("txt").unwrap();
let (with_count, count_agg, count_col) = add_count_accumulator(with_txt, a);
let count_col_idx = with_count.schema().index_of(&count_col).unwrap();
let first_col = managed_aggregate_col_name(1);
let (arg_name, arg_idx) = if non_primitive {
("txt", txt_idx)
} else {
("id", 0)
};
let first_type = with_count.schema().field(arg_idx).data_type().clone();
let first_nulls =
datafusion::arrow::array::new_null_array(&first_type, with_count.num_rows());
let mut fields = with_count.schema().fields().to_vec();
fields.push(Arc::new(Field::new(&first_col, first_type, true)));
let schema = Arc::new(Schema::new(fields));
let mut columns = with_count.columns().to_vec();
columns.push(first_nulls);
let batch = RecordBatch::try_new(Arc::clone(&schema), columns).unwrap();
let first_udaf = first_value_udaf();
let first_expr = Arc::new(
AggregateExprBuilder::new(
Arc::clone(&first_udaf),
vec![Arc::new(Column::new(arg_name, arg_idx))],
)
.schema(Arc::clone(&schema))
.alias(&first_col)
.build()
.unwrap(),
);
let first_fn = AggregateFunction {
func: first_udaf,
params: AggregateFunctionParams {
args: vec![],
distinct: false,
filter: None,
order_by: vec![],
null_treatment: None,
},
};
let first_agg = AggregateProgram::try_new(
AggregateId::try_new(1, 2).unwrap(),
first_expr,
first_fn,
ManagedAggregateBackend::Accumulator,
AccumulatorInputMode::Batch,
false,
ResolvedInputColumn::new_validated(schema.fields().len() - 1),
None,
schema.as_ref(),
)
.unwrap();
let c_predicate: Arc<dyn PhysicalExpr> = Arc::new(BinaryExpr::new(
Arc::new(BinaryExpr::new(
Arc::new(Column::new("id", 0)),
Operator::Eq,
Arc::new(Literal::new(ScalarValue::UInt32(Some(3)))),
)),
Operator::And,
Arc::new(BinaryExpr::new(
Arc::new(Column::new(&count_col, count_col_idx)),
Operator::Eq,
Arc::new(Literal::new(ScalarValue::Int64(Some(1)))),
)),
));
let programs = test_symbol_programs_with_vm_for_automaton(
compiled.as_ref(),
&[(c, c_predicate)],
&[],
vec![vec![], vec![], vec![]],
RegisterLayout::empty_compact(2),
);
let mut matcher = build_test_matcher(
Arc::clone(&schema),
NormalizedPattern::Ast(pattern.clone()),
Arc::clone(&compiled),
&deterministic_test_config(),
|input| {
input.aggregate_programs = vec![count_agg, first_agg];
input.symbols.symbol_programs = programs;
input.set_rows_per_match(RowsPerMatch::AllRows(EmptyMatchesMode::Show));
},
)
.unwrap();
assert_eq!(
matcher.program.supports_value_equivalence(),
expect_value_equiv
);
let out = run_matcher_to_batch(&mut matcher, &batch);
assert_match_rows(&out, &[1, 2, 3], &[1, 1, 1], &[1, 2, 3], None);
assert_eq!(
output_array::<StringArray>(&out, MatchMetadataColumn::Classifier.as_ref()),
&StringArray::from(vec!["A", "B", "C"])
);
}
}