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_r358039258
##########
File path:
flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/TableFactoryService.java
##########
@@ -269,16 +271,67 @@
plainContext.remove(CATALOG_PROPERTY_VERSION);
// check if required context is met
- return plainContext.keySet()
- .stream()
- .allMatch(e -> properties.containsKey(e) &&
properties.get(e).equals(plainContext.get(e)));
- }).collect(Collectors.toList());
+ int matchedSize = 0;
+ Map<String, Tuple2<String, String>> unMatchedProperties
= new HashMap<>();
+ for (Map.Entry<String, String> e :
plainContext.entrySet()) {
+ if (properties.containsKey(e.getKey()) &&
+
properties.get(e.getKey()).equals(e.getValue())) {
+ matchedSize++;
+ } else {
+ unMatchedProperties.put(
+ e.getKey(),
+ new
Tuple2<>(e.getValue(), properties.get(e.getKey())));
+ }
+ }
+ if (matchedSize == plainContext.size()) {
+ matchingFactories.add(factory);
+ } else {
+ if (bestMatched == null || matchedSize >
bestMatched.f1) {
+ bestMatched = new Tuple3<>(factory,
matchedSize, unMatchedProperties);
+ }
+ }
+ }
if (matchingFactories.isEmpty()) {
+ String bestMatchedMessage = null;
+ if (bestMatched != null && bestMatched.f1 > 0) {
+ StringBuilder builder = new StringBuilder();
+
builder.append(bestMatched.f0.getClass().getName()).append("\n");
+
+ Map<String, String> missing = new HashMap<>();
+ Map<String, Tuple2<String, String>> mismatched
= new HashMap<>();
+ bestMatched.f2.forEach((key, value) -> {
+ if (value.f1 == null) {
+ missing.put(key, value.f0);
+ } else {
+ mismatched.put(key, value);
+ }
+ });
+
+ if (missing.size() > 0) {
+ builder.append("Missing properties: ");
+ missing.forEach((k, v) ->
builder.append("\n").append(k).append("=").append(v));
+ }
+
+ if (mismatched.size() > 0) {
+ builder.append("Mismatched properties:
");
Review comment:
If we don't have the `\n` the message will be:
```
The match candidates:
org.apache.flink.streaming.connectors.kafka.KafkaTableSourceSinkFactory
Missing properties:
connector.version=universalMismatched properties:
connector.xxx=yyy <=> zzz
```
----------------------------------------------------------------
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