wuchong commented on a change in pull request #10563: [FLINK-15232][table]
Message of NoMatchingTableFactoryException should tell users what's wrong
URL: https://github.com/apache/flink/pull/10563#discussion_r357551125
##########
File path:
flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/TableFactoryService.java
##########
@@ -331,41 +384,40 @@
givenContextFreeKeys);
boolean allTrue = true;
- for (String k: givenFilteredKeys) {
- lastKey = Optional.of(k);
+ List<String> unsupportedKeys = new ArrayList<>();
+ for (String k : givenFilteredKeys) {
if (!(tuple2.f0.contains(k) ||
tuple2.f1.stream().anyMatch(k::startsWith))) {
allTrue = false;
- break;
+ unsupportedKeys.add(k);
}
}
if (allTrue) {
supportedFactories.add(factory);
+ } else {
+ if (bestMatched == null ||
unsupportedKeys.size() < bestMatched.f1.size()) {
+ bestMatched = new Tuple2<>(factory,
unsupportedKeys);
+ }
}
}
- if (supportedFactories.isEmpty() && classFactories.size() == 1
&& lastKey.isPresent()) {
- // special case: when there is only one matching
factory but the last property key
- // was incorrect
- TableFactory factory = classFactories.get(0);
- Tuple2<List<String>, List<String>> tuple2 =
normalizeSupportedProperties(factory);
-
- String errorMessage = String.format(
- "The matching factory '%s' doesn't support
'%s'.\n\nSupported properties of " +
- "this factory are:\n%s",
- factory.getClass().getName(),
- lastKey.get(),
- String.join("\n", tuple2.f0));
+ if (supportedFactories.isEmpty()) {
+ String bestMatchedMessage = null;
+ if (bestMatched != null) {
+ StringBuilder builder = new StringBuilder();
+ builder
+
.append(bestMatched.f0.getClass().getName())
+ .append("\n")
+ .append("Unsupported property
keys: ");
+ bestMatched.f1.forEach(k ->
builder.append("\n").append(k));
+ bestMatchedMessage = builder.toString();
Review comment:
Can be simplified using `String.format` like the original code.
----------------------------------------------------------------
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