twalthr commented on a change in pull request #18029:
URL: https://github.com/apache/flink/pull/18029#discussion_r763126094
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/SchemaTranslator.java
##########
@@ -113,19 +114,42 @@ public static ProducingResult createProducingResult(
ResolvedSchema inputSchema,
AbstractDataType<?> targetDataType) {
final List<String> inputFieldNames = inputSchema.getColumnNames();
+ final List<String> inputFieldNamesNormalized =
+ inputFieldNames.stream()
+ .map(n -> n.toUpperCase(Locale.ROOT))
+ .collect(Collectors.toList());
final DataType resolvedDataType =
dataTypeFactory.createDataType(targetDataType);
final List<String> targetFieldNames = flattenToNames(resolvedDataType);
+ final List<String> targetFieldNamesNormalized =
+ targetFieldNames.stream()
+ .map(n -> n.toUpperCase(Locale.ROOT))
+ .collect(Collectors.toList());
final List<DataType> targetFieldDataTypes =
flattenToDataTypes(resolvedDataType);
// help in reorder fields for POJOs if all field names are present but
out of order,
// otherwise let the sink validation fail later
- final List<String> projections;
- if (targetFieldNames.size() == inputFieldNames.size()
- && !targetFieldNames.equals(inputFieldNames)
- && targetFieldNames.containsAll(inputFieldNames)) {
- projections = targetFieldNames;
- } else {
- projections = null;
+ List<String> projections = null;
+ if (targetFieldNames.size() == inputFieldNames.size()) {
+ // reordering by name (case-sensitive)
+ if (targetFieldNames.containsAll(inputFieldNames)) {
+ projections = targetFieldNames;
+ }
+ // reordering by name (case-insensitive) but fields must be unique
+ else if
(targetFieldNamesNormalized.containsAll(inputFieldNamesNormalized)
+ && targetFieldNamesNormalized.stream().distinct().count()
+ == targetFieldNames.size()
+ && inputFieldNamesNormalized.stream().distinct().count()
+ == inputFieldNames.size()) {
+ projections =
+ targetFieldNamesNormalized.stream()
+ .map(
+ targetName -> {
+ final int inputFieldPos =
+
inputFieldNamesNormalized.indexOf(targetName);
Review comment:
If it's ok I would like to ignore this comment. It makes the code
unnecessary complicated without a clear performance benefit. Even 1000 fields
should not be a problem.
--
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]