Enum Hook

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Hook>

    public enum Hook
    extends java.lang.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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  Hook.Closeable
      Removes a Hook after use.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      CONVERTED
      Called with the output of sql-to-rel-converter.
      CREATE_MATERIALIZATION
      Called when materialization is created.
      CURRENT_TIME
      Called to get the current time.
      ENABLE_BINDABLE
      Returns a boolean value, whether the return convention should be BindableConvention.
      EXPRESSION_REDUCER
      Called when a constant expression is being reduced.
      JAVA_PLAN
      Called with the generated Java plan, just before it is compiled by Janino.
      PARSE_TREE
      Called with the SQL string and parse tree, in an array.
      PLANNER
      Called with the created planner.
      PROGRAM
      Called to create a Program to optimize the statement.
      QUERY_PLAN
      Called with a query that has been generated to send to a back-end system.
      REL_BUILDER_SIMPLIFY
      Returns a boolean value, whether RelBuilder should simplify expressions.
      STANDARD_STREAMS
      Called to get stdin, stdout, stderr.
      STRING_TO_QUERY
      Converts a SQL string to a CalcitePrepare.Query object.
      SUB
      Called by the planner after substituting a materialization.
      TRIMMED
      Called after de-correlation and field trimming, but before optimization.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.util.function.Consumer<java.lang.Object>> handlers  
      private java.lang.ThreadLocal<java.util.List<java.util.function.Consumer<java.lang.Object>>> threadHandlers  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Hook()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      <T> Hook.Closeable add​(java.util.function.Consumer<T> handler)
      Adds a handler for this Hook.
      <T,​R>
      Hook.Closeable
      add​(java.util.function.Function<T,​R> handler)
      Deprecated.
      <T,​R>
      Hook.Closeable
      addThread​(com.google.common.base.Function<T,​R> handler)
      Deprecated.
      <T> Hook.Closeable addThread​(java.util.function.Consumer<T> handler)
      Adds a handler for this thread.
      <V> V get​(V defaultValue)
      Returns the value of a property hook.
      static <V> com.google.common.base.Function<Holder<V>,​java.lang.Void> property​(V v)
      Deprecated.
      static <V> java.util.function.Consumer<Holder<V>> propertyJ​(V v)
      Returns a function that, when a hook is called, will "return" a given value.
      private boolean remove​(java.util.function.Consumer handler)
      Removes a handler from this Hook.
      private boolean removeThread​(java.util.function.Consumer handler)
      Removes a thread handler from this Hook.
      void run​(java.lang.Object arg)
      Runs all handlers registered for this Hook, with the given argument.
      static Hook valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static Hook[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • 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.
      • 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.
    • Field Detail

      • handlers

        private final java.util.List<java.util.function.Consumer<java.lang.Object>> handlers
      • threadHandlers

        private final java.lang.ThreadLocal<java.util.List<java.util.function.Consumer<java.lang.Object>>> threadHandlers
    • Constructor Detail

      • Hook

        private Hook()
    • Method Detail

      • values

        public static Hook[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (Hook c : Hook.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static Hook valueOf​(java.lang.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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • add

        public <T> Hook.Closeable add​(java.util.function.Consumer<T> handler)
        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();
             }
      • add

        @Deprecated
        public <T,​R> Hook.Closeable add​(java.util.function.Function<T,​R> handler)
        Deprecated.
      • remove

        private boolean remove​(java.util.function.Consumer handler)
        Removes a handler from this Hook.
      • addThread

        public <T> Hook.Closeable addThread​(java.util.function.Consumer<T> handler)
        Adds a handler for this thread.
      • removeThread

        private boolean removeThread​(java.util.function.Consumer handler)
        Removes a thread handler from this Hook.
      • property

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

        public static <V> java.util.function.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​(java.lang.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.)