You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2021/09/16 06:28:31 UTC

[GitHub] [hudi] xiarixiaoyao commented on a change in pull request #3668: [RFC-33] [HUDI-2429][WIP] Full schema evolution

xiarixiaoyao commented on a change in pull request #3668:
URL: https://github.com/apache/hudi/pull/3668#discussion_r709815227



##########
File path: hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/AbstractHoodieWriteClient.java
##########
@@ -1068,4 +1076,150 @@ public void close() {
     this.heartbeatClient.stop();
     this.txnManager.close();
   }
+
+  /**
+   * add columns to table.
+   *
+   * @param colName col name to be added. if we want to add col to a nested filed, the fullName should be specify
+   * @param schema col type to be added.
+   * @param doc col doc to be added.
+   * @param position col position to be added
+   * @param positionType col position change type. now support three change types: first/after/before
+   */
+  public void addColumns(String colName, Schema schema, String doc, String position, String positionType) {
+    Pair<InternalSchema, HoodieTableMetaClient> pair = getInternalSchemaAndMetaClient();
+    TableChanges.ColumnAddChange add = TableChanges.ColumnAddChange.get(pair.getLeft());
+    String parentName = TableChanges.getParentName(colName);
+    add.addColumns(parentName, colName, AvroSchemaUtil.convertToField(schema), doc);
+    if (position != null && !position.isEmpty() && positionType != null && !position.isEmpty()) {
+      String referParentName = TableChanges.getParentName(position);
+      if (!parentName.equals(referParentName)) {
+        throw new IllegalArgumentException("cannot reorder two columns which has different parent");
+      }
+      add.addPositionChange(colName, position, positionType);
+    } else if (positionType != null && positionType.equals("first")) {
+      add.addPositionChange(colName, "", "first");
+    }
+    InternalSchema newSchema = SchemaChangeUtils.applyTableChanges2Schema(pair.getLeft(), add);
+    commitTableChange(newSchema, pair.getRight());
+  }
+
+  public void addColumns(String colName, Schema schema) {
+    addColumns(colName, schema, null, null, null);
+  }
+
+  /**
+   * delete columns to table.
+   *
+   * @param colName col name to be deleted. if we want to delete col from a nested filed, the fullName should be specify
+   */
+  public void deleteColumns(String colName) {
+    Pair<InternalSchema, HoodieTableMetaClient> pair = getInternalSchemaAndMetaClient();
+    TableChanges.ColumnDeleteChange delete = TableChanges.ColumnDeleteChange.get(pair.getLeft());
+    delete.deleteColumn(colName);
+    InternalSchema newSchema = SchemaChangeUtils.applyTableChanges2Schema(pair.getLeft(), delete);
+    commitTableChange(newSchema, pair.getRight());
+  }
+
+  /**
+   * rename col name for hudi table.
+   *
+   * @param colName col name to be renamed. if we want to rename col from a nested filed, the fullName should be specify
+   * @param newName new name for current col. no need to specify fullName.
+   */
+  public void renameColumn(String colName, String newName) {
+    Pair<InternalSchema, HoodieTableMetaClient> pair = getInternalSchemaAndMetaClient();
+    TableChanges.ColumnUpdateChange updateChange = TableChanges.ColumnUpdateChange.get(pair.getLeft());
+    updateChange.renameColumn(colName, newName);
+    InternalSchema newSchema = SchemaChangeUtils.applyTableChanges2Schema(pair.getLeft(), updateChange);
+    commitTableChange(newSchema, pair.getRight());
+  }
+
+  /**
+   * update col type for hudi table.
+   *
+   * @param colName col name to be changed. if we want to change col from a nested filed, the fullName should be specify
+   * @param nullable .
+   */
+  public void updateColumnNullability(String colName, boolean nullable) {

Review comment:
       no this method used to alter table column nullable  attribute。   sorry, the annotated is wrong.  will fix it




-- 
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-unsubscribe@hudi.apache.org

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