Class QueryCompilerImpl

java.lang.Object
io.deephaven.engine.context.QueryCompilerImpl
All Implemented Interfaces:
LogOutputAppendable, QueryCompiler

public class QueryCompilerImpl extends Object implements QueryCompiler, LogOutputAppendable
A QueryCompiler implementation that compiles Java source to bytecode in memory and defines the resulting classes via ClassLoader.defineClass(byte[], int, int), avoiding filesystem writes for compilation output.

The compiler resolves dependencies from java.class.path and an optional additional classpath directory (typically where Groovy writes its bytecode). Compiled classes are loaded in per-batch child classloaders of the provided parent classloader, enabling GC of both classes and classloaders when neither the compiled Classes nor this compiler instance are reachable.

  • Field Details

  • Method Details

    • create

      public static QueryCompilerImpl create(@Nullable @Nullable File additionalClassPathDir)
      Creates a new QueryCompilerImpl. Uses the current thread's context classloader as the parent for per-batch classloaders (as required by QueryCompiler's contract).
      Parameters:
      additionalClassPathDir - optional directory to add to the compiler's classpath (e.g., groovy bytecode dir)
    • create

      public static QueryCompilerImpl create(@Nullable @Nullable File additionalClassPathDir, @Nullable @Nullable ClassLoader classLoader)
      Creates a new QueryCompilerImpl. Uses classLoader as the parent for per-batch classloaders. If classLoader is null, uses the current thread's context classloader at compile time instead (as required by QueryCompiler's contract).
      Parameters:
      additionalClassPathDir - optional directory to add to the compiler's classpath (e.g., groovy bytecode dir)
      classLoader - optional parent classloader for per-batch classloaders; if null, the current thread's context classloader is used
    • create

      public static QueryCompilerImpl create()
      Creates a new compiler that has no extra directory to read from, suitable for unit tests or cases where the existing classpath is sufficient.
    • setClassNamesForAnnotationProcessing

      @TestUseOnly public void setClassNamesForAnnotationProcessing(List<String> classNames)
      Currently only intended for testing, this method allows specifying annotation processors to run during this compile.
      Parameters:
      classNames - the annotation processor classes to allow to run
    • append

      public LogOutput append(LogOutput logOutput)
      Specified by:
      append in interface LogOutputAppendable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setLogEnabled

      public static boolean setLogEnabled(boolean logEnabled)
      Enables or disables compilation logging.
      Parameters:
      logEnabled - Whether logging should be enabled
      Returns:
      The value of logEnabled before calling this method.
    • compile

      public void compile(@NotNull @NotNull QueryCompilerRequest[] requests, @NotNull CompletionStageFuture.Resolver<Class<?>>[] resolvers)
      Description copied from interface: QueryCompiler
      Compiles all requests.
      Specified by:
      compile in interface QueryCompiler
      Parameters:
      requests - The compilation requests; these must be independent of each other
      resolvers - The resolvers to use for delivering compilation results
    • createEscapedJoinedString

      public static String createEscapedJoinedString(String originalString)
      Transform a string into the corresponding Java source code that compiles into that string.
    • createEscapedJoinedString

      public static String createEscapedJoinedString(String originalString, int maxStringLength)