在windows的IDEA執行Presto

Gin.p發表於2018-08-19

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
在windows的IDEA執行Presto

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

按照下圖設定好,就行:
在windows的IDEA執行Presto

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

相關文章