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


##########
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:
   I considered adding the compaction operation here, but considering it it 
would be a little troublesome, I didn't implement it here. 
   However, I can indeed add an option to automatically perform full compaction.



-- 
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]

Reply via email to