JingsongLi commented on code in PR #3368:
URL: https://github.com/apache/paimon/pull/3368#discussion_r1609663405
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorsIndexFile.java:
##########
@@ -48,18 +50,20 @@ public DeletionVectorsIndexFile(FileIO fileIO, PathFactory
pathFactory) {
/**
* Reads all deletion vectors from a specified file.
*
- * @param fileName The name of the file from which to read the deletion
vectors.
- * @param deletionVectorRanges A map where the key represents which file
the DeletionVector
- * belongs to and the value is a Pair object specifying the range
(start position and size)
- * within the file where the deletion vector data is located.
* @return A map where the key represents which file the DeletionVector
belongs to, and the
* value is the corresponding DeletionVector object.
* @throws UncheckedIOException If an I/O error occurs while reading from
the file.
*/
- public Map<String, DeletionVector> readAllDeletionVectors(
- String fileName, LinkedHashMap<String, Pair<Integer, Integer>>
deletionVectorRanges) {
+ public Map<String, DeletionVector> readAllDeletionVectors(IndexFileMeta
fileMeta) {
+ LinkedHashMap<String, Pair<Integer, Integer>> deletionVectorRanges =
+ fileMeta.deletionVectorsRanges();
+ if (deletionVectorRanges == null || deletionVectorRanges.isEmpty()) {
Review Comment:
Should this file be deleted? Why should handle here?
##########
paimon-core/src/main/java/org/apache/paimon/manifest/IndexManifestFileHandler.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.paimon.manifest;
+
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static
org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.index.HashIndexFile.HASH_INDEX;
+
+/** IndexManifestFile Handler. */
+public class IndexManifestFileHandler {
+
+ private final IndexManifestFile indexManifestFile;
+
+ private final BucketMode bucketMode;
+
+ IndexManifestFileHandler(IndexManifestFile indexManifestFile, BucketMode
bucketMode) {
+ this.indexManifestFile = indexManifestFile;
+ this.bucketMode = bucketMode;
+ }
+
+ String write(@Nullable String previousIndexManifest,
List<IndexManifestEntry> newIndexFiles) {
+ List<IndexManifestEntry> entries =
+ previousIndexManifest == null
+ ? new ArrayList<>()
+ : indexManifestFile.read(previousIndexManifest);
+ Pair<List<IndexManifestEntry>, List<IndexManifestEntry>> previous =
+ separateIndexEntries(entries);
+ Pair<List<IndexManifestEntry>, List<IndexManifestEntry>> current =
+ separateIndexEntries(newIndexFiles);
+
+ // Step1: get the hash index files;
+ List<IndexManifestEntry> indexEntries =
+ getIndexManifestFileCombine(HASH_INDEX)
+ .combine(previous.getLeft(), current.getLeft());
+
+ // Step2: get the dv index files;
+ indexEntries.addAll(
+ getIndexManifestFileCombine(DELETION_VECTORS_INDEX)
+ .combine(previous.getRight(), current.getRight()));
+
+ return indexManifestFile.writeWithoutRolling(indexEntries);
+ }
+
+ private Pair<List<IndexManifestEntry>, List<IndexManifestEntry>>
separateIndexEntries(
+ List<IndexManifestEntry> indexFiles) {
+ List<IndexManifestEntry> hashEntries = new ArrayList<>();
+ List<IndexManifestEntry> dvEntries = new ArrayList<>();
+ for (IndexManifestEntry entry : indexFiles) {
+ String indexType = entry.indexFile().indexType();
+ if (indexType.equals(DELETION_VECTORS_INDEX)) {
+ dvEntries.add(entry);
+ } else if (indexType.equals(HASH_INDEX)) {
+ hashEntries.add(entry);
+ } else {
+ throw new IllegalArgumentException("Can't recognize this index
type: " + indexType);
+ }
+ }
+ return Pair.of(hashEntries, dvEntries);
+ }
+
+ private IndexManifestFileCombiner getIndexManifestFileCombine(String
indexType) {
+ if (DELETION_VECTORS_INDEX.equals(indexType) &&
BucketMode.BUCKET_UNAWARE == bucketMode) {
+ return new UnawareBucketCombiner();
+ } else {
+ return new CommonBucketCombiner();
+ }
+ }
+
+ interface IndexManifestFileCombiner {
+ List<IndexManifestEntry> combine(
+ List<IndexManifestEntry> prevIndexFiles,
List<IndexManifestEntry> newIndexFiles);
+ }
+
+ /**
+ * We combine the previous and new index files by the file name. This is
only used for tables
+ * with UnawareBucket.
+ */
+ static class UnawareBucketCombiner implements IndexManifestFileCombiner {
+
+ @Override
+ public List<IndexManifestEntry> combine(
+ List<IndexManifestEntry> prevIndexFiles,
List<IndexManifestEntry> newIndexFiles) {
+ Map<String, IndexManifestEntry> indexEntries = new
LinkedHashMap<>();
+ for (IndexManifestEntry entry : prevIndexFiles) {
+ if (entry.kind() == FileKind.ADD) {
+ indexEntries.put(entry.indexFile().fileName(), entry);
+ }
+ }
+
+ for (IndexManifestEntry entry : newIndexFiles) {
+ if (entry.kind() == FileKind.ADD) {
+ indexEntries.put(entry.indexFile().fileName(), entry);
+ } else {
+ indexEntries.remove(entry.indexFile().fileName());
+ }
+ }
+ return new ArrayList<>(indexEntries.values());
+ }
+ }
+
+ /** We combine the previous and new index files by {@link
IndexManifestEntry#identifier}. */
Review Comment:
Just move `IndexManifestEntry#identifier` to here? Actually it is not
identifier now. It is only for non-UnawareBucket table.
##########
paimon-core/src/main/java/org/apache/paimon/manifest/IndexManifestFileHandler.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.paimon.manifest;
+
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static
org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.index.HashIndexFile.HASH_INDEX;
+
+/** IndexManifestFile Handler. */
+public class IndexManifestFileHandler {
+
+ private final IndexManifestFile indexManifestFile;
+
+ private final BucketMode bucketMode;
+
+ IndexManifestFileHandler(IndexManifestFile indexManifestFile, BucketMode
bucketMode) {
+ this.indexManifestFile = indexManifestFile;
+ this.bucketMode = bucketMode;
+ }
+
+ String write(@Nullable String previousIndexManifest,
List<IndexManifestEntry> newIndexFiles) {
+ List<IndexManifestEntry> entries =
+ previousIndexManifest == null
+ ? new ArrayList<>()
+ : indexManifestFile.read(previousIndexManifest);
+ Pair<List<IndexManifestEntry>, List<IndexManifestEntry>> previous =
+ separateIndexEntries(entries);
+ Pair<List<IndexManifestEntry>, List<IndexManifestEntry>> current =
+ separateIndexEntries(newIndexFiles);
+
+ // Step1: get the hash index files;
+ List<IndexManifestEntry> indexEntries =
+ getIndexManifestFileCombine(HASH_INDEX)
+ .combine(previous.getLeft(), current.getLeft());
+
+ // Step2: get the dv index files;
+ indexEntries.addAll(
+ getIndexManifestFileCombine(DELETION_VECTORS_INDEX)
+ .combine(previous.getRight(), current.getRight()));
+
+ return indexManifestFile.writeWithoutRolling(indexEntries);
+ }
+
+ private Pair<List<IndexManifestEntry>, List<IndexManifestEntry>>
separateIndexEntries(
+ List<IndexManifestEntry> indexFiles) {
+ List<IndexManifestEntry> hashEntries = new ArrayList<>();
+ List<IndexManifestEntry> dvEntries = new ArrayList<>();
+ for (IndexManifestEntry entry : indexFiles) {
+ String indexType = entry.indexFile().indexType();
+ if (indexType.equals(DELETION_VECTORS_INDEX)) {
+ dvEntries.add(entry);
+ } else if (indexType.equals(HASH_INDEX)) {
+ hashEntries.add(entry);
+ } else {
+ throw new IllegalArgumentException("Can't recognize this index
type: " + indexType);
+ }
+ }
+ return Pair.of(hashEntries, dvEntries);
+ }
+
+ private IndexManifestFileCombiner getIndexManifestFileCombine(String
indexType) {
+ if (DELETION_VECTORS_INDEX.equals(indexType) &&
BucketMode.BUCKET_UNAWARE == bucketMode) {
+ return new UnawareBucketCombiner();
+ } else {
+ return new CommonBucketCombiner();
+ }
+ }
+
+ interface IndexManifestFileCombiner {
+ List<IndexManifestEntry> combine(
+ List<IndexManifestEntry> prevIndexFiles,
List<IndexManifestEntry> newIndexFiles);
+ }
+
+ /**
+ * We combine the previous and new index files by the file name. This is
only used for tables
+ * with UnawareBucket.
+ */
+ static class UnawareBucketCombiner implements IndexManifestFileCombiner {
+
+ @Override
+ public List<IndexManifestEntry> combine(
+ List<IndexManifestEntry> prevIndexFiles,
List<IndexManifestEntry> newIndexFiles) {
+ Map<String, IndexManifestEntry> indexEntries = new
LinkedHashMap<>();
+ for (IndexManifestEntry entry : prevIndexFiles) {
+ if (entry.kind() == FileKind.ADD) {
+ indexEntries.put(entry.indexFile().fileName(), entry);
+ }
+ }
+
+ for (IndexManifestEntry entry : newIndexFiles) {
+ if (entry.kind() == FileKind.ADD) {
+ indexEntries.put(entry.indexFile().fileName(), entry);
+ } else {
+ indexEntries.remove(entry.indexFile().fileName());
+ }
+ }
+ return new ArrayList<>(indexEntries.values());
+ }
+ }
+
+ /** We combine the previous and new index files by {@link
IndexManifestEntry#identifier}. */
+ static class CommonBucketCombiner implements IndexManifestFileCombiner {
+
+ @Override
+ public List<IndexManifestEntry> combine(
+ List<IndexManifestEntry> prevIndexFiles,
List<IndexManifestEntry> newIndexFiles) {
+ Map<IndexManifestEntry.Identifier, IndexManifestEntry>
indexEntries =
+ prevIndexFiles.stream()
+ .filter(entry -> entry.kind() == FileKind.ADD)
Review Comment:
prevIndexFiles should has not delete files. here just checkArguement?
(maybe you can assert outside)
##########
paimon-core/src/main/java/org/apache/paimon/manifest/IndexManifestFileHandler.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.paimon.manifest;
+
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static
org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.index.HashIndexFile.HASH_INDEX;
+
+/** IndexManifestFile Handler. */
+public class IndexManifestFileHandler {
+
+ private final IndexManifestFile indexManifestFile;
+
+ private final BucketMode bucketMode;
+
+ IndexManifestFileHandler(IndexManifestFile indexManifestFile, BucketMode
bucketMode) {
+ this.indexManifestFile = indexManifestFile;
+ this.bucketMode = bucketMode;
+ }
+
+ String write(@Nullable String previousIndexManifest,
List<IndexManifestEntry> newIndexFiles) {
+ List<IndexManifestEntry> entries =
+ previousIndexManifest == null
+ ? new ArrayList<>()
+ : indexManifestFile.read(previousIndexManifest);
+ Pair<List<IndexManifestEntry>, List<IndexManifestEntry>> previous =
+ separateIndexEntries(entries);
+ Pair<List<IndexManifestEntry>, List<IndexManifestEntry>> current =
+ separateIndexEntries(newIndexFiles);
+
+ // Step1: get the hash index files;
+ List<IndexManifestEntry> indexEntries =
+ getIndexManifestFileCombine(HASH_INDEX)
+ .combine(previous.getLeft(), current.getLeft());
+
+ // Step2: get the dv index files;
+ indexEntries.addAll(
+ getIndexManifestFileCombine(DELETION_VECTORS_INDEX)
+ .combine(previous.getRight(), current.getRight()));
+
+ return indexManifestFile.writeWithoutRolling(indexEntries);
+ }
+
+ private Pair<List<IndexManifestEntry>, List<IndexManifestEntry>>
separateIndexEntries(
+ List<IndexManifestEntry> indexFiles) {
+ List<IndexManifestEntry> hashEntries = new ArrayList<>();
+ List<IndexManifestEntry> dvEntries = new ArrayList<>();
+ for (IndexManifestEntry entry : indexFiles) {
+ String indexType = entry.indexFile().indexType();
+ if (indexType.equals(DELETION_VECTORS_INDEX)) {
+ dvEntries.add(entry);
+ } else if (indexType.equals(HASH_INDEX)) {
+ hashEntries.add(entry);
+ } else {
+ throw new IllegalArgumentException("Can't recognize this index
type: " + indexType);
+ }
+ }
+ return Pair.of(hashEntries, dvEntries);
+ }
+
+ private IndexManifestFileCombiner getIndexManifestFileCombine(String
indexType) {
+ if (DELETION_VECTORS_INDEX.equals(indexType) &&
BucketMode.BUCKET_UNAWARE == bucketMode) {
+ return new UnawareBucketCombiner();
+ } else {
+ return new CommonBucketCombiner();
+ }
+ }
+
+ interface IndexManifestFileCombiner {
+ List<IndexManifestEntry> combine(
+ List<IndexManifestEntry> prevIndexFiles,
List<IndexManifestEntry> newIndexFiles);
+ }
+
+ /**
+ * We combine the previous and new index files by the file name. This is
only used for tables
+ * with UnawareBucket.
+ */
+ static class UnawareBucketCombiner implements IndexManifestFileCombiner {
+
+ @Override
+ public List<IndexManifestEntry> combine(
+ List<IndexManifestEntry> prevIndexFiles,
List<IndexManifestEntry> newIndexFiles) {
+ Map<String, IndexManifestEntry> indexEntries = new
LinkedHashMap<>();
+ for (IndexManifestEntry entry : prevIndexFiles) {
+ if (entry.kind() == FileKind.ADD) {
Review Comment:
prevIndexFiles should has not delete files. here just checkArguement?
(maybe you can assert outside)
##########
paimon-core/src/main/java/org/apache/paimon/manifest/IndexManifestFileHandler.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.paimon.manifest;
+
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static
org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.index.HashIndexFile.HASH_INDEX;
+
+/** IndexManifestFile Handler. */
+public class IndexManifestFileHandler {
+
+ private final IndexManifestFile indexManifestFile;
+
+ private final BucketMode bucketMode;
+
+ IndexManifestFileHandler(IndexManifestFile indexManifestFile, BucketMode
bucketMode) {
+ this.indexManifestFile = indexManifestFile;
+ this.bucketMode = bucketMode;
+ }
+
+ String write(@Nullable String previousIndexManifest,
List<IndexManifestEntry> newIndexFiles) {
+ List<IndexManifestEntry> entries =
+ previousIndexManifest == null
+ ? new ArrayList<>()
+ : indexManifestFile.read(previousIndexManifest);
+ Pair<List<IndexManifestEntry>, List<IndexManifestEntry>> previous =
+ separateIndexEntries(entries);
+ Pair<List<IndexManifestEntry>, List<IndexManifestEntry>> current =
+ separateIndexEntries(newIndexFiles);
+
+ // Step1: get the hash index files;
+ List<IndexManifestEntry> indexEntries =
+ getIndexManifestFileCombine(HASH_INDEX)
+ .combine(previous.getLeft(), current.getLeft());
+
+ // Step2: get the dv index files;
+ indexEntries.addAll(
+ getIndexManifestFileCombine(DELETION_VECTORS_INDEX)
+ .combine(previous.getRight(), current.getRight()));
+
+ return indexManifestFile.writeWithoutRolling(indexEntries);
+ }
+
+ private Pair<List<IndexManifestEntry>, List<IndexManifestEntry>>
separateIndexEntries(
+ List<IndexManifestEntry> indexFiles) {
+ List<IndexManifestEntry> hashEntries = new ArrayList<>();
+ List<IndexManifestEntry> dvEntries = new ArrayList<>();
+ for (IndexManifestEntry entry : indexFiles) {
+ String indexType = entry.indexFile().indexType();
+ if (indexType.equals(DELETION_VECTORS_INDEX)) {
+ dvEntries.add(entry);
+ } else if (indexType.equals(HASH_INDEX)) {
+ hashEntries.add(entry);
+ } else {
+ throw new IllegalArgumentException("Can't recognize this index
type: " + indexType);
+ }
+ }
+ return Pair.of(hashEntries, dvEntries);
+ }
+
+ private IndexManifestFileCombiner getIndexManifestFileCombine(String
indexType) {
+ if (DELETION_VECTORS_INDEX.equals(indexType) &&
BucketMode.BUCKET_UNAWARE == bucketMode) {
+ return new UnawareBucketCombiner();
+ } else {
+ return new CommonBucketCombiner();
+ }
+ }
+
+ interface IndexManifestFileCombiner {
+ List<IndexManifestEntry> combine(
+ List<IndexManifestEntry> prevIndexFiles,
List<IndexManifestEntry> newIndexFiles);
+ }
+
+ /**
+ * We combine the previous and new index files by the file name. This is
only used for tables
+ * with UnawareBucket.
+ */
+ static class UnawareBucketCombiner implements IndexManifestFileCombiner {
+
+ @Override
+ public List<IndexManifestEntry> combine(
+ List<IndexManifestEntry> prevIndexFiles,
List<IndexManifestEntry> newIndexFiles) {
+ Map<String, IndexManifestEntry> indexEntries = new
LinkedHashMap<>();
+ for (IndexManifestEntry entry : prevIndexFiles) {
+ if (entry.kind() == FileKind.ADD) {
+ indexEntries.put(entry.indexFile().fileName(), entry);
Review Comment:
Why not using `deletionVectorsRanges`?
I think fileName is wrong key.
--
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]