tsungchih commented on code in PR #8841:
URL: https://github.com/apache/gravitino/pull/8841#discussion_r2445207187
##########
clients/client-python/gravitino/dto/util/dto_converters.py:
##########
@@ -76,3 +94,219 @@ 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:
Review Comment:
It's a convention in Python when using `singledispatch` or
`singledispatchmethod`. After the method has been decorated by
`singledispatchmethod`, we register a new data type of argument for the method
using `_` to prevent the method from being obscured by a new declaration of the
same name.
--
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]