mchades commented on code in PR #5078:
URL: https://github.com/apache/gravitino/pull/5078#discussion_r1794704451
##########
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:
For column default value, we use `DEFAULT_VALUE_NOT_SET` and
`Literals.NULL` to represent different default values:
- For `DEFAULT_VALUE_NOT_SET`, it means that the user has not set a default
value. If the column is `nullable=false`, then this default value will be
entirely determined by the underlying catalog (for example, some engines set
the default value of `column int not null` to `0`).
- For `Literals.NULL`, if the column `nullable=true`, we can use
`Literals.NULL` to explicitly specify the default value as null. if we use
`DEFAULT_VALUE_NOT_SET`, then this default value will be entirely determined by
the underlying catalog
--
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]