trinodb / trino

Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
https://trino.io
Apache License 2.0
10.43k stars 3k forks source link

java.lang.NoClassDefFoundError: io/prestosql/operator/aggregation/state/StateCompiler #7442

Closed maijh closed 3 years ago

maijh commented 3 years ago

i am writing a plugin for presto 326,i find a error when i start presto with my plugin,like this: java.lang.NoClassDefFoundError: io/prestosql/operator/aggregation/state/StateCompiler at org.hao.aggregation.LongBitmapAggregation.(LongBitmapAggregation.java:13) at sun.misc.Unsafe.ensureClassInitialized(Native Method) at java.lang.invoke.DirectMethodHandle$EnsureInitialized.computeValue(DirectMethodHandle.java:330) at java.lang.invoke.DirectMethodHandle$EnsureInitialized.computeValue(DirectMethodHandle.java:327) at java.lang.ClassValue.getFromHashMap(ClassValue.java:227) at java.lang.ClassValue.getFromBackup(ClassValue.java:209) at java.lang.ClassValue.get(ClassValue.java:115) at java.lang.invoke.DirectMethodHandle.checkInitialized(DirectMethodHandle.java:351) at java.lang.invoke.DirectMethodHandle.ensureInitialized(DirectMethodHandle.java:341) at java.lang.invoke.DirectMethodHandle.internalMemberNameEnsureInit(DirectMethodHandle.java:291) at io.prestosql.$gen.VarbinaryBigintLongToBmAccumulator_20210329_083533_9.addInput(Unknown Source) at io.prestosql.operator.Aggregator.processPage(Aggregator.java:58) at io.prestosql.operator.AggregationOperator.addInput(AggregationOperator.java:152) at io.prestosql.operator.Driver.processInternal(Driver.java:384) at io.prestosql.operator.Driver.lambda$processFor$8(Driver.java:283) at io.prestosql.operator.Driver.tryWithLock(Driver.java:675) at io.prestosql.operator.Driver.processFor(Driver.java:276) at io.prestosql.execution.SqlTaskExecution$DriverSplitRunner.processFor(SqlTaskExecution.java:1075) at io.prestosql.execution.executor.PrioritizedSplitRunner.process(PrioritizedSplitRunner.java:163) at io.prestosql.execution.executor.TaskExecutor$TaskRunner.run(TaskExecutor.java:484) at io.prestosql.$gen.Presto_326____20210329_083505_2.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.ClassNotFoundException: io.prestosql.operator.aggregation.state.StateCompiler at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at io.prestosql.server.PluginClassLoader.loadClass(PluginClassLoader.java:85) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 24 more

i test the plugin example "avg_double" success. But why my plugin fail can someone help me ? my pom file:

<properties>
        <presto.version>326</presto.version>
        <slice.version>0.36</slice.version>
        <guava.version>26.0-jre</guava.version>
        <junit.version>4.12</junit.version>
        <javax.inject.version>1</javax.inject.version>
        <io.airlift.log.version>0.183</io.airlift.log.version>
        <jodatime.version>2.8.1</jodatime.version>
        <roaringbitmap.version>0.8.11</roaringbitmap.version>
        <hive.version>2.1.1</hive.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.1</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet>
                                <!-- dont need to add airlift.slice, presto provides it to all plugins -->
                        <includes>
                             <include>com.google.guava:guava</include>
                             <include>io.airlift:log</include>
                             <include>joda-time:joda-time</include>
                             <include>org.roaringbitmap:RoaringBitmap</include>
                         </includes>
                     </artifactSet>
                     <relocations>
                         <relocation>
                             <pattern>org.joda</pattern>
                             <shadedPattern>org.joda.shaded</shadedPattern>
                         </relocation>
                         <relocation>
                             <pattern>com.google</pattern>
                             <shadedPattern>com.google.shaded</shadedPattern>
                         </relocation>
                         <relocation>
                             <pattern>io.airlift.log</pattern>
                             <shadedPattern>io.airlift.log.shaded</shadedPattern>
                         </relocation>
                     </relocations>

                 </configuration>
             </execution>
            </executions>
            </plugin>

<!--
            <plugin>
                <groupId>io.prestosql</groupId>
                <artifactId>presto-maven-plugin</artifactId>
                <version>8</version>
                <extensions>true</extensions>
            </plugin>-->
        </plugins>
    </build>

    <dependencies>
        <!--
                <dependency>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-annotations</artifactId>
                    <version>2.10.0</version>
                    <scope>provided</scope>
                </dependency>

                <dependency>
                    <groupId>org.openjdk.jol</groupId>
                    <artifactId>jol-core</artifactId>
                    <version>0.2</version>
                    <scope>provided</scope>
                </dependency>

                <dependency>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-annotations</artifactId>
                    <version>2.10.0</version>
                    <scope>provided</scope>
                </dependency> -->
        <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-exec -->
        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-exec</artifactId>
            <version>${hive.version}</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>

        <dependency>
            <groupId>io.prestosql</groupId>
            <artifactId>presto-spi</artifactId>
            <version>${presto.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>io.prestosql</groupId>
            <artifactId>presto-main</artifactId>
            <version>${presto.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>io.airlift</groupId>
            <artifactId>slice</artifactId>
            <version>${slice.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>${guava.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>${javax.inject.version}</version>
        </dependency>

        <dependency>
            <groupId>io.airlift</groupId>
            <artifactId>log</artifactId>
            <version>${io.airlift.log.version}</version>
        </dependency>

        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>${jodatime.version}</version>
        </dependency>
        <dependency>
            <groupId>org.roaringbitmap</groupId>
            <artifactId>RoaringBitmap</artifactId>
            <version>0.8.11</version>
        </dependency>

    </dependencies>
findepi commented 3 years ago

You probably packaged trino-main (presto-main) as the plugin dependency.

Please upgrade to Trino and then add in your pom.xml

<packaging>trino-plugin</packaging>
         <plugin>
                <groupId>io.trino</groupId>
                <artifactId>trino-maven-plugin</artifactId>
                <version>10</version>
                <extensions>true</extensions>
            </plugin>

this will ensure the plugin gets correctly packaged.

findepi commented 3 years ago

I will close this as not-an-issue in Trino. We can continue conversation here, or on #dev channel on our slack. See you there!

maijh commented 3 years ago

@findepi hi, I see your answer about issue 7442,and i add presto-maven-plugin in my pom file,but i still fail.when i follow the steps below,i found i will produce a ZIP file, and it contains the presto-main.jar.

1.Add

<packaging>presto-plugin</packaging>
<plugin>
    <groupId>io.prestosql</groupId>
    <artifactId>presto-maven-plugin</artifactId>
    <version>8</version>
    <extensions>true</extensions>
</plugin>

2.Remove the shade plugin. The above will produce a ZIP file , and i unzipped in the server plugin directory. 3.Remove src/main/resources/META-INF/services/io.prestosql.spi.Plugin