cacliteparser代码生成详解 本文代码均已上传到giteehttps:gitee。comshoothzjcalciteexamplescaclite的parser代码生成分为如下两个步骤 生成Parse。jj 文件目录如下pom。xmlsrcmaincodegenconfig。fmppincludescompoundIdentifier。ftlparserImpls。ftltemplatesParser。jj 添加calcitedependencydependencygroupIdorg。apache。calcitegroupIdcalcitecoreartifactIddependency 配置drillfmppmavenplugin插件如下plugingroupIdorg。apache。drill。toolsgroupIddrillfmppmavenpluginartifactIdexecutionsexecutionconfigurationconfigsrcmaincodegenconfig。fmppconfigoutput{project。build。directory}generatedsourcesfmppoutputtemplatessrcmaincodegentemplatestemplatesconfigurationidgeneratefmppsourcesidphasevalidatephasegoalsgoalgenerategoalgoalsexecutionexecutionsplugin codegen模块的文件都拷贝自对应版本的calclitecoresrcmaincodegen路径https:github。comapachecalcitetreemaincoresrcmaincodegen 然后把https:github。comapachecalciteblobmaincoresrcmaincodegendefaultconfig。fmpp中的parser属性与config。fmpp中的parser属性合并。就可以通过mvnpackage命令生成Parser。jj了。当然,如果有定制化修改的需求,也可以在这个阶段修改config。fmpp Parser。jj生成java代码 文件目录如下pom。xmlsrcmaincodegenParser。jj Parser。jj就是我们上一步生成的Parser。jj,如果有什么想要的定制化修改,也可以在这个步骤改入到Parser。jj中。 添加calcitedependencydependencygroupIdorg。apache。calcitegroupIdcalcitecoreartifactIddependency 配置javaccmavenplugin如下plugingroupIdorg。codehaus。mojogroupIdjavaccmavenpluginartifactIdexecutionsexecutionidjavaccidgoalsgoaljavaccgoalgoalsconfigurationsourceDirectory{project。basedir}srcmaincodegensourceDirectoryincludesincludeParser。jjincludeincludesconfigurationexecutionexecutionsplugin 生成代码 无Parser。jj定制化修改,一步生成 如果不需要对Parser。jj进行定制化修改,那么可以通过连续运行两个插件来生成代码,这里给出pom文件样例,不再赘述plugingroupIdorg。apache。drill。toolsgroupIddrillfmppmavenpluginartifactIdexecutionsexecutionconfigurationconfigsrcmaincodegenconfig。fmppconfigoutput{project。build。directory}generatedsourcesfmppoutputtemplatessrcmaincodegentemplatestemplatesconfigurationidgeneratefmppsourcesidphasevalidatephasegoalsgoalgenerategoalgoalsexecutionexecutionspluginplugingroupIdorg。codehaus。mojogroupIdjavaccmavenpluginartifactIdexecutionsexecutionidjavaccidgoalsgoaljavaccgoalgoalsconfigurationsourceDirectory{project。build。directory}generatedsourcesfmppsourceDirectoryincludesincludeParser。jjincludeincludeslookAhead2lookAheadisStaticfalseisStaticconfigurationexecutionexecutionidjavacctestidphasegeneratetestsourcesphasegoalsgoaljavaccgoalgoalsconfigurationsourceDirectory{project。build。directory}generatedtestsourcesfmppsourceDirectoryoutputDirectory{project。build。directory}generatedtestsourcesjavaccoutputDirectoryincludesincludeParser。jjincludeincludesisStaticfalseisStaticignoreCasetrueignoreCaseunicodeInputtrueunicodeInputconfigurationexecutionexecutionsplugin