面对较长的sql难以招架,对sql进行解析,返回其主要结构图
- 大数据组件的sql层基本都是使用Antlr4来进行语法设计,例如:hive/presto/spark
- Antlr4设计使用监听者/访问者模式,可以很快上手
- Antlr4社区提供了较多语法文件,不需要额外编写语法文件
- Antlr4提供了Jetbrain平台相关的插件,解析g4语法文件,生成相应的监听器/访问器文件。
其实Antlr4很好的与java结合,这里使用c++进行开发,存粹是个人偏爱c/c++,作为练手。 最后用python作为胶水打包c++所写的功能。
在 cpp-target 中提到需要下载编译运行时环境:
Once you've generated the lexer and/or parser code, you need to download or build the runtime.
从 antlr4 download 官网下载c++运行时环境 将其中的runtime/src拷贝出来即可通过编译。
- 解析语法文件,可以在clion安装使用antlr4的插件,进行辅助生成
- 或可运行gen.sh命令进行生成
/bin/bash gen.sh
- ddl to csv (done)
- restructure code (doing)
- dml to json (todo)
- dml to graph (todo)