[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r358639663 ## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/NoMatchingTableFactoryException.java ## @@ -41,13 +43,15 @@ public NoMatchingTableFactoryException( String message, + String matchCandidatesMessage, Review comment: Add `@Nullable` annotation to `matchCandidatesMessage` parameter. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r358640517 ## File path: flink-table/flink-table-common/src/test/java/org/apache/flink/table/factories/TestTableSinkFactory.java ## @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.table.factories; + +import org.apache.flink.table.sinks.TableSink; +import org.apache.flink.types.Row; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.apache.flink.table.descriptors.ConnectorDescriptorValidator.CONNECTOR_PROPERTY_VERSION; +import static org.apache.flink.table.descriptors.ConnectorDescriptorValidator.CONNECTOR_TYPE; +import static org.apache.flink.table.descriptors.FormatDescriptorValidator.FORMAT_PROPERTY_VERSION; +import static org.apache.flink.table.descriptors.FormatDescriptorValidator.FORMAT_TYPE; + +/** + * Test table sink factory. + */ +public class TestTableSinkFactory implements TableFactory, TableSinkFactory { Review comment: Can we remove `TestTableSinkFactory` in flink-table-planner now? 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r358641289 ## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/NoMatchingTableFactoryException.java ## @@ -58,24 +62,32 @@ public NoMatchingTableFactoryException( Class factoryClass, List factories, Map properties) { + this(message, null, factoryClass, factories, properties, null); + } - this(message, factoryClass, factories, properties, null); + public NoMatchingTableFactoryException( + String message, + String matchCandidatesMessage, + Class factoryClass, + List factories, + Map properties) { + this(message, matchCandidatesMessage, factoryClass, factories, properties, null); } @Override public String getMessage() { + String matchCandidatesString = matchCandidatesMessage == null ? + "" : + "The match candidates:\n" + matchCandidatesMessage + "\n\n"; Review comment: `match` -> `matched` ? 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r358639769 ## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/NoMatchingTableFactoryException.java ## @@ -58,24 +62,32 @@ public NoMatchingTableFactoryException( Class factoryClass, List factories, Map properties) { + this(message, null, factoryClass, factories, properties, null); + } - this(message, factoryClass, factories, properties, null); + public NoMatchingTableFactoryException( + String message, + String matchCandidatesMessage, + Class factoryClass, + List factories, + Map properties) { + this(message, matchCandidatesMessage, factoryClass, factories, properties, null); } @Override public String getMessage() { + String matchCandidatesString = matchCandidatesMessage == null ? + "" : + "The match candidates:\n" + matchCandidatesMessage + "\n\n"; return String.format( "Could not find a suitable table factory for '%s' in\nthe classpath.\n\n" + - "Reason: %s\n\n" + + "Reason: %s\n\n" + matchCandidatesString + Review comment: Use String.format pattern. ``` "Reason: %s\n\n%s" ``` 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r358639624 ## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/NoMatchingTableFactoryException.java ## @@ -32,6 +32,8 @@ // message that indicates the current matching step private final String message; + // message that indicates the best matched factory + private final String matchCandidatesMessage; Review comment: Add `@Nullable` annotation to `matchCandidatesMessage`. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r358643641 ## File path: flink-table/flink-table-common/src/test/resources/log4j-test.properties ## @@ -0,0 +1,27 @@ + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# Set root logger level to OFF to not flood build logs +# set manually to INFO for debugging purposes +log4j.rootLogger=OFF, testlogger Review comment: Are log4j and logback configuration files required? 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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> unMatchedProperties = new HashMap<>(); + for (Map.Entry 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 missing = new HashMap<>(); + Map> 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r358038750 ## 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> unMatchedProperties = new HashMap<>(); + for (Map.Entry e : plainContext.entrySet()) { + if (properties.containsKey(e.getKey()) && + properties.get(e.getKey()).equals(e.getValue())) { + matchedSize++; Review comment: The `matchedSize` can be calculated by `requiredProperties.size() - unMatchedProperties.size()`. Is that right? 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r358038244 ## 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> unMatchedProperties = new HashMap<>(); + for (Map.Entry e : plainContext.entrySet()) { + if (properties.containsKey(e.getKey()) && + properties.get(e.getKey()).equals(e.getValue())) { + matchedSize++; Review comment: The `matchedSize` can be calculated by `userProperties.size() - unMatchedProperties.size()`. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r358038244 ## 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> unMatchedProperties = new HashMap<>(); + for (Map.Entry e : plainContext.entrySet()) { + if (properties.containsKey(e.getKey()) && + properties.get(e.getKey()).equals(e.getValue())) { + matchedSize++; Review comment: The `matchedSize` can be calculated by `userProperties.size() - unMatchedProperties.size()`. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r357548211 ## 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> unMatchedProperties = new HashMap<>(); + for (Map.Entry 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 missing = new HashMap<>(); + Map> 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: ```suggestion builder.append("\nMismatched properties: "); ``` We should have a line feed to separate with the preceding "Missing properties" 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r357515041 ## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/NoMatchingTableFactoryException.java ## @@ -58,24 +62,32 @@ public NoMatchingTableFactoryException( Class factoryClass, List factories, Map properties) { + this(message, null, factoryClass, factories, properties, null); + } - this(message, factoryClass, factories, properties, null); + public NoMatchingTableFactoryException( + String message, + String matchCandidatesMessage, + Class factoryClass, + List factories, + Map properties) { + this(message, matchCandidatesMessage, factoryClass, factories, properties, null); } @Override public String getMessage() { + String matchCandidatesString = matchCandidatesMessage == null ? + "" : + "The match candidates: \n" + matchCandidatesMessage + "\n\n"; return String.format( "Could not find a suitable table factory for '%s' in\nthe classpath.\n\n" + - "Reason: %s\n\n" + + "Reason: %s\n\n" + matchCandidatesString + "The following properties are requested:\n%s\n\n" + "The following factories have been considered:\n%s", factoryClass.getName(), message, DescriptorProperties.toString(properties), - String.join( - "\n", - factories.stream().map(p -> p.getClass().getName()).collect(Collectors.toList()) - ) + factories.stream().map(p -> p.getClass().getName()).collect(Collectors.joining("\n")) Review comment: Indent. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r357547300 ## 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> unMatchedProperties = new HashMap<>(); + for (Map.Entry e : plainContext.entrySet()) { + if (properties.containsKey(e.getKey()) && + properties.get(e.getKey()).equals(e.getValue())) { + matchedSize++; Review comment: If we have `unMatchedProperties`, we don't need to track `matchedSize` any more. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r357548252 ## 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> unMatchedProperties = new HashMap<>(); + for (Map.Entry 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 missing = new HashMap<>(); + Map> 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: "); Review comment: ```suggestion builder.append("\nMissing properties: "); ``` 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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 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> 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r357552890 ## 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> unMatchedProperties = new HashMap<>(); + for (Map.Entry 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 missing = new HashMap<>(); + Map> 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: "); + bestMatched.f2.entrySet().stream().filter(e -> e.getValue().f1 != null).forEach(e -> + builder.append("\n") + .append(e.getKey()) + .append("=") + .append(e.getValue().f0) + .append(" <=> ") + .append(e.getValue().f1)); Review comment: ``` Mismatched properties: connector.version=universal <=> 0.10 ``` can be improved to: ``` Mismatched properties: 'connector.version' expects 'universal', but is '0.10'. ``` 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10563: [FLINK-15232][table] Message of NoMatchingTableFactoryException should tell users what's wrong
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_r357546560 ## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/TableFactoryService.java ## @@ -255,10 +256,11 @@ private static List filterByContext( Class factoryClass, Map properties, - List foundFactories, List classFactories) { - List matchingFactories = classFactories.stream().filter(factory -> { + List matchingFactories = new ArrayList<>(); + Tuple3>> bestMatched = null; Review comment: Could you create a inner class to encapsulate the matched information? It's really hard to guess what does every part mean. 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: us...@infra.apache.org With regards, Apache Git Services