You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2021/06/09 21:25:43 UTC

[GitHub] [calcite] birschick-bq commented on pull request #1766: [CALCITE-3745] UnitCompiler can not find required class information.

birschick-bq commented on pull request #1766:
URL: https://github.com/apache/calcite/pull/1766#issuecomment-858113293


   @vlsi / @gr4ve 
   
   Independent of where you get your class loader, you'll need to update to the latest version of Janino to be able to pass your intended class loader to get their default compiler factory.
   
   Here are my suggestions for updating to Janino. 
   
   Note: there is still a bug in the Janino code that is not passing the class loader to load the factory class. I've left a [comment](https://github.com/janino-compiler/janino/issues/141#issuecomment-858078770) with the author to resolve the issue.
   https://github.com/janino-compiler/janino/issues/141#issuecomment-858078770
   
   So, in the end, we'll need to update to version 3.1.5, assuming the fix is completed in that version.
   
   ```
    .../apache/calcite/adapter/enumerable/EnumerableInterpretable.java   | 5 +++--
    .../main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java  | 5 +++--
    .../org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java   | 5 +++--
    core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java | 4 ++--
    gradle.properties                                                    | 2 +-
    .../apache/calcite/adapter/enumerable/CodeGenerationBenchmark.java   | 5 +++--
    6 files changed, 15 insertions(+), 11 deletions(-)
   
   diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableInterpretable.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableInterpretable.java
   index 616ef22f1..51571e419 100644
   --- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableInterpretable.java
   +++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableInterpretable.java
   @@ -134,8 +134,9 @@ public static Bindable toBindable(Map<String, Object> parameters,
      static Bindable getBindable(ClassDeclaration expr, String s, int fieldCount)
          throws CompileException, IOException, ExecutionException {
        ICompilerFactory compilerFactory;
   +    final ClassLoader classLoader = EnumerableInterpretable.class.getClassLoader();
        try {
   -      compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory();
   +      compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(classLoader);
        } catch (Exception e) {
          throw new IllegalStateException(
              "Unable to instantiate java compiler", e);
   @@ -147,7 +148,7 @@ static Bindable getBindable(ClassDeclaration expr, String s, int fieldCount)
            fieldCount == 1
                ? new Class[] {Bindable.class, Typed.class}
                : new Class[] {ArrayBindable.class});
   -    cbe.setParentClassLoader(EnumerableInterpretable.class.getClassLoader());
   +    cbe.setParentClassLoader(classLoader);
        if (CalciteSystemProperty.DEBUG.value()) {
          // Add line numbers to the generated janino class
          cbe.setDebuggingInformation(true, true, true);
   diff --git a/core/src/main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java b/core/src/main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java
   index 8f244459b..5258d5428 100644
   --- a/core/src/main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java
   +++ b/core/src/main/java/org/apache/calcite/interpreter/JaninoRexCompiler.java
   @@ -199,8 +199,9 @@ public JaninoRexCompiler(RexBuilder rexBuilder) {
      static Scalar.Producer getScalar(ClassDeclaration expr, String s)
          throws CompileException, IOException {
        ICompilerFactory compilerFactory;
   +    final ClassLoader classLoader = JaninoRexCompiler.class.getClassLoader();
        try {
   -      compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory();
   +      compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(classLoader);
        } catch (Exception e) {
          throw new IllegalStateException(
              "Unable to instantiate java compiler", e);
   @@ -208,7 +209,7 @@ public JaninoRexCompiler(RexBuilder rexBuilder) {
        IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator();
        cbe.setClassName(expr.name);
        cbe.setImplementedInterfaces(new Class[] {Scalar.Producer.class});
   -    cbe.setParentClassLoader(JaninoRexCompiler.class.getClassLoader());
   +    cbe.setParentClassLoader(classLoader);
        if (CalciteSystemProperty.DEBUG.value()) {
          // Add line numbers to the generated janino class
          cbe.setDebuggingInformation(true, true, true);
   diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java b/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
   index 76106c938..a4c31e612 100644
   --- a/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
   +++ b/core/src/main/java/org/apache/calcite/rel/metadata/JaninoRelMetadataProvider.java
   @@ -423,15 +423,16 @@ private static StringBuilder paramList(StringBuilder buff, Method method) {
          String classBody, MetadataDef<M> def,
          List<Object> argList) throws CompileException, IOException {
        final ICompilerFactory compilerFactory;
   +    final ClassLoader classLoader = JaninoRexCompiler.class.getClassLoader();
        try {
   -      compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory();
   +      compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(classLoader);
        } catch (Exception e) {
          throw new IllegalStateException(
              "Unable to instantiate java compiler", e);
        }
    
        final ISimpleCompiler compiler = compilerFactory.newSimpleCompiler();
   -    compiler.setParentClassLoader(JaninoRexCompiler.class.getClassLoader());
   +    compiler.setParentClassLoader(classLoader);
    
        final String s = "public final class " + className
            + " implements " + def.handlerClass.getCanonicalName() + " {\n"
   diff --git a/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java b/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java
   index 001a0bf16..d4ca4b3ae 100644
   --- a/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java
   +++ b/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java
   @@ -19,10 +19,10 @@
    import org.apache.calcite.config.CalciteSystemProperty;
    
    import org.checkerframework.checker.nullness.qual.Nullable;
   +import org.codehaus.commons.compiler.util.resource.MapResourceFinder;
   +import org.codehaus.commons.compiler.util.resource.ResourceFinder;
    import org.codehaus.janino.JavaSourceClassLoader;
    import org.codehaus.janino.util.ClassFile;
   -import org.codehaus.janino.util.resource.MapResourceFinder;
   -import org.codehaus.janino.util.resource.ResourceFinder;
    
    import java.io.File;
    import java.io.FileOutputStream;
   diff --git a/gradle.properties b/gradle.properties
   index ac11bbcf0..7b8da5a11 100644
   --- a/gradle.properties
   +++ b/gradle.properties
   @@ -106,7 +106,7 @@ hydromatic.tpcds.version=0.4
    innodb-java-reader.version=1.0.10
    jackson-databind.version=2.9.10.1
    jackson.version=2.10.0
   -janino.version=3.0.11
   +janino.version=3.1.4
    java-diff.version=1.1.2
    jcip-annotations.version=1.0-1
    jcommander.version=1.72
   diff --git a/ubenchmark/src/jmh/java/org/apache/calcite/adapter/enumerable/CodeGenerationBenchmark.java b/ubenchmark/src/jmh/java/org/apache/calcite/adapter/enumerable/CodeGenerationBenchmark.java
   index fe5ed0d2f..0807ebe19 100644
   --- a/ubenchmark/src/jmh/java/org/apache/calcite/adapter/enumerable/CodeGenerationBenchmark.java
   +++ b/ubenchmark/src/jmh/java/org/apache/calcite/adapter/enumerable/CodeGenerationBenchmark.java
   @@ -184,8 +184,9 @@ public void setup() {
                Expressions.toString(info.classExpr.memberDeclarations, "\n", false);
    
            ICompilerFactory compilerFactory;
   +        final ClassLoader classLoader = EnumerableInterpretable.class.getClassLoader();
            try {
   -          compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory();
   +          compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(classLoader);
            } catch (Exception e) {
              throw new IllegalStateException(
                  "Unable to instantiate java compiler", e);
   @@ -197,7 +198,7 @@ public void setup() {
                plan.getRowType().getFieldCount() == 1
                    ? new Class[]{Bindable.class, Typed.class}
                    : new Class[]{ArrayBindable.class});
   -        cbe.setParentClassLoader(EnumerableInterpretable.class.getClassLoader());
   +        cbe.setParentClassLoader(classLoader);
            info.cbe = cbe;
            planInfos[i] = info;
          }
   ```
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org