jerryshao commented on code in PR #5078:
URL: https://github.com/apache/gravitino/pull/5078#discussion_r1794570920


##########
core/src/main/java/org/apache/gravitino/storage/relational/utils/POConverters.java:
##########
@@ -424,6 +447,73 @@ public static TableEntity fromTablePO(TablePO tablePO, 
Namespace namespace) {
     }
   }
 
+  public static ColumnEntity fromColumnPO(ColumnPO columnPO) {
+    try {
+      return ColumnEntity.builder()
+          .withId(columnPO.getColumnId())
+          .withName(columnPO.getColumnName())
+          
.withDataType(JsonUtils.anyFieldMapper().readValue(columnPO.getColumnType(), 
Type.class))
+          .withComment(columnPO.getColumnComment())
+          .withAutoIncrement(
+              
ColumnPO.AutoIncrement.fromValue(columnPO.getAutoIncrement()).autoIncrement())
+          
.withNullable(ColumnPO.Nullable.fromValue(columnPO.getNullable()).nullable())
+          .withDefaultValue(
+              columnPO.getDefaultValue() == null
+                  ? Column.DEFAULT_VALUE_NOT_SET
+                  : DTOConverters.fromFunctionArg(
+                      (FunctionArg)
+                          JsonUtils.anyFieldMapper()
+                              .readValue(columnPO.getDefaultValue(), 
Expression.class)))
+          .withAuditInfo(
+              JsonUtils.anyFieldMapper().readValue(columnPO.getAuditInfo(), 
AuditInfo.class))
+          .build();
+    } catch (JsonProcessingException e) {
+      throw new RuntimeException("Failed to deserialize json object:", e);
+    }
+  }
+
+  public static List<ColumnEntity> fromColumnPOs(List<ColumnPO> columnPOs) {
+    return 
columnPOs.stream().map(POConverters::fromColumnPO).collect(Collectors.toList());
+  }
+
+  public static ColumnPO initializeColumnPO(
+      TablePO tablePO, ColumnEntity columnEntity, ColumnPO.ColumnOpType 
opType) {
+    try {
+      return ColumnPO.builder()
+          .withColumnId(columnEntity.id())
+          .withColumnName(columnEntity.name())
+          .withMetalakeId(tablePO.getMetalakeId())
+          .withCatalogId(tablePO.getCatalogId())
+          .withSchemaId(tablePO.getSchemaId())
+          .withTableId(tablePO.getTableId())
+          .withTableVersion(tablePO.getCurrentVersion())
+          
.withColumnType(JsonUtils.anyFieldMapper().writeValueAsString(columnEntity.dataType()))
+          .withColumnComment(columnEntity.comment())
+          
.withNullable(ColumnPO.Nullable.fromBoolean(columnEntity.nullable()).value())
+          .withAutoIncrement(
+              
ColumnPO.AutoIncrement.fromBoolean(columnEntity.autoIncrement()).value())
+          .withDefaultValue(
+              columnEntity.defaultValue() == null
+                      || 
columnEntity.defaultValue().equals(Column.DEFAULT_VALUE_NOT_SET)
+                  ? null

Review Comment:
   We use this `DEFAULT_VALUE_NOT_SET` to represent null, I think it is aligned 
with ColumnDTO's current implementation.



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