You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by da...@apache.org on 2025/04/25 01:26:21 UTC

(hudi) branch master updated: [HUDI-8796] Restrict insert operation with bucket index for Flink (#12545)

This is an automated email from the ASF dual-hosted git repository.

danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git


The following commit(s) were added to refs/heads/master by this push:
     new 999ff9c1095 [HUDI-8796] Restrict insert operation with bucket index for Flink (#12545)
999ff9c1095 is described below

commit 999ff9c1095803b6268fa68c5d7df05d9842141e
Author: Geser Dugarov <ge...@gmail.com>
AuthorDate: Fri Apr 25 08:26:15 2025 +0700

    [HUDI-8796] Restrict insert operation with bucket index for Flink (#12545)
---
 .../java/org/apache/hudi/sink/utils/Pipelines.java |  4 ++++
 .../hudi/sink/bucket/ITTestBucketStreamWrite.java  | 26 +++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/utils/Pipelines.java b/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/utils/Pipelines.java
index 10fc7b5a631..9c55c39fdcd 100644
--- a/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/utils/Pipelines.java
+++ b/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/utils/Pipelines.java
@@ -204,6 +204,10 @@ public class Pipelines {
       Configuration conf,
       RowType rowType,
       DataStream<RowData> dataStream) {
+    if (OptionsResolver.isBucketIndexType(conf)) {
+      throw new HoodieNotSupportedException("Bucket index supports only upsert operation. Please, use upsert operation or switch to another index type.");
+    }
+
     WriteOperatorFactory<RowData> operatorFactory = AppendWriteOperator.getFactory(conf, rowType);
 
     return dataStream
diff --git a/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/bucket/ITTestBucketStreamWrite.java b/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/bucket/ITTestBucketStreamWrite.java
index 45a42ef6d4e..f3fd7c81711 100644
--- a/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/bucket/ITTestBucketStreamWrite.java
+++ b/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/bucket/ITTestBucketStreamWrite.java
@@ -26,6 +26,7 @@ import org.apache.hudi.common.table.timeline.HoodieTimeline;
 import org.apache.hudi.common.testutils.FileCreateUtilsLegacy;
 import org.apache.hudi.common.testutils.HoodieTestUtils;
 import org.apache.hudi.configuration.FlinkOptions;
+import org.apache.hudi.exception.HoodieNotSupportedException;
 import org.apache.hudi.index.HoodieIndex.IndexType;
 import org.apache.hudi.storage.HoodieStorage;
 import org.apache.hudi.storage.StoragePath;
@@ -37,6 +38,7 @@ import org.apache.hudi.utils.TestSQL;
 import org.apache.flink.table.api.EnvironmentSettings;
 import org.apache.flink.table.api.TableEnvironment;
 import org.apache.flink.table.api.internal.TableEnvironmentImpl;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.junit.jupiter.api.io.TempDir;
 import org.junit.jupiter.params.ParameterizedTest;
@@ -45,6 +47,7 @@ import org.junit.jupiter.params.provider.ValueSource;
 import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -54,6 +57,7 @@ import java.util.stream.Collectors;
 
 import static org.apache.hudi.common.testutils.HoodieTestUtils.INSTANT_FILE_NAME_GENERATOR;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertLinesMatch;
 
 /**
  * Integration test cases for {@link BucketStreamWriteFunction}.
@@ -111,6 +115,18 @@ public class ITTestBucketStreamWrite {
     }
   }
 
+  @ParameterizedTest
+  @ValueSource(booleans = {true, false})
+  public void testBucketWriteRestrictInsert(boolean isCow) {
+    String tablePath = tempFile.getAbsolutePath();
+    Map<String, String> customOptions = new HashMap<>();
+    customOptions.put(FlinkOptions.OPERATION.key(), "insert");
+    HoodieNotSupportedException ex =
+        Assertions.assertThrows(HoodieNotSupportedException.class, () -> doWrite(tablePath, isCow, 2, customOptions));
+    assertLinesMatch(Collections.singletonList("Bucket index supports only upsert operation. Please, use upsert operation or switch to another index type."),
+        Collections.singletonList(ex.getMessage()));
+  }
+
   private static void doDeleteCommit(String tablePath) throws Exception {
     // create metaClient
     HoodieTableMetaClient metaClient = HoodieTestUtils.createMetaClient(tablePath);
@@ -145,13 +161,21 @@ public class ITTestBucketStreamWrite {
     });
   }
 
-  private static void doWrite(String path, boolean isCow, int bucketNum)
+  private static void doWrite(String path, boolean isCow, int bucketNum) throws ExecutionException, InterruptedException {
+    doWrite(path, isCow, bucketNum, null);
+  }
+
+  private static void doWrite(String path, boolean isCow, int bucketNum, Map<String, String> customOptions)
       throws InterruptedException, ExecutionException {
     EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build();
     TableEnvironment tableEnv = TableEnvironmentImpl.create(settings);
     Map<String, String> options = new HashMap<>();
     options.put(FlinkOptions.PATH.key(), path);
 
+    if (null != customOptions) {
+      options.putAll(customOptions);
+    }
+
     // use bucket index
     options.put(FlinkOptions.TABLE_TYPE.key(), isCow ? FlinkOptions.TABLE_TYPE_COPY_ON_WRITE : FlinkOptions.TABLE_TYPE_MERGE_ON_READ);
     options.put(FlinkOptions.INDEX_TYPE.key(), IndexType.BUCKET.name());