raminqaf commented on code in PR #28114:
URL: https://github.com/apache/flink/pull/28114#discussion_r3450765427
##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeFunctionOperation.java:
##########
@@ -114,19 +126,84 @@ 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. Log at
+ // DEBUG so the cause is diagnosable when a user reports an unexpected
<unknown>.
+ String typeStr;
Review Comment:
Please use StringBuilder
##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeFunctionOperation.java:
##########
@@ -114,19 +126,84 @@ 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. Log at
+ // DEBUG so the cause is diagnosable when a user reports an unexpected
<unknown>.
Review Comment:
Let's move this to 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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]