You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "YannByron (via GitHub)" <gi...@apache.org> on 2024/05/27 09:27:40 UTC
[PR] [core] Introduce DeletionVectorIndexFileWriter [paimon]
YannByron opened a new pull request, #3402:
URL: https://github.com/apache/paimon/pull/3402
<!-- Please specify the module before the PR name: [core] ... or [flink] ... -->
### Purpose
to support merge and write multi deletion vector within same partition and bucket to one index file.
<!-- Linking this pull request to the issue -->
Linked issue: close #xxx
<!-- What is the purpose of the change -->
### Tests
<!-- List UT and IT cases to verify this change -->
### API and Format
<!-- Does this change affect API or storage format -->
### Documentation
<!-- Does this change introduce a new feature -->
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Introduce DeletionVectorIndexFileWriter [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #3402:
URL: https://github.com/apache/paimon/pull/3402
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Introduce DeletionVectorIndexFileWriter [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3402:
URL: https://github.com/apache/paimon/pull/3402#discussion_r1618402946
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.deletionvectors;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.options.MemorySize;
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.Preconditions;
+
+import java.io.Closeable;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.VERSION_ID_V1;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.calculateChecksum;
+
+/** Writer for deletion vector index file. */
+public class DeletionVectorIndexFileWriter {
+
+ private final PathFactory indexPathFactory;
+ private final FileIO fileIO;
+ private final boolean isWrittenToMulitFiles;
+ private final long targetSizeInBytes;
+
+ public DeletionVectorIndexFileWriter(
+ FileIO fileIO,
+ PathFactory pathFactory,
+ BucketMode bucketMode,
+ MemorySize targetSizePerIndexFile) {
+ this.indexPathFactory = pathFactory;
+ this.fileIO = fileIO;
+ this.isWrittenToMulitFiles = BucketMode.BUCKET_UNAWARE == bucketMode;
+ this.targetSizeInBytes = targetSizePerIndexFile.getBytes();
+ }
+
+ public List<IndexFileMeta> write(Map<String, DeletionVector> input) throws IOException {
+ if (input.isEmpty()) {
+ return emptyIndexFile();
+ }
+ List<IndexFileMeta> result = new ArrayList<>();
+ Iterator<Map.Entry<String, DeletionVector>> iterator = input.entrySet().iterator();
+ while (iterator.hasNext()) {
+ result.add(tryWriter(iterator));
+ }
+ return result;
+ }
+
+ private IndexFileMeta tryWriter(Iterator<Map.Entry<String, DeletionVector>> iterator)
+ throws IOException {
+ SingleIndexFileWriter writer =
+ new SingleIndexFileWriter(fileIO, indexPathFactory.newPath());
+ try {
+ while (iterator.hasNext()) {
+ Map.Entry<String, DeletionVector> entry = iterator.next();
+ long currentSize = writer.write(entry.getKey(), entry.getValue());
+
+ if (isWrittenToMulitFiles
+ && !writer.hasWritten()
Review Comment:
`!writer.hasWritten()` always return true?
Maybe you should remove it.
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.deletionvectors;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.options.MemorySize;
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.Preconditions;
+
+import java.io.Closeable;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.VERSION_ID_V1;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.calculateChecksum;
+
+/** Writer for deletion vector index file. */
+public class DeletionVectorIndexFileWriter {
+
+ private final PathFactory indexPathFactory;
+ private final FileIO fileIO;
+ private final boolean isWrittenToMulitFiles;
+ private final long targetSizeInBytes;
+
+ public DeletionVectorIndexFileWriter(
+ FileIO fileIO,
+ PathFactory pathFactory,
+ BucketMode bucketMode,
+ MemorySize targetSizePerIndexFile) {
+ this.indexPathFactory = pathFactory;
+ this.fileIO = fileIO;
+ this.isWrittenToMulitFiles = BucketMode.BUCKET_UNAWARE == bucketMode;
+ this.targetSizeInBytes = targetSizePerIndexFile.getBytes();
+ }
+
+ public List<IndexFileMeta> write(Map<String, DeletionVector> input) throws IOException {
+ if (input.isEmpty()) {
+ return emptyIndexFile();
Review Comment:
If this is possible? Why we need to return a empty Index file?
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.deletionvectors;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.options.MemorySize;
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.Preconditions;
+
+import java.io.Closeable;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.VERSION_ID_V1;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.calculateChecksum;
+
+/** Writer for deletion vector index file. */
+public class DeletionVectorIndexFileWriter {
+
+ private final PathFactory indexPathFactory;
+ private final FileIO fileIO;
+ private final boolean isWrittenToMulitFiles;
+ private final long targetSizeInBytes;
+
+ public DeletionVectorIndexFileWriter(
+ FileIO fileIO,
+ PathFactory pathFactory,
+ BucketMode bucketMode,
+ MemorySize targetSizePerIndexFile) {
+ this.indexPathFactory = pathFactory;
+ this.fileIO = fileIO;
+ this.isWrittenToMulitFiles = BucketMode.BUCKET_UNAWARE == bucketMode;
+ this.targetSizeInBytes = targetSizePerIndexFile.getBytes();
+ }
+
+ public List<IndexFileMeta> write(Map<String, DeletionVector> input) throws IOException {
+ if (input.isEmpty()) {
+ return emptyIndexFile();
+ }
+ List<IndexFileMeta> result = new ArrayList<>();
+ Iterator<Map.Entry<String, DeletionVector>> iterator = input.entrySet().iterator();
+ while (iterator.hasNext()) {
+ result.add(tryWriter(iterator));
+ }
+ return result;
+ }
+
+ private IndexFileMeta tryWriter(Iterator<Map.Entry<String, DeletionVector>> iterator)
+ throws IOException {
+ SingleIndexFileWriter writer =
+ new SingleIndexFileWriter(fileIO, indexPathFactory.newPath());
+ try {
+ while (iterator.hasNext()) {
+ Map.Entry<String, DeletionVector> entry = iterator.next();
+ long currentSize = writer.write(entry.getKey(), entry.getValue());
+
+ if (isWrittenToMulitFiles
+ && !writer.hasWritten()
+ && writer.writtenSizeInBytes() + currentSize > targetSizeInBytes) {
+ break;
+ }
+ }
+ } finally {
+ writer.close();
+ }
+ return writer.writtenIndexFile();
+ }
+
+ private List<IndexFileMeta> emptyIndexFile() throws IOException {
+ try (SingleIndexFileWriter writer =
+ new SingleIndexFileWriter(fileIO, indexPathFactory.newPath())) {
+ return Collections.singletonList(writer.writtenIndexFile());
+ }
+ }
+
+ class SingleIndexFileWriter implements Closeable {
+ private final FileIO fileIO;
+
+ private final Path path;
+
+ private final DataOutputStream dataOutputStream;
+
+ private final LinkedHashMap<String, Pair<Integer, Integer>> dvRanges;
+
+ private long writtenSizeInBytes = 0L;
+
+ public SingleIndexFileWriter(FileIO fileIO, Path path) throws IOException {
Review Comment:
```
public SingleIndexFileWriter() throws IOException {
this.path = indexPathFactory.newPath();
.....
}
```
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.deletionvectors;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.options.MemorySize;
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.Preconditions;
+
+import java.io.Closeable;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.VERSION_ID_V1;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.calculateChecksum;
+
+/** Writer for deletion vector index file. */
+public class DeletionVectorIndexFileWriter {
+
+ private final PathFactory indexPathFactory;
+ private final FileIO fileIO;
+ private final boolean isWrittenToMulitFiles;
+ private final long targetSizeInBytes;
+
+ public DeletionVectorIndexFileWriter(
+ FileIO fileIO,
+ PathFactory pathFactory,
+ BucketMode bucketMode,
+ MemorySize targetSizePerIndexFile) {
+ this.indexPathFactory = pathFactory;
+ this.fileIO = fileIO;
+ this.isWrittenToMulitFiles = BucketMode.BUCKET_UNAWARE == bucketMode;
+ this.targetSizeInBytes = targetSizePerIndexFile.getBytes();
+ }
+
+ public List<IndexFileMeta> write(Map<String, DeletionVector> input) throws IOException {
+ if (input.isEmpty()) {
+ return emptyIndexFile();
+ }
+ List<IndexFileMeta> result = new ArrayList<>();
+ Iterator<Map.Entry<String, DeletionVector>> iterator = input.entrySet().iterator();
+ while (iterator.hasNext()) {
+ result.add(tryWriter(iterator));
+ }
+ return result;
+ }
+
+ private IndexFileMeta tryWriter(Iterator<Map.Entry<String, DeletionVector>> iterator)
+ throws IOException {
+ SingleIndexFileWriter writer =
+ new SingleIndexFileWriter(fileIO, indexPathFactory.newPath());
+ try {
+ while (iterator.hasNext()) {
+ Map.Entry<String, DeletionVector> entry = iterator.next();
+ long currentSize = writer.write(entry.getKey(), entry.getValue());
+
+ if (isWrittenToMulitFiles
+ && !writer.hasWritten()
+ && writer.writtenSizeInBytes() + currentSize > targetSizeInBytes) {
+ break;
+ }
+ }
+ } finally {
+ writer.close();
+ }
+ return writer.writtenIndexFile();
+ }
+
+ private List<IndexFileMeta> emptyIndexFile() throws IOException {
+ try (SingleIndexFileWriter writer =
+ new SingleIndexFileWriter(fileIO, indexPathFactory.newPath())) {
+ return Collections.singletonList(writer.writtenIndexFile());
+ }
+ }
+
+ class SingleIndexFileWriter implements Closeable {
Review Comment:
private
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.deletionvectors;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.options.MemorySize;
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.Preconditions;
+
+import java.io.Closeable;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.VERSION_ID_V1;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.calculateChecksum;
+
+/** Writer for deletion vector index file. */
+public class DeletionVectorIndexFileWriter {
+
+ private final PathFactory indexPathFactory;
+ private final FileIO fileIO;
+ private final boolean isWrittenToMulitFiles;
Review Comment:
typo: `isWrittenToMultiFiles`
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.deletionvectors;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.options.MemorySize;
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.Preconditions;
+
+import java.io.Closeable;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.VERSION_ID_V1;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.calculateChecksum;
+
+/** Writer for deletion vector index file. */
+public class DeletionVectorIndexFileWriter {
+
+ private final PathFactory indexPathFactory;
+ private final FileIO fileIO;
+ private final boolean isWrittenToMulitFiles;
+ private final long targetSizeInBytes;
+
+ public DeletionVectorIndexFileWriter(
+ FileIO fileIO,
+ PathFactory pathFactory,
+ BucketMode bucketMode,
Review Comment:
Maybe we don't need `bucketMode`, here we can just pass a `long targetSizePerIndexFile`. If it is `BUCKET_UNAWARE`, `targetSizePerIndexFile` can be `Long.MAX`.
Same to `DeletionVectorsIndexFile`.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Introduce DeletionVectorIndexFileWriter [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3402:
URL: https://github.com/apache/paimon/pull/3402#discussion_r1618118477
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.deletionvectors;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.options.MemorySize;
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.Preconditions;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.VERSION_ID_V1;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.calculateChecksum;
+
+/** Writer for deletion vector index file. */
+public class DeletionVectorIndexFileWriter {
+
+ private final PathFactory indexPathFactory;
+ private final FileIO fileIO;
+ private final boolean isWrittenToMulitFiles;
+ private final long targetSizeInBytes;
+
+ private boolean written = false;
Review Comment:
This class looks a bit strange, why does it need variables? It only provides one method, which appears to not require any state preservation.
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.deletionvectors;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.options.MemorySize;
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.Preconditions;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.VERSION_ID_V1;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.calculateChecksum;
+
+/** Writer for deletion vector index file. */
+public class DeletionVectorIndexFileWriter {
+
+ private final PathFactory indexPathFactory;
+ private final FileIO fileIO;
+ private final boolean isWrittenToMulitFiles;
+ private final long targetSizeInBytes;
+
+ private boolean written = false;
+
+ private long writtenSizeInBytes = 0L;
+
+ public DeletionVectorIndexFileWriter(
+ FileIO fileIO,
+ PathFactory pathFactory,
+ BucketMode bucketMode,
+ MemorySize targetSizePerIndexFile) {
+ this.indexPathFactory = pathFactory;
+ this.fileIO = fileIO;
+ this.isWrittenToMulitFiles = BucketMode.BUCKET_UNAWARE == bucketMode;
+ this.targetSizeInBytes = targetSizePerIndexFile.getBytes();
+ }
+
+ public List<IndexFileMeta> write(Map<String, DeletionVector> input) throws IOException {
+ List<IndexFileMeta> result = new ArrayList<>();
+ SingleIndexFileWriter writer = createWriter();
+
+ for (Map.Entry<String, DeletionVector> entry : input.entrySet()) {
+ String dataFile = entry.getKey();
+ byte[] valueBytes = entry.getValue().serializeToBytes();
+ int currentSize = valueBytes.length;
+
+ if (isWrittenToMulitFiles
+ && written
+ && writtenSizeInBytes + currentSize > targetSizeInBytes) {
+ result.add(writer.closeWriter());
+ writer = createWriter();
+ }
+
+ writer.write(dataFile, valueBytes);
+ written = true;
+ writtenSizeInBytes += currentSize;
+ }
+ result.add(writer.closeWriter());
+ return result;
+ }
+
+ private SingleIndexFileWriter createWriter() throws IOException {
+ written = false;
+ writtenSizeInBytes = 0L;
+ return new SingleIndexFileWriter(fileIO, indexPathFactory.newPath());
+ }
+
+ static class SingleIndexFileWriter {
Review Comment:
private, and maybe can be an inner class instead of static.
In this way, you can inline `createWriter` to the `SingleIndexFileWriter` constructor.
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.deletionvectors;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.options.MemorySize;
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.Preconditions;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.VERSION_ID_V1;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.calculateChecksum;
+
+/** Writer for deletion vector index file. */
+public class DeletionVectorIndexFileWriter {
+
+ private final PathFactory indexPathFactory;
+ private final FileIO fileIO;
+ private final boolean isWrittenToMulitFiles;
+ private final long targetSizeInBytes;
+
+ private boolean written = false;
+
+ private long writtenSizeInBytes = 0L;
+
+ public DeletionVectorIndexFileWriter(
+ FileIO fileIO,
+ PathFactory pathFactory,
+ BucketMode bucketMode,
+ MemorySize targetSizePerIndexFile) {
+ this.indexPathFactory = pathFactory;
+ this.fileIO = fileIO;
+ this.isWrittenToMulitFiles = BucketMode.BUCKET_UNAWARE == bucketMode;
+ this.targetSizeInBytes = targetSizePerIndexFile.getBytes();
+ }
+
+ public List<IndexFileMeta> write(Map<String, DeletionVector> input) throws IOException {
+ List<IndexFileMeta> result = new ArrayList<>();
+ SingleIndexFileWriter writer = createWriter();
+
+ for (Map.Entry<String, DeletionVector> entry : input.entrySet()) {
+ String dataFile = entry.getKey();
+ byte[] valueBytes = entry.getValue().serializeToBytes();
+ int currentSize = valueBytes.length;
+
+ if (isWrittenToMulitFiles
+ && written
+ && writtenSizeInBytes + currentSize > targetSizeInBytes) {
+ result.add(writer.closeWriter());
+ writer = createWriter();
+ }
+
+ writer.write(dataFile, valueBytes);
+ written = true;
+ writtenSizeInBytes += currentSize;
+ }
+ result.add(writer.closeWriter());
Review Comment:
It is better to use `try (resource)` to avoid resource leak.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Introduce DeletionVectorIndexFileWriter [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3402:
URL: https://github.com/apache/paimon/pull/3402#discussion_r1619681928
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.deletionvectors;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.options.MemorySize;
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.Preconditions;
+
+import java.io.Closeable;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.VERSION_ID_V1;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.calculateChecksum;
+
+/** Writer for deletion vector index file. */
+public class DeletionVectorIndexFileWriter {
+
+ private final PathFactory indexPathFactory;
+ private final FileIO fileIO;
+ private final boolean isWrittenToMulitFiles;
+ private final long targetSizeInBytes;
+
+ public DeletionVectorIndexFileWriter(
+ FileIO fileIO,
+ PathFactory pathFactory,
+ BucketMode bucketMode,
+ MemorySize targetSizePerIndexFile) {
+ this.indexPathFactory = pathFactory;
+ this.fileIO = fileIO;
+ this.isWrittenToMulitFiles = BucketMode.BUCKET_UNAWARE == bucketMode;
+ this.targetSizeInBytes = targetSizePerIndexFile.getBytes();
+ }
+
+ public List<IndexFileMeta> write(Map<String, DeletionVector> input) throws IOException {
+ if (input.isEmpty()) {
+ return emptyIndexFile();
Review Comment:
This may only be to overwrite the old deletion file, as there is no proactive message to delete the deletion file for the primary key table.
But for append table, maybe here no need to generate empty deletion file?
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Introduce DeletionVectorIndexFileWriter [paimon]
Posted by "YannByron (via GitHub)" <gi...@apache.org>.
YannByron commented on code in PR #3402:
URL: https://github.com/apache/paimon/pull/3402#discussion_r1618509583
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.deletionvectors;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.options.MemorySize;
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.Preconditions;
+
+import java.io.Closeable;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.VERSION_ID_V1;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.calculateChecksum;
+
+/** Writer for deletion vector index file. */
+public class DeletionVectorIndexFileWriter {
+
+ private final PathFactory indexPathFactory;
+ private final FileIO fileIO;
+ private final boolean isWrittenToMulitFiles;
+ private final long targetSizeInBytes;
+
+ public DeletionVectorIndexFileWriter(
+ FileIO fileIO,
+ PathFactory pathFactory,
+ BucketMode bucketMode,
+ MemorySize targetSizePerIndexFile) {
+ this.indexPathFactory = pathFactory;
+ this.fileIO = fileIO;
+ this.isWrittenToMulitFiles = BucketMode.BUCKET_UNAWARE == bucketMode;
+ this.targetSizeInBytes = targetSizePerIndexFile.getBytes();
+ }
+
+ public List<IndexFileMeta> write(Map<String, DeletionVector> input) throws IOException {
+ if (input.isEmpty()) {
+ return emptyIndexFile();
Review Comment:
here just aligned to the original logic.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Introduce DeletionVectorIndexFileWriter [paimon]
Posted by "YannByron (via GitHub)" <gi...@apache.org>.
YannByron commented on code in PR #3402:
URL: https://github.com/apache/paimon/pull/3402#discussion_r1618452303
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.deletionvectors;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.options.MemorySize;
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.Preconditions;
+
+import java.io.Closeable;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.VERSION_ID_V1;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.calculateChecksum;
+
+/** Writer for deletion vector index file. */
+public class DeletionVectorIndexFileWriter {
+
+ private final PathFactory indexPathFactory;
+ private final FileIO fileIO;
+ private final boolean isWrittenToMulitFiles;
+ private final long targetSizeInBytes;
+
+ public DeletionVectorIndexFileWriter(
+ FileIO fileIO,
+ PathFactory pathFactory,
+ BucketMode bucketMode,
+ MemorySize targetSizePerIndexFile) {
+ this.indexPathFactory = pathFactory;
+ this.fileIO = fileIO;
+ this.isWrittenToMulitFiles = BucketMode.BUCKET_UNAWARE == bucketMode;
+ this.targetSizeInBytes = targetSizePerIndexFile.getBytes();
+ }
+
+ public List<IndexFileMeta> write(Map<String, DeletionVector> input) throws IOException {
+ if (input.isEmpty()) {
+ return emptyIndexFile();
Review Comment:
This empty index file is needed to overwrite the previous one when `compact`.
I am going to think it again when to support `compact` operation on deletion vector.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Introduce DeletionVectorIndexFileWriter [paimon]
Posted by "YannByron (via GitHub)" <gi...@apache.org>.
YannByron commented on code in PR #3402:
URL: https://github.com/apache/paimon/pull/3402#discussion_r1618449804
##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.deletionvectors;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.options.MemorySize;
+import org.apache.paimon.table.BucketMode;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.PathFactory;
+import org.apache.paimon.utils.Preconditions;
+
+import java.io.Closeable;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.VERSION_ID_V1;
+import static org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.calculateChecksum;
+
+/** Writer for deletion vector index file. */
+public class DeletionVectorIndexFileWriter {
+
+ private final PathFactory indexPathFactory;
+ private final FileIO fileIO;
+ private final boolean isWrittenToMulitFiles;
+ private final long targetSizeInBytes;
+
+ public DeletionVectorIndexFileWriter(
+ FileIO fileIO,
+ PathFactory pathFactory,
+ BucketMode bucketMode,
Review Comment:
Fine. That's what I thought at first. But I don't think it's a little serious.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org