Constraint

Trait Constraint 

Source
pub trait Constraint:
    Debug
    + Send
    + Sync {
    // Required methods
    fn evaluate<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: &'life1 SessionContext,
    ) -> Pin<Box<dyn Future<Output = Result<ConstraintResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn name(&self) -> &str;

    // Provided methods
    fn column(&self) -> Option<&str> { ... }
    fn description(&self) -> Option<&str> { ... }
    fn metadata(&self) -> ConstraintMetadata { ... }
}
Expand description

A validation constraint that can be evaluated against data.

This trait defines the interface for all validation rules in the Term library. Implementations should be stateless and reusable across multiple validations.

§Examples

use term_guard::core::{Constraint, ConstraintResult, ConstraintMetadata};
use async_trait::async_trait;

struct CompletenessConstraint {
    column: String,
    threshold: f64,
}

#[async_trait]
impl Constraint for CompletenessConstraint {
    async fn evaluate(&self, ctx: &SessionContext) -> Result<ConstraintResult> {
        // Implementation here
        Ok(ConstraintResult::success())
    }

    fn name(&self) -> &str {
        "completeness"
    }

    fn metadata(&self) -> ConstraintMetadata {
        ConstraintMetadata::for_column(&self.column)
            .with_description(format!("Checks completeness >= {}", self.threshold))
    }
}

Required Methods§

Source

fn evaluate<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 SessionContext, ) -> Pin<Box<dyn Future<Output = Result<ConstraintResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Evaluates the constraint against the data in the session context.

§Arguments
  • ctx - The DataFusion session context containing the data to validate
§Returns

A Result containing the constraint evaluation result or an error

Source

fn name(&self) -> &str

Returns the name of the constraint.

Provided Methods§

Source

fn column(&self) -> Option<&str>

Returns the column this constraint operates on (if single-column).

Implementors should override this method if they operate on a single column. The default implementation returns None.

Source

fn description(&self) -> Option<&str>

Returns a description of what this constraint validates.

Implementors should override this method to provide a description. The default implementation returns None.

Source

fn metadata(&self) -> ConstraintMetadata

Returns the metadata associated with this constraint.

The default implementation returns empty metadata for backward compatibility. Implementors should override this method to provide meaningful metadata.

Implementors§