01.JSqlParser It is built using JavaCC
net.sf.jsqlparser.parser.CCJSqlParserUtil
The method CCJSqlParserManager.parse returns a class implementing Statement
which can be used to navigate the structure representing the SQL statement
Jsqlparser对SQL的遍历采用了 VISITOR 模式, 遍历SQL语句比较方便
应用场景: 状态过滤、权限过滤,表和字段血缘管理
02. Apache Calcite是一个动态数据管理框架,它具备很多典型数据库管理系统的功能,比如SQL 解析、SQL校验、SQL查询优化、SQL生成以及数据连接查询等,基于JavaCC。
3. fdb-sql-parser
4. 正则匹配的方法
开发
01.Maven依赖
<dependency><groupId>com.github.jsqlparser</groupId><artifactId>jsqlparser</artifactId><version>1.2</version></dependency>
02.源码
文件: JSqlParserCC.jjt
/**
* It represents an expression like "(" expression ")"
*/
public class Parenthesis implements Expression {}
public interface Expression {void accept(ExpressionVisitor expressionVisitor);}
/**
* The core of a "SELECT" statement (no UNION, no ORDER BY)
*/
public class PlainSelect implements SelectBody {
public Expression getWhere() {return where;}
……}
public interface SelectBody {void accept(SelectVisitor selectVisitor);}
public class Select implements Statement {}
public interface Statement {void accept(StatementVisitor statementVisitor);}
03.具体概念
Statement SQL语句
Select,Create,Drop,Insert,Delete等,它们作为Statement实现类,均实现accept方法
Expression
ExpressionVisitor
Visitor有StatementVisitor,SelectVisitor,ExpressionVisitor,SelectItemVisitor,FromItemVisitor
CNFConverter :This class handles the conversion from a normal expression tree into the CNF form.
SelectDeParser :
A class to de-parse (that is, tranform from JSqlParser hierarchy into a string)
// de为英语前缀,前缀de-来自拉丁语,意为"away from",de-还表示"除去"、"取消"以及"否定"、"非"、"相反"的意思