Skip to main content

Module diff

Module diff 

Source
Expand description

AST Diff — semantic comparison of SQL expression trees.

Implements a tree edit distance algorithm inspired by the Change Distiller approach used in Python sqlglot’s diff.py. Computes a sequence of ChangeActions that transform one AST into another.

§Example

use sqlglot_rust::{parse, Dialect};
use sqlglot_rust::diff::{diff, ChangeAction};

let source = parse("SELECT a, b FROM t WHERE a > 1", Dialect::Ansi).unwrap();
let target = parse("SELECT a, c FROM t WHERE a > 2", Dialect::Ansi).unwrap();
let changes = diff(&source, &target);

for change in &changes {
    println!("{change:?}");
}

Enums§

AstNode
A wrapper around an AST node that can represent either statements or expressions, enabling uniform diff output.
ChangeAction
A change action describing a single difference between two ASTs.

Functions§

diff
Compute the semantic diff between two SQL statements.
diff_sql
Parse two SQL strings and compute their diff.