jerryshao commented on code in PR #14806:
URL: https://github.com/apache/gravitino/pull/14806#discussion_r4520768079
##########
clients/client-python/gravitino/api/rel/expressions/literals/literals.py:
##########
@@ -108,8 +108,10 @@ def double_literal(value: float) -> LiteralImpl[float]:
@staticmethod
def decimal_literal(value: decimal.Decimal) ->
LiteralImpl[decimal.Decimal]:
- precision: int = len(value.as_tuple().digits)
- scale: int = -value.as_tuple().exponent
+ decimal_tuple = value.as_tuple()
Review Comment:
Non-blocking: for `Decimal("NaN")` and `Decimal("Infinity")`,
`as_tuple().exponent` is a string (`'n'` / `'F'`), so
`max(decimal_tuple.exponent, 0)` raises a `TypeError`. The old `-exponent`
failed the same way, so this is not a regression, but a short `if not
value.is_finite(): raise ValueError(...)` would give a clearer error. Fine to
handle in a follow-up.
##########
clients/client-python/gravitino/api/rel/expressions/literals/literals.py:
##########
@@ -108,8 +108,10 @@ def double_literal(value: float) -> LiteralImpl[float]:
@staticmethod
def decimal_literal(value: decimal.Decimal) ->
LiteralImpl[decimal.Decimal]:
- precision: int = len(value.as_tuple().digits)
- scale: int = -value.as_tuple().exponent
+ decimal_tuple = value.as_tuple()
+ # Positive exponents add integer digits, not a negative fractional
scale.
+ precision: int = len(decimal_tuple.digits) +
max(decimal_tuple.exponent, 0)
Review Comment:
Heads up on parity with the Java side: `Decimal(BigDecimal)` uses
`value.scale()` as the scale, and `new BigDecimal("1E+3")` has scale -3, which
`DecimalType.checkPrecisionScale` rejects. So after this change the Python
client accepts a positive-exponent value that the Java API still rejects. The
fix itself looks correct to me. Could you confirm that a literal like
`Decimal("1E+3")` still works when it is sent to the server (e.g. how it is
serialized, and that the server can parse `1E+3`), or note the intended
behaviour in the docstring or PR description?
--
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]