featzhang commented on code in PR #28114:
URL: https://github.com/apache/flink/pull/28114#discussion_r3235733630


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeFunctionOperation.java:
##########
@@ -114,19 +121,78 @@ public TableResultInternal execute(Context ctx) {
                     Arrays.asList(
                             "supports constant folding",
                             
String.valueOf(definition.supportsConstantFolding())));
+            final TypeInference typeInference =
+                    
definition.getTypeInference(ctx.getCatalogManager().getDataTypeFactory());
             rows.add(
                     Arrays.asList(
                             "signature",
-                            generateSignature(
-                                    definition.getTypeInference(
-                                            
ctx.getCatalogManager().getDataTypeFactory()),
-                                    function.toString(),
-                                    definition)));
+                            generateSignature(typeInference, 
function.toString(), definition)));
+            rows.addAll(buildPtfMetadataRows(definition, typeInference));
         }
 
         return buildTableResult(
                 new String[] {"info name", "info value"},
                 new DataType[] {DataTypes.STRING(), DataTypes.STRING()},
                 rows.stream().map(List::toArray).toArray(Object[][]::new));
     }
+
+    /**
+     * Builds supplemental info rows from the given {@link FunctionDefinition} 
and {@link
+     * TypeInference}: a {@code state: <name>} row per state entry (with type 
and TTL) and, for
+     * PROCESS_TABLE functions, three capability rows: {@code accepts system 
arguments} (whether the
+     * framework auto-injects {@code uid} / {@code on_time}), {@code is 
changelog function} (whether
+     * the function implements {@link ChangelogFunction}), and {@code uses 
timers} (whether the
+     * function declares an {@code onTimer} method). Returns an empty list 
when none apply.
+     */
+    private static List<List<Object>> buildPtfMetadataRows(
+            FunctionDefinition definition, TypeInference typeInference) {
+        final List<List<Object>> rows = new ArrayList<>();
+        typeInference
+                .getStateTypeStrategies()
+                .forEach(
+                        (name, strategy) ->
+                                rows.add(
+                                        Arrays.asList(
+                                                "state: " + name, 
formatStateEntry(strategy))));
+        if (definition.getKind() == FunctionKind.PROCESS_TABLE) {
+            rows.add(
+                    Arrays.asList(
+                            "accepts system arguments",
+                            
String.valueOf(!typeInference.disableSystemArguments())));
+            rows.add(
+                    Arrays.asList(
+                            "is changelog function",
+                            String.valueOf(definition instanceof 
ChangelogFunction)));
+            rows.add(
+                    Arrays.asList(
+                            "uses timers",
+                            String.valueOf(
+                                    !ExtractionUtils.collectMethods(
+                                                    definition.getClass(),
+                                                    UserDefinedFunctionHelper
+                                                            
.PROCESS_TABLE_ON_TIMER)
+                                            .isEmpty())));
+        }
+        return rows;
+    }
+
+    private static String formatStateEntry(StateTypeStrategy strategy) {
+        // We have no CallContext at DESCRIBE time. Many strategies (including 
TTL lookups in
+        // DefaultStateTypeStrategy) ignore the context, but inferType 
forwards it to the wrapped
+        // TypeStrategy which may dereference it. Catch and degrade to 
<unknown> rather than
+        // failing the entire DESCRIBE for one strategy that needs a real 
CallContext.
+        String typeStr;
+        try {
+            typeStr = 
strategy.inferType(null).map(Object::toString).orElse("<unknown>");
+        } catch (Exception e) {
+            typeStr = "<unknown>";
+        }
+        final Optional<Duration> ttl;
+        try {
+            ttl = strategy.getTimeToLive(null);
+        } catch (Exception e) {

Review Comment:
   `StateTypeStrategy#getTimeToLive(CallContext)` is `@PublicEvolving` and the 
parameter is not annotated `@Nullable`, so user-defined strategies are free to 
dereference it (e.g. to derive TTL from argument types). Calling it with `null` 
here means any such custom strategy degrades to `ttl=<unknown>` in `DESCRIBE`, 
with no hint about the cause.
   
   Two options worth considering: (a) document on `StateTypeStrategy` (and 
`TypeStrategy`) that DESCRIBE may pass `null` and implementations should be 
defensive; or (b) narrow the `catch` to `NullPointerException` and log at 
debug, so the cause is at least diagnosable. Same applies to `inferType(null)` 
a few lines above.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to