twalthr opened a new pull request #10606: [FLINK-15009][table-common] Add a 
utility for creating type inference logic via reflection
URL: https://github.com/apache/flink/pull/10606
 
 
   ## What is the purpose of the change
   
   This implements the full annotation and extraction logic mentioned in 
FLIP-65. The utility takes any of the currently supported functions and returns 
a `TypeInference` instance.
   
   For more information, the documentation of the `FunctionHint` annotation 
should clarify the semantics:
   
   ```
   /**
    * A hint that influences the reflection-based extraction of input types, 
accumulator types, and output
    * types for constructing the {@link TypeInference} logic of a {@link 
UserDefinedFunction}.
    *
    * <p>One or more annotations can be declared on top of a {@link 
UserDefinedFunction} class or individually
    * for each {@code eval()/accumulate()} method for overloading function 
signatures. All hint parameters
    * are optional. If a parameter is not defined, the default reflection-based 
extraction is used. Hint
    * parameters defined on top of a {@link UserDefinedFunction} class are 
inherited by all {@code eval()/accumulate()}
    * methods.
    *
    * <p>The following examples show how to explicitly specify function 
signatures as a whole or in part
    * and let the default extraction do the rest:
    *
    * <pre>
    * {@code
    *   // accepts (INT, STRING) and returns BOOLEAN
    *   @FunctionHint(
    *     input = [@DataTypeHint("INT"), @DataTypeHint("STRING")],
    *     output = @DataTypeHint("BOOLEAN")
    *   )
    *   class X extends ScalarFunction { ... }
    *
    *   // accepts (INT, STRING) or (BOOLEAN) and returns BOOLEAN
    *   @FunctionHint(
    *     input = [@DataTypeHint("INT"), @DataTypeHint("STRING")],
    *     output = @DataTypeHint("BOOLEAN")
    *   )
    *   @FunctionHint(
    *     input = [@DataTypeHint("BOOLEAN")],
    *     output = @DataTypeHint("BOOLEAN")
    *   )
    *   class X extends ScalarFunction { ... }
    *
    *   // accepts (INT, STRING) or (BOOLEAN) and always returns BOOLEAN
    *   @FunctionHint(
    *     output = @DataTypeHint("BOOLEAN")
    *   )
    *   class X extends ScalarFunction {
    *     @FunctionHint(
    *       input = [@DataTypeHint("INT"), @DataTypeHint("STRING")]
    *     )
    *     @FunctionHint(
    *       input = [@DataTypeHint("BOOLEAN")]
    *     )
    *     Object eval(Object... o) { ... }
    *   }
    *
    *   // accepts (INT) or (BOOLEAN) and always returns ROW<f0 BOOLEAN, f1 INT>
    *   @FunctionHint(
    *     output = @DataTypeHint("ROW<f0 BOOLEAN, f1 INT>")
    *   )
    *   class X extends ScalarFunction {
    *     Row eval(int i) { ... }
    *     Row eval(boolean b) { ... }
    *   }
    *
    *   // accepts (ROW<f BOOLEAN>...) or (BOOLEAN...) and returns INT
    *   class X extends ScalarFunction {
    *     @FunctionHint(
    *       input = [@DataTypeHint("ROW<f BOOLEAN>")],
    *       isVarArgs = true
    *     )
    *     int eval(Row... r) { ... }
    *
    *     int eval(boolean... b) { ... }
    *   }
    *
    *   // accepts (INT) and returns INT but allows RAW types in the 
accumulator type
    *   @FunctionHint(
    *     accumulator = @DataTypeHint(bridgedTo = MyClass.class, 
allowRawGlobally = TRUE)
    *   )
    *   class X extends AggregateFunction<Integer, MyClass> {
    *     void accumulate(Row acc, int in) { ... }
    *     // ...
    *   }
    * }
    * </pre>
    *
    * @see DataTypeHint
    */
   ```
   
   The PR is based on FLINK-15149.
   
   The concept of `DataView`s for accumulating functions is not supported yet.
   
   ## Brief change log
   
   - Addition of the `FunctionHint` annotation
   - Implementation of the `TypeInferenceExtractor`
   
   ## Verifying this change
   
   This change added tests and can be verified as follows: 
`TypeInferenceExtractorTest`
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): yes
     - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: yes
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Yarn/Mesos, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? yes
     - If yes, how is the feature documented? JavaDocs
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to