Enum 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


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

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

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

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

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

      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.

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

      public static final Hook SQL2REL_CONVERTER_CONFIG_BUILDER
      Called before SqlToRelConverter is built.

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

      public static final Hook PLANNER
      Called with the created planner.

      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.

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

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

      public static final Hook CREATE_MATERIALIZATION
      Called when materialization is created.

      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.

      @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.
      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.)
      name - the name of the enum constant to be returned.
      the enum constant with the specified name
      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)
      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 {
      See Also:
    • add

      @Deprecated public <T, R> Hook.Closeable add(Function<T,R> handler)
    • 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)
    • property

      @Deprecated public static <V> com.google.common.base.Function<Holder<V>,Void> property(V v)
    • 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.)