tsreaper commented on code in PR #4651:
URL: https://github.com/apache/paimon/pull/4651#discussion_r1875567114
##########
paimon-core/src/main/java/org/apache/paimon/utils/BulkFormatMapping.java:
##########
@@ -139,17 +176,51 @@ public BulkFormatMapping build(
indexCastMapping.getIndexMapping(),
indexCastMapping.getCastMapping(),
partitionMapping,
+ trimmedKeyPair.getLeft(),
formatDiscover
.discover(formatIdentifier)
- .createReaderFactory(readDataRowType, readFilters),
+ .createReaderFactory(trimmedKeyPair.getRight(),
readFilters),
dataSchema,
readFilters);
}
- private List<DataField> readDataFields(TableSchema dataSchema) {
- List<DataField> dataFields = fieldsExtractor.apply(dataSchema);
+ static Pair<int[], RowType> trimKeyFields(
+ List<DataField> fieldsWithoutPartition, List<DataField>
fields) {
+ int[] map = new int[fieldsWithoutPartition.size()];
+ List<DataField> trimmedFields = new ArrayList<>();
+ Map<Integer, DataField> fieldMap = new HashMap<>();
+ Map<Integer, Integer> positionMap = new HashMap<>();
+
+ for (DataField field : fields) {
+ fieldMap.put(field.id(), field);
+ }
+
+ AtomicInteger index = new AtomicInteger();
+ for (int i = 0; i < fieldsWithoutPartition.size(); i++) {
+ DataField field = fieldsWithoutPartition.get(i);
+ boolean keyField = SpecialFields.isKeyField(field.name());
+ int id = keyField ? field.id() - KEY_FIELD_ID_START :
field.id();
+ // field in data schema
+ DataField f = fieldMap.get(id);
+
+ if (f != null) {
+ if (positionMap.containsKey(id)) {
+ map[i] = positionMap.get(id);
+ } else {
+ trimmedFields.add(keyField ? f : field);
+ map[i] = positionMap.computeIfAbsent(id, k ->
index.getAndIncrement());
Review Comment:
```suggestion
map[i] = positionMap.put(id, trimmedFields.size());
trimmedFields.add(f);
```
--
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]