Skip to content

Commit ec7eb8d

Browse files
committed
[hotfix][table-planner-blink] Give more helpful exception for codegen structured types
1 parent d457cad commit ec7eb8d

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public static Field getStructuredField(Class<?> clazz, String fieldName) {
187187
}
188188
}
189189
throw extractionError(
190-
"Could not to find a field named '%s' in class '%s' for structured type.",
190+
"Could not find a field named '%s' in class '%s' for structured type.",
191191
fieldName, clazz.getName());
192192
}
193193

flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/data/conversion/StructuredObjectConverter.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,10 @@ private static String getterExpr(
250250
// field is accessible with a getter
251251
final Method getter =
252252
getStructuredFieldGetter(implementationClass, field)
253-
.orElseThrow(IllegalStateException::new);
253+
.orElseThrow(
254+
() ->
255+
fieldNotReadableException(
256+
implementationClass, fieldName));
254257
accessExpr = expr("external.", getter.getName(), "()");
255258
}
256259
accessExpr = castExpr(accessExpr, fieldClass);
@@ -264,6 +267,25 @@ private static String getterExpr(
264267
"))");
265268
}
266269

270+
private static IllegalStateException fieldNotReadableException(
271+
Class<?> implementationClass, String fieldName) {
272+
return new IllegalStateException(
273+
String.format(
274+
"Could not find a getter for field '%s' in class '%s'. "
275+
+ "Make sure that the field is readable (via public visibility or getter).",
276+
fieldName, implementationClass.getName()));
277+
}
278+
279+
private static IllegalStateException fieldNotWritableException(
280+
Class<?> implementationClass, String fieldName) {
281+
return new IllegalStateException(
282+
String.format(
283+
"Could not find a setter for field '%s' in class '%s'. "
284+
+ "Make sure that the field is writable (via public visibility, "
285+
+ "setter, or full constructor).",
286+
fieldName, implementationClass.getName()));
287+
}
288+
267289
private static String parameterExpr(int pos, Class<?> fieldClass) {
268290
final String conversionExpr =
269291
expr(
@@ -295,7 +317,10 @@ private static String setterExpr(Class<?> implementationClass, int pos, String f
295317
// field is accessible with a setter
296318
final Method setter =
297319
getStructuredFieldSetter(implementationClass, field)
298-
.orElseThrow(IllegalStateException::new);
320+
.orElseThrow(
321+
() ->
322+
fieldNotWritableException(
323+
implementationClass, fieldName));
299324
return expr(
300325
"structured.",
301326
setter.getName(),

0 commit comments

Comments
 (0)