JingsongLi commented on code in PR #1416:
URL: https://github.com/apache/incubator-paimon/pull/1416#discussion_r1236288694
##########
paimon-core/src/main/java/org/apache/paimon/mergetree/compact/PartialUpdateMergeFunction.java:
##########
@@ -190,11 +193,36 @@ private Factory(Options options, RowType rowType) {
@Override
public MergeFunction<KeyValue> create(@Nullable int[][] projection) {
List<DataType> fieldTypes = tableTypes;
+ Map<Integer, SequenceGenerator> projFieldSequences = new
HashMap<>();
Review Comment:
naming: projectedFieldSequences
##########
paimon-core/src/test/java/org/apache/paimon/mergetree/compact/PartialUpdateMergeFunctionTest.java:
##########
@@ -95,6 +95,38 @@ public void testSequenceGroupRepeatDefine() {
.hasMessageContaining("is defined repeatedly by multiple
groups");
}
+ @Test
+ public void testAdjustProjection() {
Review Comment:
This test is too simple, you should cover more.
##########
paimon-core/src/main/java/org/apache/paimon/mergetree/compact/PartialUpdateMergeFunction.java:
##########
@@ -190,11 +193,36 @@ private Factory(Options options, RowType rowType) {
@Override
public MergeFunction<KeyValue> create(@Nullable int[][] projection) {
List<DataType> fieldTypes = tableTypes;
+ Map<Integer, SequenceGenerator> projFieldSequences = new
HashMap<>();
+
if (projection != null) {
fieldTypes = Projection.of(projection).project(tableTypes);
+ int[] fieldOldIndex =
Projection.of(projection).toTopLevelIndexes();
Review Comment:
naming: fieldOldIndex -> projects
##########
paimon-core/src/main/java/org/apache/paimon/mergetree/compact/PartialUpdateMergeFunction.java:
##########
@@ -190,11 +193,36 @@ private Factory(Options options, RowType rowType) {
@Override
public MergeFunction<KeyValue> create(@Nullable int[][] projection) {
List<DataType> fieldTypes = tableTypes;
+ Map<Integer, SequenceGenerator> projFieldSequences = new
HashMap<>();
+
if (projection != null) {
fieldTypes = Projection.of(projection).project(tableTypes);
+ int[] fieldOldIndex =
Projection.of(projection).toTopLevelIndexes();
+ Map<Integer, Integer> indexMap = new HashMap<>();
+ for (int i = 0; i < fieldOldIndex.length; i++) {
+ indexMap.put(fieldOldIndex[i], i);
+ }
+ for (int index = 0; index < fieldOldIndex.length; index++) {
+ int oldIndex = fieldOldIndex[index];
+ if (fieldSequences.get(oldIndex) != null) {
+ int oldKeyIndex = fieldSequences.get(oldIndex).index();
+ int keyIndex = indexMap.get(oldKeyIndex);
+ if (!projFieldSequences.containsKey(keyIndex)) {
+ SequenceGenerator newSequenceGen =
+ new SequenceGenerator(keyIndex,
fieldTypes.get(keyIndex));
Review Comment:
keyIndex is not new index of oldIndex.
There should be a bug! You should add tests to cover.
##########
paimon-core/src/main/java/org/apache/paimon/mergetree/compact/PartialUpdateMergeFunction.java:
##########
@@ -190,11 +193,36 @@ private Factory(Options options, RowType rowType) {
@Override
public MergeFunction<KeyValue> create(@Nullable int[][] projection) {
List<DataType> fieldTypes = tableTypes;
+ Map<Integer, SequenceGenerator> projFieldSequences = new
HashMap<>();
+
if (projection != null) {
fieldTypes = Projection.of(projection).project(tableTypes);
+ int[] fieldOldIndex =
Projection.of(projection).toTopLevelIndexes();
+ Map<Integer, Integer> indexMap = new HashMap<>();
+ for (int i = 0; i < fieldOldIndex.length; i++) {
+ indexMap.put(fieldOldIndex[i], i);
+ }
+ for (int index = 0; index < fieldOldIndex.length; index++) {
Review Comment:
loop `fieldSequences` like this:
```
fieldSequences.forEach((field, sequence) -> {
int newField = indexMap.get(field);
checkArguement(newField != -1);
int newSequenceId = indexMap.get(sequence.index());
projectedFieldSequences.put(newField, new
SequenceGenerator(newSequenceId, ...));
});
```
--
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]