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


##########
clients/client-python/gravitino/dto/util/dto_converters.py:
##########
@@ -76,3 +108,249 @@ def from_function_args(args: list[FunctionArg]) -> 
list[Expression]:
         if not args:
             return Expression.EMPTY_EXPRESSION
         return [DTOConverters.from_function_arg(arg) for arg in args]
+
+    @singledispatchmethod
+    @staticmethod
+    def from_dto(dto) -> object:
+        raise IllegalArgumentException(f"Unsupported DTO type: {type(dto)}")
+
+    @from_dto.register
+    @staticmethod
+    def _(dto: DistributionDTO) -> Distribution:
+        """Converts a DistributionDTO to a Distribution.
+
+        Args:
+            dto (DistributionDTO): The distribution DTO.
+
+        Returns:
+            Distribution: The distribution.
+        """
+        if dto is None or DistributionDTO.NONE.equals(dto):
+            return Distributions.NONE
+
+        return Distributions.of(
+            dto.strategy(),
+            dto.number(),
+            *DTOConverters.from_function_args(dto.args()),
+        )
+
+    @from_dto.register
+    @staticmethod
+    def _(dto: IndexDTO) -> Index:
+        """Converts an IndexDTO to an Index.
+
+        Args:
+            dto (IndexDTO): The Index DTO to be converted.
+
+        Returns:
+            Index: The index.
+        """
+        return Indexes.of(dto.type(), dto.name(), dto.field_names())
+
+    @from_dto.register
+    @staticmethod
+    def _(dto: SortOrderDTO) -> SortOrder:
+        """Converts a SortOrderDTO to a SortOrder.
+
+        Args:
+            dto (SortOrderDTO): The sort order DTO to be converted.
+
+        Returns:
+            SortOrder: The sort order.
+        """
+        return SortOrders.of(
+            DTOConverters.from_function_arg(dto.sort_term()),
+            dto.direction(),
+            dto.null_ordering(),
+        )
+
+    @from_dto.register
+    @staticmethod
+    def _(dto: ColumnDTO) -> Column:
+        """Converts a ColumnDTO to a Column.
+
+        Args:
+            dto (ColumnDTO): The column DTO to be converted.
+
+        Returns:
+            Column: The column.
+        """
+        if dto.default_value() == Column.DEFAULT_VALUE_NOT_SET:
+            return dto
+        return Column.of(
+            dto.name(),
+            dto.data_type(),
+            dto.comment(),
+            dto.nullable(),
+            dto.auto_increment(),
+            DTOConverters.from_function_arg(dto.default_value()),
+        )
+
+    @from_dto.register
+    @staticmethod
+    def _(dto: Partitioning) -> Transform:  # pylint: 
disable=too-many-return-statements
+        """Converts a partitioning DTO to a Transform.
+
+        Args:
+            dto (Partitioning): The partitioning DTO to be converted.
+
+        Returns:
+            Transform: The transform.
+        """
+        strategy = dto.strategy()
+        if strategy is Partitioning.Strategy.IDENTITY:
+            return Transforms.identity(cast(SingleFieldPartitioning, 
dto).field_name())
+        if strategy is Partitioning.Strategy.YEAR:
+            return Transforms.year(cast(SingleFieldPartitioning, 
dto).field_name())
+        if strategy is Partitioning.Strategy.MONTH:
+            return Transforms.month(cast(SingleFieldPartitioning, 
dto).field_name())
+        if strategy is Partitioning.Strategy.DAY:
+            return Transforms.day(cast(SingleFieldPartitioning, 
dto).field_name())
+        if strategy is Partitioning.Strategy.HOUR:
+            return Transforms.hour(cast(SingleFieldPartitioning, 
dto).field_name())
+        if strategy is Partitioning.Strategy.BUCKET:
+            bucket_partitioning_dto = cast(BucketPartitioningDTO, dto)
+            return Transforms.bucket(
+                bucket_partitioning_dto.num_buckets(),
+                *bucket_partitioning_dto.field_names(),
+            )
+        if strategy is Partitioning.Strategy.TRUNCATE:
+            truncate_partitioning_dto = cast(TruncatePartitioningDTO, dto)
+            return Transforms.truncate(
+                truncate_partitioning_dto.width(),
+                truncate_partitioning_dto.field_name(),
+            )
+        if strategy is Partitioning.Strategy.LIST:
+            list_partitioning_dto = cast(ListPartitioningDTO, dto)
+            return Transforms.list(
+                field_names=list_partitioning_dto.field_names(),
+                assignments=[
+                    cast(ListPartition, DTOConverters.from_dto(p))
+                    for p in list_partitioning_dto.assignments()
+                ],
+            )
+        if strategy is Partitioning.Strategy.RANGE:
+            range_partitioning_dto = cast(RangePartitioningDTO, dto)
+            return Transforms.range(
+                range_partitioning_dto.field_name(),
+                [
+                    cast(RangePartition, DTOConverters.from_dto(p))
+                    for p in range_partitioning_dto.assignments()
+                ],
+            )
+        if strategy is Partitioning.Strategy.FUNCTION:
+            function_partitioning_dto = cast(FunctionPartitioningDTO, dto)
+            return Transforms.apply(
+                function_partitioning_dto.function_name(),
+                
DTOConverters.from_function_args(function_partitioning_dto.args()),
+            )
+        raise IllegalArgumentException(f"Unsupported partitioning: {strategy}")
+
+    @from_dto.register
+    @staticmethod
+    def _(dto: TableDTO) -> Table:
+        """Converts a TableDTO to a Table.
+
+        Args:
+            dto (TableDTO): The table DTO to be converted.
+
+        Returns:
+            Table: The table.
+        """
+
+        class TableImpl(Table):  # pylint: disable=too-many-instance-attributes

Review Comment:
   I think the purpose is the same, whether it holds the `tableDTO`, or the 
fields of `tableDTO` don't affect the purpose of this class (this class object 
will be used by the user). We don't have to strictly align with Java's 
implementation, but my feeling is that the class name should be the same. So 
for the users who are migrating from Java to Python can easily find the 
counterpart class to use, what do you think?



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