{"repo":"AfterShip/clickhouse-sql-parser","free":true,"listed":false,"github":"https://github.com/AfterShip/clickhouse-sql-parser","clone":"git clone https://github.com/AfterShip/clickhouse-sql-parser.git","description":"Go library and CLI that parses ClickHouse-dialect SQL into a typed AST. Supports lexing, parsing, AST walking, round-trip formatting, and beautification. Use for query linting, static analysis, rewriting, access-control enforcement, schema validation, and SQL formatting.","language":"Go","stars":245,"topics":["clickhouse","go","sql-parser"],"license":"MIT","category":"databases-storage","readme_excerpt":"ClickHouse SQL Parser The goal of this project is to build a ClickHouse SQL parser in Go with the following key features: - Parse ClickHouse SQL into AST - Beautify ClickHouse SQL format This project is inspired by memefish which is a SQL parser for Spanner in Go. How to use You can use it as your Go library or CLI tool, see the following examples: - Use clickhouse-sql-parser as a Go library - Install clickhouse-sql-parser as a CLI tool On Linux: On macOS: Parse ClickHouse SQL into AST or format ClickHouse SQL: Beautify SQL Example The -beautify flag formats SQL with proper indentation and line breaks, making complex queries more readable: - Parsed tree(AST) back into a SQL statement AST Traversal Walk Pattern (Recommended) The Walk pattern provides a simple and efficient way to traverse AST nodes. Use the Walk function to visit all nodes in the AST: Walk Pattern Functions - Walk(node Expr, fn WalkFunc) - Traverses all nodes in depth-first order - WalkWithBreak(node Expr, fn WalkFunc) - Allows early termination of traversal - Find(root Expr, predicate func(Expr) bool) - Finds the first node matching a condition - FindAll(root Expr, predicate func(Expr) bool) - Finds all nodes matching a condition - Transform(root Expr, transformer func(Expr) Expr) - Applies transformations to nodes Examples Find all table identifiers: Find the first WHERE clause: Update test assets For the files inside output and format dir are generated by the test cases, if you want to update them, you can ","default_branch":null,"files":null,"tree":[],"storefront":"/r/AfterShip","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/AfterShip/clickhouse-sql-parser/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}