use std::collections::BTreeSet;
use std::sync::Arc;
use crate::core::{
EmptyMatchesMode, MatchMetadataColumn, MatchRecognizeOutputSpec, MatchSummaryField,
NavigationOffsets, RowsPerMatch, SymbolId,
};
use crate::functions::navigation_common::nullable_navigation_data_type;
use crate::nfa::CompiledAutomaton;
use crate::planning::logical::MAX_DIRECT_EDGE_OFFSET;
use crate::planning::logical::MetadataEndpoint;
pub(crate) use crate::planning::logical::SelectedReductionOp;
use datafusion::arrow::datatypes::{DataType, Schema, SchemaRef};
use datafusion::common::{DataFusionError, Result, internal_err};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct ResolvedMatchNumberColumn(usize);
impl ResolvedMatchNumberColumn {
const fn new_validated(index: usize) -> Self {
Self(index)
}
pub(crate) const fn index(self) -> usize {
self.0
}
}
#[derive(Debug, Clone)]
pub(crate) struct ExecutableRowStreamPlan {
schema: SchemaRef,
passthrough_schema: SchemaRef,
spec: MatchRecognizeOutputSpec,
classifier_bitset_symbol_ids: Arc<[SymbolId]>,
match_number_column: Option<ResolvedMatchNumberColumn>,
has_classifier: bool,
has_sequence_number: bool,
has_excluded: bool,
rows_per_match: RowsPerMatch,
original_rows_per_match: RowsPerMatch,
suppress_navigation_buffer_rows: bool,
}
impl ExecutableRowStreamPlan {
fn try_new(
input_schema: &Schema,
spec: MatchRecognizeOutputSpec,
classifier_bitset_symbol_ids: Arc<[SymbolId]>,
summary_fields: &[MatchSummaryField],
rows_per_match: RowsPerMatch,
automaton: &CompiledAutomaton,
) -> Result<Arc<Self>> {
validate_metadata_columns(&spec)?;
validate_passthrough_indices(input_schema, &spec)?;
validate_classifier_ids(&spec, &classifier_bitset_symbol_ids, automaton)?;
let schema = spec.build_arrow_schema_with_summaries(input_schema, summary_fields);
let passthrough_len = spec.passthrough_input_indices().len();
let passthrough_schema = Arc::new(Schema::new_with_metadata(
schema.fields()[..passthrough_len].to_vec(),
schema.metadata().clone(),
));
let match_number_column = spec
.metadata_columns()
.iter()
.position(|column| *column == MatchMetadataColumn::MatchNumber)
.map(|metadata_index| {
passthrough_len
.checked_add(metadata_index)
.map(ResolvedMatchNumberColumn::new_validated)
.ok_or_else(|| {
DataFusionError::Internal(
"MATCH_RECOGNIZE MATCH_NUMBER output index overflow"
.to_string(),
)
})
})
.transpose()?;
Ok(Arc::new(Self {
original_rows_per_match: rows_per_match.clone(),
rows_per_match,
suppress_navigation_buffer_rows: false,
has_classifier: spec
.metadata_columns()
.contains(&MatchMetadataColumn::Classifier),
has_sequence_number: spec
.metadata_columns()
.contains(&MatchMetadataColumn::MatchSequenceNumber),
has_excluded: spec
.metadata_columns()
.contains(&MatchMetadataColumn::Excluded),
schema,
passthrough_schema,
spec,
classifier_bitset_symbol_ids,
match_number_column,
}))
}
pub(crate) fn schema(&self) -> &SchemaRef {
&self.schema
}
pub(crate) fn passthrough_schema(&self) -> &SchemaRef {
&self.passthrough_schema
}
pub(crate) fn spec(&self) -> &MatchRecognizeOutputSpec {
&self.spec
}
pub(crate) fn classifier_bitset_symbol_ids(&self) -> &Arc<[SymbolId]> {
&self.classifier_bitset_symbol_ids
}
pub(crate) const fn match_number_column(&self) -> Option<ResolvedMatchNumberColumn> {
self.match_number_column
}
pub(crate) const fn has_classifier(&self) -> bool {
self.has_classifier
}
pub(crate) const fn has_sequence_number(&self) -> bool {
self.has_sequence_number
}
pub(crate) const fn has_excluded(&self) -> bool {
self.has_excluded
}
pub(crate) const fn navigation_offsets(&self) -> NavigationOffsets {
self.spec.navigation_offsets()
}
pub(crate) const fn rows_per_match(&self) -> &RowsPerMatch {
&self.rows_per_match
}
pub(crate) const fn original_rows_per_match(&self) -> &RowsPerMatch {
&self.original_rows_per_match
}
pub(crate) fn emits_navigation_buffer_rows(&self) -> bool {
!self.navigation_offsets().is_zero() && !self.suppress_navigation_buffer_rows
}
pub(crate) fn empty_matches_mode(&self) -> &EmptyMatchesMode {
static SHOW: EmptyMatchesMode = EmptyMatchesMode::Show;
match &self.rows_per_match {
RowsPerMatch::OneRow => &SHOW,
RowsPerMatch::AllRows(mode) => mode,
}
}
pub(crate) fn emits_virtual_empty_match(&self) -> bool {
!matches!(self.empty_matches_mode(), EmptyMatchesMode::Omit)
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) enum WinningValue {
Int32(Option<i32>),
Int64(Option<i64>),
Float64(Option<f64>),
Decimal128(Option<i128>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct ExecutableReduction {
pub(crate) op: SelectedReductionOp,
pub(crate) input_column: usize,
pub(crate) input_type: DataType,
pub(crate) output_type: DataType,
pub(crate) managed_aggregate: Option<usize>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct ExecutableEdge {
pub(crate) input_column: usize,
pub(crate) last: bool,
pub(crate) logical_offset: usize,
pub(crate) physical_shift: i64,
pub(crate) default_value: Option<datafusion::common::ScalarValue>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
enum SelectedValue {
Count,
Edge(ExecutableEdge),
Reduction(ExecutableReduction),
Metadata(MetadataEndpoint),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct ExecutableDirectCountSummary {
field: MatchSummaryField,
symbol_id: Option<SymbolId>,
value: SelectedValue,
}
impl ExecutableDirectCountSummary {
pub(crate) fn new(field: MatchSummaryField, symbol_id: Option<SymbolId>) -> Self {
Self {
field,
symbol_id,
value: SelectedValue::Count,
}
}
#[cfg(test)]
pub(crate) fn new_edge(
field: MatchSummaryField,
symbol_id: Option<SymbolId>,
input_column: usize,
last: bool,
) -> Self {
Self::new_edge_spec(
field,
symbol_id,
ExecutableEdge {
input_column,
last,
logical_offset: 0,
physical_shift: 0,
default_value: None,
},
)
}
pub(crate) fn new_edge_spec(
field: MatchSummaryField,
symbol_id: Option<SymbolId>,
edge: ExecutableEdge,
) -> Self {
Self {
field,
symbol_id,
value: SelectedValue::Edge(edge),
}
}
pub(crate) fn format_selected_value(&self, prefix: &str, input: &Schema) -> String {
let name = self.field().column_name();
match &self.value {
SelectedValue::Reduction(reduction) => {
let column = input.field(reduction.input_column).name();
let function = format!("{:?}", reduction.op).to_uppercase();
let route = if reduction.managed_aggregate.is_some() {
"DirectRegister"
} else {
"DirectSliceAgg"
};
format!("{name}={function}({prefix}{column}):{route}")
}
SelectedValue::Metadata(endpoint) => {
let function = if endpoint.last() { "LAST" } else { "FIRST" };
let column = endpoint.column().measure_function_name().to_uppercase();
format!("{name}={function}({prefix}{column}()):DirectEdge")
}
SelectedValue::Edge(edge) => {
let column = input.field(edge.input_column).name();
let function = if edge.last { "LAST" } else { "FIRST" };
let inner = if edge.logical_offset == 0 {
format!("{function}({prefix}{column})")
} else {
format!("{function}({prefix}{column}, {})", edge.logical_offset)
};
let expr = if edge.physical_shift < 0 {
format!("PREV({inner}, {})", edge.physical_shift.unsigned_abs())
} else if edge.physical_shift > 0 {
format!("NEXT({inner}, {})", edge.physical_shift)
} else {
inner
};
format!("{name}={expr}:DirectEdge")
}
SelectedValue::Count => format!("{name}=COUNT({prefix}*):DirectCount"),
}
}
pub(crate) const fn edge(&self) -> Option<&ExecutableEdge> {
match &self.value {
SelectedValue::Edge(edge) => Some(edge),
_ => None,
}
}
pub(crate) fn new_metadata(
field: MatchSummaryField,
symbol_id: Option<SymbolId>,
endpoint: MetadataEndpoint,
) -> Self {
Self {
field,
symbol_id,
value: SelectedValue::Metadata(endpoint),
}
}
pub(crate) const fn metadata(&self) -> Option<MetadataEndpoint> {
match self.value {
SelectedValue::Metadata(endpoint) => Some(endpoint),
_ => None,
}
}
pub(crate) fn new_reduction(
field: MatchSummaryField,
symbol_id: Option<SymbolId>,
reduction: ExecutableReduction,
) -> Self {
Self {
field,
symbol_id,
value: SelectedValue::Reduction(reduction),
}
}
pub(crate) const fn reduction(&self) -> Option<&ExecutableReduction> {
match &self.value {
SelectedValue::Reduction(reduction) => Some(reduction),
_ => None,
}
}
pub(crate) const fn input_column(&self) -> Option<usize> {
match &self.value {
SelectedValue::Count | SelectedValue::Metadata(_) => None,
SelectedValue::Edge(edge) => Some(edge.input_column),
SelectedValue::Reduction(reduction) => Some(reduction.input_column),
}
}
pub(crate) fn field(&self) -> &MatchSummaryField {
&self.field
}
pub(crate) const fn symbol_id(&self) -> Option<SymbolId> {
self.symbol_id
}
}
#[derive(Debug, Clone)]
pub(crate) struct ExecutableOutputPlan {
stream: Arc<ExecutableRowStreamPlan>,
finalizer: ExecutableOutputFinalizer,
}
#[derive(Debug, Clone)]
pub(crate) enum ExecutableOutputFinalizer {
Rows,
DirectCounts {
summaries: Arc<[ExecutableDirectCountSummary]>,
},
}
impl ExecutableOutputPlan {
pub(crate) fn with_synthetic_row_filter(
mut self: Arc<Self>,
rows_per_match: RowsPerMatch,
) -> Result<Arc<Self>> {
use EmptyMatchesMode::{Omit, Show, WithUnmatched};
use RowsPerMatch::AllRows;
if !matches!(self.finalizer, ExecutableOutputFinalizer::Rows)
|| self.stream.emits_navigation_buffer_rows()
|| !self.stream.classifier_bitset_symbol_ids().is_empty()
|| !matches!(
(self.rows_per_match(), &rows_per_match),
(AllRows(WithUnmatched), AllRows(_))
| (AllRows(Show), AllRows(Show | Omit))
| (AllRows(Omit), AllRows(Omit))
)
{
return internal_err!("invalid MATCH_RECOGNIZE synthetic row filter");
}
let stream = Arc::make_mut(&mut Arc::make_mut(&mut self).stream);
stream.rows_per_match = rows_per_match;
Ok(self)
}
pub(crate) fn try_rows(
input_schema: &Schema,
spec: MatchRecognizeOutputSpec,
classifier_bitset_symbol_ids: Arc<[SymbolId]>,
rows_per_match: RowsPerMatch,
automaton: &CompiledAutomaton,
) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
stream: ExecutableRowStreamPlan::try_new(
input_schema,
spec,
classifier_bitset_symbol_ids,
&[],
rows_per_match,
automaton,
)?,
finalizer: ExecutableOutputFinalizer::Rows,
}))
}
pub(crate) fn try_direct_counts(
input_schema: &Schema,
spec: MatchRecognizeOutputSpec,
classifier_bitset_symbol_ids: Arc<[SymbolId]>,
summaries: Vec<ExecutableDirectCountSummary>,
automaton: &CompiledAutomaton,
) -> Result<Arc<Self>> {
validate_direct_counts(
&summaries,
input_schema,
spec.navigation_offsets(),
automaton,
)?;
let fields = summaries
.iter()
.map(|summary| summary.field.clone())
.collect::<Vec<_>>();
let mut stream = ExecutableRowStreamPlan::try_new(
input_schema,
spec,
classifier_bitset_symbol_ids,
&fields,
RowsPerMatch::OneRow,
automaton,
)?;
Arc::make_mut(&mut stream).suppress_navigation_buffer_rows = true;
Ok(Arc::new(Self {
stream,
finalizer: ExecutableOutputFinalizer::DirectCounts {
summaries: summaries.into(),
},
}))
}
pub(crate) fn stream(&self) -> &Arc<ExecutableRowStreamPlan> {
&self.stream
}
pub(crate) fn schema(&self) -> &SchemaRef {
self.stream().schema()
}
pub(crate) fn spec(&self) -> &MatchRecognizeOutputSpec {
self.stream().spec()
}
pub(crate) fn classifier_bitset_symbol_ids(&self) -> &Arc<[SymbolId]> {
self.stream().classifier_bitset_symbol_ids()
}
pub(crate) fn match_number_column(&self) -> Option<ResolvedMatchNumberColumn> {
self.stream().match_number_column()
}
pub(crate) fn rows_per_match(&self) -> &RowsPerMatch {
self.stream.rows_per_match()
}
pub(crate) const fn finalizer(&self) -> &ExecutableOutputFinalizer {
&self.finalizer
}
pub(crate) fn summary_count(&self) -> usize {
match &self.finalizer {
ExecutableOutputFinalizer::Rows => 0,
ExecutableOutputFinalizer::DirectCounts { summaries } => summaries.len(),
}
}
pub(crate) fn mark_referenced_input_columns(&self, needed: &mut [bool]) {
for &idx in self.spec().passthrough_input_indices() {
if let Some(slot) = needed.get_mut(idx) {
*slot = true;
}
}
if let ExecutableOutputFinalizer::DirectCounts { summaries } = &self.finalizer {
for summary in summaries.iter() {
if let Some(idx) = summary.input_column()
&& let Some(slot) = needed.get_mut(idx)
{
*slot = true;
}
}
}
}
pub(crate) fn with_appended_passthrough(
&self,
input_schema: &Schema,
input_index: usize,
automaton: &CompiledAutomaton,
) -> Result<Arc<Self>> {
if input_schema.fields().len() != input_index.saturating_add(1) {
return internal_err!(
"MATCH_RECOGNIZE private passthrough must be the final input column"
);
}
let mut passthrough = self.spec().passthrough_input_indices().to_vec();
passthrough.push(input_index);
let spec = self
.spec()
.clone()
.with_passthrough_input_indices(passthrough);
let fields = match &self.finalizer {
ExecutableOutputFinalizer::Rows => Vec::new(),
ExecutableOutputFinalizer::DirectCounts { summaries } => summaries
.iter()
.map(|summary| summary.field.clone())
.collect(),
};
let mut stream = ExecutableRowStreamPlan::try_new(
input_schema,
spec,
Arc::clone(self.classifier_bitset_symbol_ids()),
&fields,
self.rows_per_match().clone(),
automaton,
)?;
let updated = Arc::make_mut(&mut stream);
updated.original_rows_per_match = self.stream.original_rows_per_match.clone();
updated.suppress_navigation_buffer_rows =
self.stream.suppress_navigation_buffer_rows;
Ok(Arc::new(Self {
stream,
..self.clone()
}))
}
}
fn validate_metadata_columns(spec: &MatchRecognizeOutputSpec) -> Result<()> {
for (index, column) in spec.metadata_columns().iter().enumerate() {
if *column == MatchMetadataColumn::PathId {
return internal_err!(
"MATCH_RECOGNIZE internal path ID cannot be selected for final output"
);
}
if spec.metadata_columns()[..index].contains(column) {
return internal_err!(
"MATCH_RECOGNIZE output metadata column '{}' is selected more than once",
column.as_ref()
);
}
}
Ok(())
}
fn validate_passthrough_indices(
input_schema: &Schema,
spec: &MatchRecognizeOutputSpec,
) -> Result<()> {
if let Some(index) = spec
.passthrough_input_indices()
.iter()
.copied()
.find(|index| *index >= input_schema.fields().len())
{
return internal_err!(
"MATCH_RECOGNIZE output passthrough index {index} is out of bounds for the validated input schema with {} columns",
input_schema.fields().len()
);
}
Ok(())
}
fn validate_classifier_ids(
spec: &MatchRecognizeOutputSpec,
ids: &[SymbolId],
automaton: &CompiledAutomaton,
) -> Result<()> {
if ids.len() != spec.classifier_bitset_symbols().len() {
return internal_err!(
"MATCH_RECOGNIZE classifier output has {} IDs, expected {}",
ids.len(),
spec.classifier_bitset_symbols().len()
);
}
let mut seen = BTreeSet::new();
for (position, (id, name)) in
ids.iter().zip(spec.classifier_bitset_symbols()).enumerate()
{
if !seen.insert(*id) {
return internal_err!(
"MATCH_RECOGNIZE classifier output position {position} duplicates symbol ID {id}"
);
}
let Some(Some(compiled_name)) = automaton.id_to_symbol().get(id.index()) else {
return internal_err!(
"MATCH_RECOGNIZE classifier output position {position} has invalid symbol ID {id}"
);
};
if compiled_name != name {
return internal_err!(
"MATCH_RECOGNIZE classifier output position {position} binds '{name}' to compiled symbol {:?}",
Some(compiled_name)
);
}
}
Ok(())
}
fn validate_direct_counts(
summaries: &[ExecutableDirectCountSummary],
input_schema: &Schema,
navigation_offsets: NavigationOffsets,
automaton: &CompiledAutomaton,
) -> Result<()> {
let mut output_ids = BTreeSet::new();
for (position, summary) in summaries.iter().enumerate() {
let id = summary.field.output_id();
if !output_ids.insert(id) {
return internal_err!(
"MATCH_RECOGNIZE summary output ID {id} is selected more than once"
);
}
let field = summary.field.arrow_field();
match &summary.value {
SelectedValue::Reduction(reduction)
if !input_schema
.fields()
.get(reduction.input_column)
.is_some_and(|input| input.data_type() == &reduction.input_type)
|| field.data_type() != &reduction.output_type
|| !reduction
.op
.accepts(&reduction.input_type, &reduction.output_type)
|| field.is_nullable()
!= (reduction.op != SelectedReductionOp::Count) =>
{
return internal_err!(
"MATCH_RECOGNIZE reduction {position} has incompatible input or result type"
);
}
SelectedValue::Metadata(endpoint)
if field.data_type() != &endpoint.column().data_type()
|| !field.is_nullable() =>
{
return internal_err!(
"MATCH_RECOGNIZE metadata endpoint {position} has incompatible field {field:?}"
);
}
SelectedValue::Edge(edge) => {
let Some(input) = input_schema.fields().get(edge.input_column) else {
return internal_err!(
"MATCH_RECOGNIZE edge input {} is out of bounds",
edge.input_column
);
};
if nullable_navigation_data_type(input.data_type()) != *field.data_type()
|| input.metadata() != field.metadata()
|| !field.is_nullable()
{
return internal_err!(
"MATCH_RECOGNIZE edge summary {position} field {field:?} cannot gather input {input:?}"
);
}
if edge.logical_offset > MAX_DIRECT_EDGE_OFFSET {
return internal_err!(
"MATCH_RECOGNIZE edge summary {position} logical offset {} exceeds limit {MAX_DIRECT_EDGE_OFFSET}",
edge.logical_offset
);
}
let shift_ok = if edge.physical_shift < 0 {
edge.physical_shift.unsigned_abs()
<= navigation_offsets.previous().as_u64()
} else {
(edge.physical_shift as u64) <= navigation_offsets.next().as_u64()
};
if !shift_ok {
return internal_err!(
"MATCH_RECOGNIZE edge summary {position} shift {} exceeds navigation offsets {:?}",
edge.physical_shift,
navigation_offsets
);
}
if let Some(default) = &edge.default_value
&& (default.is_null() || default.data_type() != *field.data_type())
{
return internal_err!(
"MATCH_RECOGNIZE edge summary {position} default {default:?} does not match field {field:?}"
);
}
}
SelectedValue::Count
if field.data_type() != &DataType::Int64 || field.is_nullable() =>
{
return internal_err!(
"MATCH_RECOGNIZE direct count summary {position} requires a non-null Int64 field, got {field:?}"
);
}
SelectedValue::Count
| SelectedValue::Reduction(_)
| SelectedValue::Metadata(_) => {}
}
if let Some(symbol_id) = summary.symbol_id
&& !matches!(
automaton.id_to_symbol().get(symbol_id.index()),
Some(Some(_))
)
{
return internal_err!(
"MATCH_RECOGNIZE direct count summary {position} has invalid symbol ID {symbol_id}"
);
}
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
use crate::core::{NormalizedPattern, Pattern, Symbol};
use datafusion::arrow::datatypes::Field;
fn automaton() -> CompiledAutomaton {
CompiledAutomaton::compile(
&NormalizedPattern::Ast(Pattern::Symbol(Symbol::Named("A".into()))),
&["A".into()],
)
.unwrap()
}
#[test]
fn synthetic_row_filters_only_tighten_and_survive_private_projection() -> Result<()> {
use EmptyMatchesMode::{Omit, Show, WithUnmatched};
use RowsPerMatch::AllRows;
let graph = automaton();
let key = Field::new("k", DataType::Int64, false);
let base = ExecutableOutputPlan::try_rows(
&Schema::new(vec![key.clone()]),
MatchRecognizeOutputSpec::new(vec![0], vec![], vec![]),
Arc::from([]),
AllRows(WithUnmatched),
&graph,
)?;
let show = Arc::clone(&base).with_synthetic_row_filter(AllRows(Show))?;
assert_eq!(base.rows_per_match(), &AllRows(WithUnmatched));
assert!(show.stream().emits_virtual_empty_match());
assert!(Arc::ptr_eq(base.schema(), show.schema()));
assert!(
Arc::clone(&show)
.with_synthetic_row_filter(AllRows(WithUnmatched))
.is_err()
);
let projected = show
.with_synthetic_row_filter(AllRows(Omit))?
.with_appended_passthrough(
&Schema::new(vec![key, Field::new("private", DataType::Int64, true)]),
1,
&graph,
)?;
assert_eq!(projected.rows_per_match(), &AllRows(Omit));
assert_eq!(
projected.stream().original_rows_per_match(),
&AllRows(WithUnmatched)
);
Ok(())
}
#[test]
fn direct_counts_keep_one_row_cardinality_without_private_rows() {
for with_count in [false, true] {
let summaries = if with_count {
vec![ExecutableDirectCountSummary::new(
MatchSummaryField::new(
0,
Arc::new(Field::new("count", DataType::Int64, false)),
),
None,
)]
} else {
vec![]
};
let plan = ExecutableOutputPlan::try_direct_counts(
&Schema::empty(),
MatchRecognizeOutputSpec::new(vec![], vec![], vec![]),
Arc::from([]),
summaries,
&automaton(),
)
.unwrap();
let ExecutableOutputFinalizer::DirectCounts { summaries } = plan.finalizer()
else {
panic!("expected native counts");
};
assert_eq!(summaries.len(), usize::from(with_count));
assert_eq!(plan.rows_per_match(), &RowsPerMatch::OneRow);
}
}
#[test]
fn direct_edges_bind_nullable_values_to_original_input_types() {
let input = Schema::new(vec![
Field::new("z", DataType::Utf8, false),
Field::new("value", DataType::Int32, true),
]);
let automaton = automaton();
let field = MatchSummaryField::new(
0,
Arc::new(Field::new("endpoint", DataType::Int32, true)),
);
for (index, valid) in [(0, false), (1, true), (2, false)] {
let edge =
ExecutableDirectCountSummary::new_edge(field.clone(), None, index, true);
assert_eq!(
validate_direct_counts(
&[edge],
&input,
NavigationOffsets::ZERO,
&automaton
)
.is_ok(),
valid
);
}
}
#[test]
fn direct_count_sealing_validates_ids_fields_and_symbol_targets() {
for (ids, data_type, nullable, symbol, error) in [
(vec![4, 5], DataType::Int64, false, None, None),
(
vec![4, 4],
DataType::Int64,
false,
None,
Some("output ID 4 is selected more than once"),
),
(
vec![4],
DataType::Int32,
false,
None,
Some("requires a non-null Int64 field"),
),
(
vec![4],
DataType::Int64,
true,
None,
Some("requires a non-null Int64 field"),
),
(
vec![4],
DataType::Int64,
false,
Some(SymbolId::try_new(2, 3).unwrap()),
Some("invalid symbol ID 2"),
),
] {
let summaries = ids
.into_iter()
.map(|id| {
ExecutableDirectCountSummary::new(
MatchSummaryField::new(
id,
Arc::new(Field::new("count", data_type.clone(), nullable)),
),
symbol,
)
})
.collect();
let result = ExecutableOutputPlan::try_direct_counts(
&Schema::empty(),
MatchRecognizeOutputSpec::new(vec![], vec![], vec![]),
Arc::from([]),
summaries,
&automaton(),
);
if let Some(expected) = error {
let error = result.unwrap_err();
assert!(error.to_string().contains(expected), "{error}");
} else {
assert!(result.is_ok());
}
}
}
}