pub use crate::core::{
AfterMatchSkip, EmptyMatchesMode, MatchMetadataColumn, MatchRecognizeDefinition,
MatchRecognizeMeasure, MatchRecognizeNamedExpression, MatchRecognizeNullOrdering,
MatchRecognizeOutputContract, MatchRecognizeSortDirection, MatchRecognizeSortExpr,
MatchRecognizeSpec, MatchRecognizeSpecError, MatchRecognizeSpecResult,
NormalizedPattern, Pattern, PatternStructuralInfo, RepetitionPreference,
RepetitionQuantifier, RowsPerMatch, Symbol,
};
use datafusion::logical_expr::{AggregateUDF, ScalarUDF};
use datafusion_common::config::ConfigOptions;
pub(crate) use deferred_program::{
DeferredHistorySlotOwner, DeferredOperationSpec, DeferredProgramSpec,
};
pub use define::{
DefineRequirement, MatchRecognizeRequirements, analyze_match_recognize_requirements,
};
pub(crate) use expressions::NamedExpr;
pub(crate) use extract::{
ManagedAggregate, ManagedAggregateBackend, ManagedAggregateBackendSet,
};
pub(crate) use hybrid_guard::LogicalHybridGuardExpr;
#[cfg(test)]
pub(crate) use logical::ExecutableMatchProgramInput;
pub use logical::MatchRecognize;
pub(crate) use physical_derivation::compile_match_program;
pub(crate) use routed_program::{
AccumulatorInputMode, MatchCompilerOptions, RoutedAggregate, RoutedEvaluator,
RoutedHistoryGuard, RoutedMatchProgram, RoutedPredicate, RoutedSymbol,
};
pub use source::{
BoundMatchAggregateCall, BoundMatchExpr, BoundMatchExprSort, BoundMatchNavigation,
BoundMatchSpec, CanonicalBoundMatchSpec, MatchAggregateCall, MatchExpr,
MatchExprSort, MatchMetadataFunction, MatchNavigation, MatchPatternFieldRef,
MatchPredicateKind, MatchRecognizePlanningCapabilities, MatchUnaryOperator,
validate_pattern_qualifiers,
};
#[cfg(feature = "substrait")]
pub(crate) use source_lowering::plan_match_recognize_native_one_row_node_from_source_with_capabilities;
pub use source_lowering::{
plan_match_recognize_from_source, plan_match_recognize_from_source_with_capabilities,
plan_match_recognize_node_from_source_with_capabilities,
};
use std::sync::Arc;
pub(crate) use symbol_relationships::SymbolRelationships;
pub(crate) use type_validation::can_have_nulls_outside_bitmap;
pub(crate) use vm_assembly::VmAssemblyDowngrade;
pub(crate) mod logical;
pub(crate) mod predicate;
mod bound_expr_lowering;
mod deferred_program;
mod define;
mod expr_safety;
mod expressions;
pub(crate) mod extract;
mod hybrid_guard;
mod measures;
mod navigation_names;
mod phases;
pub(crate) mod physical_derivation;
pub(crate) mod routed_program;
mod semantic_metadata;
mod source;
mod source_lowering;
mod static_extraction;
pub(crate) mod symbol_relationships;
mod type_validation;
mod vm_assembly;
pub(crate) fn can_reorder_input_scalar(
expr: &datafusion::logical_expr::Expr,
schema: &datafusion_common::DFSchema,
) -> bool {
expr_safety::can_discard_scalar(expr, Some(schema))
}
pub(crate) const BUILTIN_SUBSTRING_NAME: &str = "__mr_builtin_substr";
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct MatchRecognizePlanningOptions {
pub disable_managed_aggregates: bool,
pub disable_static_extraction: bool,
}
impl MatchRecognizePlanningOptions {
pub(crate) fn from_config_options(options: &ConfigOptions) -> Self {
let Some(config) = options
.extensions
.get::<crate::config::MatchRecognizeConfig>()
else {
return Self::default();
};
Self {
disable_managed_aggregates: config.diagnostics.disable_managed_aggregates,
disable_static_extraction: config.diagnostics.disable_static_extraction,
}
}
}
pub trait MatchRecognizePlanningContext {
fn options(&self) -> &ConfigOptions;
fn match_recognize_options(&self) -> MatchRecognizePlanningOptions {
MatchRecognizePlanningOptions::from_config_options(self.options())
}
fn scalar_udf(&self, _name: &str) -> Option<Arc<ScalarUDF>> {
None
}
fn aggregate_udf(&self, name: &str) -> Option<Arc<AggregateUDF>> {
bound_expr_lowering::builtin_aggregate_udf(name)
}
}
#[derive(Debug, Clone, Default)]
pub struct DefaultMatchRecognizePlanningContext {
options: ConfigOptions,
}
impl DefaultMatchRecognizePlanningContext {
pub fn new() -> Self {
Self::default()
}
pub fn with_options(options: ConfigOptions) -> Self {
Self { options }
}
}
impl MatchRecognizePlanningContext for DefaultMatchRecognizePlanningContext {
fn options(&self) -> &ConfigOptions {
&self.options
}
}
impl MatchRecognizePlanningContext for ConfigOptions {
fn options(&self) -> &ConfigOptions {
self
}
}
#[cfg(test)]
mod options_tests {
use super::*;
#[test]
fn reads_planning_overrides_from_registered_options() {
let mut options = ConfigOptions::default();
assert_eq!(
MatchRecognizePlanningOptions::from_config_options(&options),
MatchRecognizePlanningOptions::default()
);
options
.extensions
.insert(crate::config::MatchRecognizeConfig::default());
assert_eq!(
MatchRecognizePlanningOptions::from_config_options(&options),
MatchRecognizePlanningOptions::default()
);
options
.set(
"match_recognize.diagnostics.disable_managed_aggregates",
"true",
)
.unwrap();
options
.set(
"match_recognize.diagnostics.disable_static_extraction",
"true",
)
.unwrap();
assert_eq!(
MatchRecognizePlanningOptions::from_config_options(&options),
MatchRecognizePlanningOptions {
disable_managed_aggregates: true,
disable_static_extraction: true,
}
);
}
}