Enum Hook

java.lang.Object
java.lang.Enum<Hook>
org.apache.calcite.runtime.Hook
All Implemented Interfaces:
Serializable, Comparable<Hook>, Constable

public enum Hook extends Enum<Hook>
Collection of hooks that can be set by observers and are executed at various parts of the query preparation process.

For testing and debugging rather than for end-users.

  • Enum Constant Details

    • CURRENT_TIME

      public static final Hook CURRENT_TIME
      Called to get the current time. Use this to return a predictable time in tests.
    • STANDARD_STREAMS

      public static final Hook STANDARD_STREAMS
      Called to get stdin, stdout, stderr. Use this to re-assign streams in tests.
    • REL_BUILDER_SIMPLIFY

      public static final Hook REL_BUILDER_SIMPLIFY
      Returns a boolean value, whether RelBuilder should simplify expressions. Default true.
    • ENABLE_BINDABLE

      public static final Hook ENABLE_BINDABLE
      Returns a boolean value, whether the return convention should be BindableConvention. Default false.
    • PARSE_TREE

      public static final Hook PARSE_TREE
      Called with the SQL string and parse tree, in an array.
    • STRING_TO_QUERY

      public static final Hook STRING_TO_QUERY
      Converts a SQL string to a CalcitePrepare.Query object. This hook is an opportunity to execute a RelNode query plan in the JDBC driver rather than the usual SQL string.
    • JAVA_PLAN

      public static final Hook JAVA_PLAN
      Called with the generated Java plan, just before it is compiled by Janino.
    • SQL2REL_CONVERTER_CONFIG_BUILDER

      public static final Hook SQL2REL_CONVERTER_CONFIG_BUILDER
      Called before SqlToRelConverter is built.
    • CONVERTED

      public static final Hook CONVERTED
      Called with the output of sql-to-rel-converter.
    • PLANNER

      public static final Hook PLANNER
      Called with the created planner.
    • TRIMMED

      public static final Hook TRIMMED
      Called after de-correlation and field trimming, but before optimization.
    • SUB

      public static final Hook SUB
      Called by the planner after substituting a materialization.
    • EXPRESSION_REDUCER

      public static final Hook EXPRESSION_REDUCER
      Called when a constant expression is being reduced.
    • PROGRAM

      public static final Hook PROGRAM
      Called to create a Program to optimize the statement.
    • CREATE_MATERIALIZATION

      public static final Hook CREATE_MATERIALIZATION
      Called when materialization is created.
    • QUERY_PLAN

      public static final Hook QUERY_PLAN
      Called with a query that has been generated to send to a back-end system. The query might be a SQL string (for the JDBC adapter), a list of Mongo pipeline expressions (for the MongoDB adapter), et cetera.
    • PLAN_BEFORE_IMPLEMENTATION

      @API(since="1.22", status=EXPERIMENTAL) public static final Hook PLAN_BEFORE_IMPLEMENTATION
      Called when a plan is about to be implemented (e.g. implemented via Enumerable, Bindable, and so on). The hook supplies RelRoot as an argument.
  • Method Details

    • values

      public static Hook[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static Hook valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • add

      @API(status=MAINTAINED) @Deprecated public <T> Hook.Closeable add(Consumer<T> handler)
      Deprecated.
      this installs a global hook (cross-thread), so it might have greater impact than expected. Use with caution. Prefer thread-local hooks.
      Adds a handler for this Hook.

      Returns a Hook.Closeable so that you can use the following try-finally pattern to prevent leaks:

           final Hook.Closeable closeable = Hook.FOO.add(HANDLER);
           try {
               ...
           } finally {
               closeable.close();
           }
      See Also:
    • add

      @Deprecated public <T, R> Hook.Closeable add(Function<T,R> handler)
      Deprecated.
    • addThread

      public <T> Hook.Closeable addThread(Consumer<T> handler)
      Adds a handler for this thread.
    • addThread

      @Deprecated public <T, R> Hook.Closeable addThread(com.google.common.base.Function<T,R> handler)
      Deprecated.
    • property

      @Deprecated public static <V> com.google.common.base.Function<Holder<V>,Void> property(V v)
      Deprecated.
    • propertyJ

      public static <V> Consumer<Holder<V>> propertyJ(V v)
      Returns a function that, when a hook is called, will "return" a given value. (Because of the way hooks work, it "returns" the value by writing into a Holder.
    • run

      public void run(Object arg)
      Runs all handlers registered for this Hook, with the given argument.
    • get

      public <V> V get(V defaultValue)
      Returns the value of a property hook. (Property hooks take a Holder as an argument.)