JingsongLi commented on a change in pull request #16:
URL: https://github.com/apache/flink-table-store/pull/16#discussion_r805453263
##########
File path:
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/manifest/ManifestCommittableSerializer.java
##########
@@ -55,6 +55,8 @@ public int getVersion() {
public byte[] serialize(ManifestCommittable obj) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
DataOutputViewStreamWrapper view = new
DataOutputViewStreamWrapper(out);
+ view.writeInt(obj.uuid().length());
Review comment:
writeUtf8?
##########
File path:
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/manifest/ManifestFileMeta.java
##########
@@ -169,13 +171,16 @@ private static void merge(
List<ManifestFileMeta> newMetas) {
if (metas.size() > 1) {
ManifestFileMeta newMeta = merge(metas, manifestFile);
- result.add(newMeta);
- newMetas.add(newMeta);
+ if (newMeta != null) {
+ result.add(newMeta);
+ newMetas.add(newMeta);
+ }
} else {
result.addAll(metas);
}
}
+ @Nullable
private static ManifestFileMeta merge(List<ManifestFileMeta> metas,
ManifestFile manifestFile) {
Review comment:
return Optional?
##########
File path:
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/operation/FileStoreCommitImpl.java
##########
@@ -168,21 +157,67 @@ public void overwrite(
Map<String, String> partition,
ManifestCommittable committable,
Map<String, String> properties) {
- throw new UnsupportedOperationException();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(
+ "Ready to overwrite partition "
+ + partition.toString()
+ + "\n"
+ + committable.toString());
+ }
+
+ BinaryRowData partitionRowData =
+ TypeUtils.partitionMapToBinaryRowData(partition,
partitionType);
+
+ List<ManifestEntry> appendChanges =
collectChanges(committable.newFiles(), ValueKind.ADD);
+ tryOverwrite(
+ partitionRowData, appendChanges, committable.uuid(),
Snapshot.CommitKind.APPEND);
+
+ List<ManifestEntry> compactChanges = new ArrayList<>();
+ compactChanges.addAll(collectChanges(committable.compactBefore(),
ValueKind.DELETE));
+ compactChanges.addAll(collectChanges(committable.compactAfter(),
ValueKind.ADD));
+ tryCommit(compactChanges, committable.uuid(),
Snapshot.CommitKind.COMPACT);
}
- private String digestManifestCommittable(ManifestCommittable committable) {
- try {
- return new String(
- Base64.getEncoder()
- .encode(
- MessageDigest.getInstance("MD5")
-
.digest(committableSerializer.serialize(committable))));
- } catch (NoSuchAlgorithmException e) {
- throw new RuntimeException("MD5 algorithm not found. This is
impossible.", e);
- } catch (IOException e) {
- throw new RuntimeException(
- "Failed to serialize ManifestCommittable. This is
unexpected.", e);
+ private void tryCommit(
+ List<ManifestEntry> changes, String hash, Snapshot.CommitKind
commitKind) {
+ while (true) {
+ Long latestSnapshotId = pathFactory.latestSnapshotId();
+ if (tryCommitOnce(changes, hash, commitKind, latestSnapshotId)) {
+ break;
+ }
+ }
+ }
+
+ private void tryOverwrite(
+ BinaryRowData partition,
+ List<ManifestEntry> changes,
+ String hash,
+ Snapshot.CommitKind commitKind) {
+ while (true) {
+ Long latestSnapshotId = pathFactory.latestSnapshotId();
+
+ List<ManifestEntry> changesWithOverwrite = new ArrayList<>();
+ if (latestSnapshotId != null) {
+ List<ManifestEntry> currentEntries =
+ scan.withSnapshot(latestSnapshotId)
+
.withPartitionFilter(Collections.singletonList(partition))
+ .plan()
+ .files();
+ for (ManifestEntry entry : currentEntries) {
+ changesWithOverwrite.add(
+ new ManifestEntry(
+ ValueKind.DELETE,
+ entry.partition(),
+ entry.bucket(),
+ entry.totalBuckets(),
+ entry.file()));
+ }
+ }
+ changesWithOverwrite.addAll(changes);
+
+ if (tryCommitOnce(changesWithOverwrite, hash, commitKind,
latestSnapshotId)) {
Review comment:
It seems that there is no need to check `noConflictsOrFail` again?
##########
File path:
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/utils/TypeUtils.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.flink.table.store.file.utils;
+
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.binary.BinaryRowData;
+import org.apache.flink.table.data.binary.BinaryStringData;
+import org.apache.flink.table.data.binary.BinaryStringDataUtil;
+import org.apache.flink.table.runtime.typeutils.RowDataSerializer;
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.RowType;
+
+import java.util.List;
+import java.util.Map;
+
+/** Utils for parsing among different types. */
+public class TypeUtils {
+
+ public static BinaryRowData partitionMapToBinaryRowData(
+ Map<String, String> partition, RowType partitionType) {
+ List<String> fieldNames = partitionType.getFieldNames();
+ RowDataSerializer serializer = new RowDataSerializer(partitionType);
+ GenericRowData rowData = new
GenericRowData(partitionType.getFieldCount());
+ for (Map.Entry<String, String> entry : partition.entrySet()) {
Review comment:
check that `partition` has no full partition keys
--
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]