danny0405 commented on code in PR #9937:
URL: https://github.com/apache/hudi/pull/9937#discussion_r1375739969


##########
hudi-cli/src/main/java/org/apache/hudi/cli/commands/TableCommand.java:
##########
@@ -229,6 +233,55 @@ public String deleteTableConfig(
     return renderOldNewProps(newProps, oldProps);
   }
 
+  @ShellMethod(key = "table change-table-type", value = "Change hudi table 
type, COW_TO_MOR or MOR_TO_COW.")
+  public String changeTableType(
+      @ShellOption(value = {"--type"},
+          help = "COW_TO_MOR or MOR_TO_COW stands for changing table from COW 
to MOR or from MOR to COW respectively.") final String changeType) {
+    HoodieTableMetaClient client = HoodieCLI.getTableMetaClient();
+    String tableName = client.getTableConfig().getTableName();
+    String tablePath = client.getBasePathV2().toString();
+    Map<String, String> oldProps = client.getTableConfig().propsMap();
+
+    HoodieTableType currentType = client.getTableType();
+    String targetType;
+    switch (changeType) {
+      case "COW_TO_MOR":
+        if (currentType.equals(HoodieTableType.MERGE_ON_READ)) {
+          return String.format("table %s path %s is already %s", tableName, 
tablePath, HoodieTableType.MERGE_ON_READ);
+        }
+        targetType = HoodieTableType.MERGE_ON_READ.name();
+        break;
+      case "MOR_TO_COW":
+        if (currentType.equals(HoodieTableType.COPY_ON_WRITE)) {
+          return String.format("table %s path %s is already %s", tableName, 
tablePath, HoodieTableType.COPY_ON_WRITE);
+        }
+        // TODO check if remain any compaction or deltacommit;
+        Option<HoodieInstant> lastInstant = 
client.getActiveTimeline().lastInstant();
+        if (lastInstant.isPresent()) {
+          // before changing mor to cow, need to do a full compaction first;
+          if (!lastInstant.get().getAction().equals("compaction") || 
!lastInstant.get().isCompleted()) {
+            throw new HoodieException(String.format("The last action must be a 
completed compaction for this operation. "

Review Comment:
   > considering it it would be a little troublesome
   
   Yeah, you need to customize the compaction options to compact all the logs.



-- 
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: commits-unsubscr...@hudi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to