在windows的IDEA運行Presto
After building Presto for the first time, you can load the project into your IDE and run the server. We recommend using IntelliJ IDEA. Because Presto is a standard Maven project, you can import it into your IDE using the root pom.xml file
既然Presto的github首頁推薦我們在IDEA運行服務器,那麽我們就用IDEA來吧。
1、克隆項目 & checkout 版本
git clone https://github.com/prestodb/presto.git
git checkout 0.207
這裏註意應該直接克隆項目,而不是下載代碼導入IDEA,否則在後面構建程序的時候可能會出現關於git-comment-id-plugin的錯誤。
2、生成anltr4代碼
在運行項目的時候,出現例如在presto-parser模塊Cannot resolve symbol ‘SqlBaseParser
缺少代碼的錯誤,這是因為源碼不帶anltr4的生成代碼。可以在根目錄運行生成anltr4代碼的命令。
mvn antlr4:antlr4
在執行命令完成後,錯誤依舊沒有消失,我們可以看看項目的結構。File -> Project Structure -> Modules -> presto-parser,將presto-parser的target -> generated-sources ->anltr4設置為Sources
3、設置Presto環境
Requirements
Mac OS X or Linux
Java 8 Update 92 or higher (8u92+), 64-bit. Both Oracle JDK and OpenJDK are supported.
Maven 3.3.9+ (for building)
Python 2.4+ (for running with the launcher script)
官網好像不支持windows,不過沒關系,我們動些手腳讓windows也能運行。
Presto comes with sample configuration that should work out-of-the-box for development. Use the following options to create a run configuration:
Main Class: com.facebook.presto.server.PrestoServer
VM Options: -ea -XX:+UseG1GC -XX:G1HeapRegionSize=32M -XX:+UseGCOverheadLimit -XX:+ExplicitGCInvokesConcurrent -Xmx2G -Dconfig=etc/config.properties -Dlog.levels-file=etc/log.properties
Working directory: $MODULE_DIR$
Use classpath of module: presto-main
按照下圖設置好,就行:
4、修改文件
註釋presto-main模塊PrestoSystemRequirements的代碼,相關代碼片段用IDEA搜索功能查找
failRequirement("Presto requires Linux or Mac OS X (found %s)", osName);
修改文件描述符大小限制(手動改成10000):
private static OptionalLong getMaxFileDescriptorCount()
{
try {
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
//Object maxFileDescriptorCount = mbeanServer.getAttribute(ObjectName.getInstance(OPERATING_SYSTEM_MXBEAN_NAME), "MaxFileDescriptorCount");
Object maxFileDescriptorCount = 10000;
return OptionalLong.of(((Number) maxFileDescriptorCount).longValue());
}
catch (Exception e) {
return OptionalLong.empty();
}
}
下面a/b步驟可以根據目的選一個,a步不包含任何插件,可以快速調試接口。b步包含完整插件,有完整的功能:
a、接下來,把PluginManager的插件註釋掉,
/*for (File file : listFiles(installedPluginsDir)) {
if (file.isDirectory()) {
loadPlugin(file.getAbsolutePath());
}
}
for (String plugin : plugins) {
loadPlugin(plugin);
}*/
把etc/catalog的配置文件全部改名為.properties.bak
。
b、下載presto-server-0.207.tar.gz文件,解壓到任意目錄,把這裏邊的plugin目錄作為IDEA工程的plugin目錄,需要打開文件PluginManagerConfig.java,做如下修改:
// private File installedPluginsDir = new File("plugin");
private File installedPluginsDir = new File("D:\\presto-server-0.207\\plugin");
etc/catalog的配置文件根據需要改名為.properties.bak
。
最後運行PrestoServer。
參考文獻:
https://github.com/prestodb/presto
https://blog.csdn.net/sinat_27545249/article/details/72852148
在windows的IDEA運行Presto