🌳 AST Explorer¶
The AST Explorer provides an interactive visualization of Abstract Syntax Trees generated by the General SQL Parser, allowing you to understand the structure and analyze SQL statements at the node level.
🎯 Quick Start¶
🔍 AST Visualization¶
📊 AST Analysis Tools¶
🎓 Learning Guides¶
🌱 AST Basics
Learn the fundamentals of Abstract Syntax Trees and how SQL statements are represented as tree structures.
- Understanding node types
- Parent-child relationships
- Leaf nodes vs. internal nodes
🔍 Node Inspection
Discover how to examine individual nodes and understand their properties, attributes, and relationships.
- Node properties exploration
- Type-specific attributes
- Source location mapping
🏗️ Tree Manipulation
Learn advanced techniques for modifying, transforming, and generating code from AST structures.
- Node modification
- Tree transformation
- Code generation
📋 Common AST Patterns¶
📊 SELECT Statement Structure
SelectStatement ├── SelectList │ ├── ResultColumn: c.customer_name │ ├── ResultColumn: SUM(o.total_amount) │ └── ResultColumn: COUNT(o.order_id) ├── FromClause │ └── TableJoin (INNER) │ ├── LeftTable: customers (alias: c) │ └── RightTable: orders (alias: o) ├── WhereClause │ └── ComparisonExpression (>=) ├── GroupByClause │ ├── c.customer_id │ └── c.customer_name ├── HavingClause │ └── ComparisonExpression (>) └── OrderByClause └── total_spent DESC
🔄 CTE Structure
WithClause ├── CommonTableExpression: sales_summary │ ├── ColumnList │ │ ├── region │ │ └── total_sales │ └── SubQuery │ ├── SelectList │ ├── FromClause │ └── GroupByClause └── MainQuery ├── SelectList ├── FromClause: sales_summary └── OrderByClause
🪟 Window Function Structure
WindowFunction: ROW_NUMBER() ├── FunctionName: ROW_NUMBER ├── ArgumentList: (empty) └── WindowSpecification ├── PartitionByClause │ └── department_id └── OrderByClause └── salary DESC
🔧 Advanced Features¶
Custom Node Filtering¶
Filter the AST view to focus on specific node types or patterns:
- Statement Nodes: SELECT, INSERT, UPDATE, DELETE
- Expression Nodes: Functions, operators, literals
- Clause Nodes: WHERE, ORDER BY, GROUP BY
- Reference Nodes: Tables, columns, aliases
AST Diff Comparison¶
Compare AST structures between different SQL variations:
- Syntax Variations: Different ways to write the same query
- Database Dialects: Same logic across different SQL dialects
- Optimization Changes: Before/after query optimization
Code Generation¶
Generate equivalent code from AST structures:
- Different SQL Dialects: Convert between database syntaxes
- Formatted Output: Pretty-printed SQL with consistent styling
- Documentation: Auto-generated query documentation