You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by lz...@apache.org on 2022/09/09 07:20:14 UTC
[flink-table-store] branch release-0.2 updated: [FLINK-29241] Can not overwrite from empty input
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch release-0.2
in repository https://gitbox.apache.org/repos/asf/flink-table-store.git
The following commit(s) were added to refs/heads/release-0.2 by this push:
new 59a19927 [FLINK-29241] Can not overwrite from empty input
59a19927 is described below
commit 59a1992726ccd437e6cb59a73ec8866b54d7908b
Author: Jingsong Lee <ji...@gmail.com>
AuthorDate: Fri Sep 9 15:20:10 2022 +0800
[FLINK-29241] Can not overwrite from empty input
This closes #289
---
.../store/connector/BatchFileStoreITCase.java | 46 ++++++++++++++++++++++
.../flink/table/store/table/sink/TableCommit.java | 15 ++++++-
2 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/BatchFileStoreITCase.java b/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/BatchFileStoreITCase.java
new file mode 100644
index 00000000..60a48760
--- /dev/null
+++ b/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/BatchFileStoreITCase.java
@@ -0,0 +1,46 @@
+/*
+ * 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.connector;
+
+import org.apache.flink.types.Row;
+
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** ITCase for batch file store. */
+public class BatchFileStoreITCase extends FileStoreTableITCase {
+
+ @Override
+ protected List<String> ddl() {
+ return Collections.singletonList("CREATE TABLE IF NOT EXISTS T (a INT, b INT, c INT)");
+ }
+
+ @Test
+ public void testOverwriteEmpty() {
+ batchSql("INSERT INTO T VALUES (1, 11, 111), (2, 22, 222)");
+ assertThat(batchSql("SELECT * FROM T"))
+ .containsExactlyInAnyOrder(Row.of(1, 11, 111), Row.of(2, 22, 222));
+ batchSql("INSERT OVERWRITE T SELECT * FROM T WHERE 1 <> 1");
+ assertThat(batchSql("SELECT * FROM T")).isEmpty();
+ }
+}
diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/table/sink/TableCommit.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/table/sink/TableCommit.java
index 8e2392b4..1b5cea0b 100644
--- a/flink-table-store-core/src/main/java/org/apache/flink/table/store/table/sink/TableCommit.java
+++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/table/sink/TableCommit.java
@@ -85,9 +85,20 @@ public class TableCommit implements AutoCloseable {
commit.commit(committable, new HashMap<>());
}
} else {
- for (ManifestCommittable committable : committables) {
- commit.overwrite(overwritePartition, committable, new HashMap<>());
+ ManifestCommittable committable;
+ if (committables.size() > 1) {
+ throw new RuntimeException(
+ "Multiple committables appear in overwrite mode, this may be a bug, please report it: "
+ + committables);
+ } else if (committables.size() == 1) {
+ committable = committables.get(0);
+ } else {
+ // create an empty committable
+ // identifier is Long.MAX_VALUE, come from batch job
+ // TODO maybe it can be produced by CommitterOperator
+ committable = new ManifestCommittable(String.valueOf(Long.MAX_VALUE));
}
+ commit.overwrite(overwritePartition, committable, new HashMap<>());
}
expire.expire();
}