2018-07-02 18:01:01 +08:00
|
|
|
const Parser = require('../core/astParser');
|
|
|
|
const Cache = require("../core/cache");
|
2018-08-16 18:02:31 +08:00
|
|
|
const dtSqlParser=require("../core/sqlSyntaxParser");
|
2018-07-02 18:01:01 +08:00
|
|
|
const filter = require("./filter");
|
|
|
|
|
|
|
|
|
|
|
|
const astCache=new Cache();
|
|
|
|
|
|
|
|
function parse(sql){
|
|
|
|
const cleanSql=filter.cleanSql(sql);
|
|
|
|
console.log(cleanSql)
|
|
|
|
let ast=astCache.get(cleanSql);
|
|
|
|
if(ast){
|
|
|
|
return ast
|
|
|
|
}else{
|
|
|
|
ast=Parser.parse(cleanSql).ast;
|
|
|
|
astCache.set(cleanSql,ast);
|
|
|
|
return ast;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 18:02:31 +08:00
|
|
|
/**
|
|
|
|
* sql sql
|
|
|
|
* type 语法类型。默认hive
|
|
|
|
* return 返回解析对象
|
|
|
|
*/
|
|
|
|
function parseSyntax(sql,type){
|
|
|
|
if(typeof type=="undefined"){
|
|
|
|
type="hive"
|
|
|
|
}
|
|
|
|
return dtSqlParser.parser.parseSyntax(sql,'',type,false)
|
|
|
|
}
|
2018-07-02 18:01:01 +08:00
|
|
|
|
|
|
|
exports.parse=parse;
|
2018-08-16 18:02:31 +08:00
|
|
|
exports.parseSyntax=parseSyntax;
|