Trait Transform

Source
pub trait Transform: Send + Sync {
    // Required methods
    fn name(&self) -> String;
    fn get_reduction_points(&self, ast: Statement) -> Vec<usize>;
    fn apply_on(
        &self,
        ast: &mut Statement,
        reduction_points: Vec<usize>,
    ) -> Statement;

    // Provided method
    fn transform(
        &self,
        ast: Statement,
        idx: usize,
        strategy: Strategy,
    ) -> Vec<(Statement, usize)> { ... }
}
Expand description

A transformation that can reduce parts of a SQL AST while preserving failure behavior.

A Transform operates by identifying reduction points in the AST—locations where a simplification or mutation can be safely attempted—and then applying those changes.

§Reduction Points

A reduction point is an index identifying a target element (e.g., a SELECT item, a WHERE clause, or a binary operator) that can be removed, replaced, or mutated.

§Example:
  • For a SELECT list:
    SELECT a + b, c, d FROM t;
              ^    ^
              |    └── reduction point 1 (c)
              └────── reduction point 0 (a + b)

Required Methods§

Source

fn name(&self) -> String

Source

fn get_reduction_points(&self, ast: Statement) -> Vec<usize>

This function analyzes the given SQL AST and returns all the reduction points where the transformation might be applicable.

§Arguments
  • ast: The SQL AST to analyze.
§Returns
  • A list of reduction points where the transformation might be applicable.

Implementors should return a list of all applicable reduction indices for their transform.

Source

fn apply_on( &self, ast: &mut Statement, reduction_points: Vec<usize>, ) -> Statement

Applies the transformation to the AST at the given reduction points.

§Arguments
  • ast: The SQL AST to apply the transformation to.
  • reduction_points: The list of reduction points to apply the transformation to.
§Returns
  • The modified AST.

Provided Methods§

Source

fn transform( &self, ast: Statement, idx: usize, strategy: Strategy, ) -> Vec<(Statement, usize)>

Applies the transformation to the AST at the given reduction points.

§Arguments
  • ast: The SQL AST to apply the transformation to.
  • idx: The index of the reduction point to apply the transformation to.
  • strategy: The strategy to use for applying the transformation.

Trait Implementations§

Source§

impl Display for dyn Transform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Implementors§