aboutsummaryrefslogtreecommitdiff
path: root/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
diff options
context:
space:
mode:
authorPaul Rogers <progers@maprtech.com>2016-11-19 18:29:24 -0800
committerJinfeng Ni <jni@apache.org>2016-12-19 15:57:36 -0800
commitbbcf4b765e6946a8b6c7110372c4e1cadbfefa44 (patch)
treec6134f346284e9c5a971b22b184cf44640c648f5 /exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
parent03928af0b5cafd52e5b153aa852e5642b505f2c6 (diff)
DRILL-5052: Option to debug generated Java code using an IDE
Provides a second compilation path for generated code: “plan old Java” in which generated code inherit from their templates. Such code can be compiled directly, allowing easy debugging of generated code. Also show to generate two classes in the External Sort Batch as “plain old Java” to enable IDE debugging of that generated code. Required minor clean-up of the templates. Fixes some broken toString( ) methods in code generation classes Fixes a variety of small compilation warnings Adds Java doc to a few classes Includes clean-up from code review comments. close apache/drill#660
Diffstat (limited to 'exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java')
-rw-r--r--exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java27
1 files changed, 22 insertions, 5 deletions
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
index 02323a985..3c3c30e7d 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
@@ -22,12 +22,13 @@ import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
+import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.common.util.DrillStringUtils;
import org.apache.drill.common.util.FileUtils;
import org.apache.drill.exec.compile.MergeAdapter.MergedClassResult;
import org.apache.drill.exec.exception.ClassTransformationException;
+import org.apache.drill.exec.expr.CodeGenerator;
import org.apache.drill.exec.server.options.OptionManager;
-import org.apache.drill.exec.server.options.OptionValue;
import org.apache.drill.exec.server.options.TypeValidators.EnumeratedStringValidator;
import org.codehaus.commons.compiler.CompileException;
import org.objectweb.asm.ClassReader;
@@ -39,12 +40,21 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+/**
+ * Compiles generated code, merges the resulting class with the
+ * template class, and performs byte-code cleanup on the resulting
+ * byte codes. The most important transform is scalar replacement
+ * which replaces occurences of non-escaping objects with a
+ * collection of member variables.
+ */
+
public class ClassTransformer {
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ClassTransformer.class);
private static final int MAX_SCALAR_REPLACE_CODE_SIZE = 2*1024*1024; // 2meg
private final ByteCodeLoader byteCodeLoader = new ByteCodeLoader();
+ private final DrillConfig config;
private final OptionManager optionManager;
public final static String SCALAR_REPLACEMENT_OPTION =
@@ -73,13 +83,14 @@ public class ClassTransformer {
return TRY;
case "on":
return ON;
+ default:
+ throw new IllegalArgumentException("Invalid ScalarReplacementOption \"" + s + "\"");
}
-
- throw new IllegalArgumentException("Invalid ScalarReplacementOption \"" + s + "\"");
}
}
- public ClassTransformer(final OptionManager optionManager) {
+ public ClassTransformer(final DrillConfig config, final OptionManager optionManager) {
+ this.config = config;
this.optionManager = optionManager;
}
@@ -210,6 +221,12 @@ public class ClassTransformer {
}
}
+ public Class<?> getImplementationClass(CodeGenerator<?> cg) throws ClassTransformationException {
+ final QueryClassLoader loader = new QueryClassLoader(config, optionManager);
+ return getImplementationClass(loader, cg.getDefinition(),
+ cg.getGeneratedCode(), cg.getMaterializedClassName());
+ }
+
public Class<?> getImplementationClass(
final QueryClassLoader classLoader,
final TemplateClassDefinition<?> templateDefinition,
@@ -248,7 +265,7 @@ public class ClassTransformer {
final ClassNames nextGenerated = nextSet.generated;
final ClassNode generatedNode = classesToMerge.get(nextGenerated.slash);
- /**
+ /*
* TODO
* We're having a problem with some cases of scalar replacement, but we want to get
* the code in so it doesn't rot anymore.