Class AstUtils

java.lang.Object
io.trino.sql.util.AstUtils

public final class AstUtils extends Object
  • Method Details

    • preOrder

      public static Stream<Node> preOrder(Node node)
    • treeEqual

      public static boolean treeEqual(Node left, Node right, BiFunction<Node,Node,Boolean> subtreeComparator)

      Compares two AST trees recursively by applying the provided comparator to each pair of nodes.

      The comparator can perform a hybrid shallow/deep comparison. If it returns true or false, the nodes and any subtrees are considered equal or different, respectively. If it returns null, the nodes are considered shallowly-equal and their children will be compared recursively.

    • treeHash

      public static int treeHash(Node node, Function<Node,OptionalInt> subtreeHasher)

      Computes a hash of the given AST by applying the provided subtree hasher at each level.

      If the hasher returns a non-empty OptionalInt, the value is treated as the hash for the subtree at that node. Otherwise, the hashes of its children are computed and combined.

    • extractConjuncts

      public static List<Expression> extractConjuncts(Expression expression)