Skip to content

AST Tree Nodes Reference

This section provides comprehensive documentation for all Abstract Syntax Tree (AST) nodes in General SQL Parser. The AST represents the hierarchical structure of parsed SQL statements, where each node corresponds to a specific SQL element.

Quick Navigation

Core Node Categories

📋 SQL Statements

Top-level SQL operations and commands - SELECT Statement - Query operations - INSERT Statement - Data insertion
- UPDATE Statement - Data modification - DELETE Statement - Data removal - DDL Statements - Schema operations

🔧 SQL Clauses

Components that appear within SQL statements - WHERE Clause - Filtering conditions - FROM Clause - Data sources - JOIN Clause - Table relationships - GROUP BY Clause - Data grouping - ORDER BY Clause - Result sorting

🧮 Expressions

Mathematical, logical, and comparison operations - Basic Expressions - TExpression overview - Function Calls - SQL functions - Arithmetic Operations - Math operations - Logical Operations - AND, OR, NOT - CASE Expressions - Conditional logic

🗂️ Table References

How tables and data sources are represented - Table Nodes - Basic table references - JOIN Nodes - Table joins - Derived Tables - Subqueries as tables

📊 Columns and Lists

Column selections and list structures
- Result Columns - SELECT column lists - Column References - Column identifiers - Value Lists - INSERT values

📝 Literals and Constants

Constant values and data types - String Literals - Text values - Numeric Literals - Numbers
- Date Literals - Dates and times

🚀 Advanced Nodes

Complex SQL features and database-specific nodes - Window Functions - OVER clauses - Common Table Expressions - WITH clauses - Database-Specific Features - Vendor extensions

Getting Started

For SQL Analysts

  1. Start with SELECT Statement to understand query structure
  2. Learn about WHERE Clause for filtering
  3. Explore Expressions for condition analysis

For Java Developers

  1. Review Basic Expressions for core concepts
  2. Check API Documentation for method signatures
  3. See Javadoc API for complete technical reference

For Data Engineers

  1. Focus on Table References for lineage analysis
  2. Study JOIN Nodes for relationship mapping
  3. Use Advanced Nodes for complex transformations

Common Usage Patterns

Traversing AST Trees

1
2
3
4
5
6
7
8
9
// Basic pattern for visiting all nodes
public void traverseAST(TSqlStatement stmt) {
    stmt.acceptChildren(new IElementVisitor() {
        public void visitElement(TParseTreeNode node) {
            // Process each node
            System.out.println(node.getClass().getSimpleName());
        }
    });
}

Finding Specific Node Types

1
2
3
4
5
6
7
8
// Find all SELECT statements in a script
List<TSelectSqlStatement> selects = new ArrayList<>();
for (int i = 0; i < parser.sqlstatements.size(); i++) {
    TSqlStatement stmt = parser.sqlstatements.get(i);
    if (stmt instanceof TSelectSqlStatement) {
        selects.add((TSelectSqlStatement) stmt);
    }
}

Node Hierarchy Overview

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
TSqlStatement (Abstract base)
├── TSelectSqlStatement
├── TInsertSqlStatement  
├── TUpdateSqlStatement
├── TDeleteSqlStatement
├── TCreateSqlStatement
└── TCustomSqlStatement
    └── Various database-specific statements

TParseTreeNode (Abstract base)
├── TExpression (and subtypes)
├── TSourceToken
└── Various clause and component nodes

See Also