lirui-apache commented on a change in pull request #13144:
URL: https://github.com/apache/flink/pull/13144#discussion_r475425845



##########
File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveScalarFunction.java
##########
@@ -104,4 +142,62 @@ public Object eval(Object... args) {
         * Evaluation logical, args will be wrapped when is a single array.
         */
        protected abstract Object evalInternal(Object[] args);
+
+       private Tuple2<Object[], DataType[]> getConstantArgAndTypes(CallContext 
callContext) {
+               DataType[] inputTypes = 
callContext.getArgumentDataTypes().toArray(new DataType[0]);
+               Object[] constantArgs = new Object[inputTypes.length];
+               for (int i = 0; i < constantArgs.length; i++) {
+                       if (callContext.isArgumentLiteral(i)) {
+                               constantArgs[i] = callContext.getArgumentValue(
+                                               i, 
ClassLogicalTypeConverter.getDefaultExternalClassForType(inputTypes[i].getLogicalType()))
+                                               .orElse(null);
+                       }
+               }
+               return Tuple2.of(constantArgs, inputTypes);
+       }
+
+       /**
+        * Validate input argument types and decide result type.
+        */
+       protected abstract DataType validateInputTypes(DataType[] argTypes) 
throws UDFArgumentException;
+
+       private class HiveUDFOutputStrategy implements TypeStrategy {
+
+               @Override
+               public Optional<DataType> inferType(CallContext callContext) {
+                       Tuple2<Object[], DataType[]> constantArgAndTypes = 
getConstantArgAndTypes(callContext);
+                       return 
Optional.ofNullable(getHiveResultType(constantArgAndTypes.f0, 
constantArgAndTypes.f1));
+               }
+       }
+
+       private class HiveUDFInputStrategy implements InputTypeStrategy {

Review comment:
       I think this is needed for input type validation. For example, according 
to the API contract, a `ValidationException` can be thrown if the input is 
invalid, but this should only happen during input inference rather than output 
inference.




----------------------------------------------------------------
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]


Reply via email to