kz930 commented on code in PR #8597:
URL: https://github.com/apache/texera/pull/8597#discussion_r4138559220
##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/StandaloneHelpers.scala:
##########
@@ -144,6 +192,38 @@ object StandaloneHelpers {
| return float(x)
|
|
+ |def _texera_java_text(x):
+ | # The text Java's toString gives the value Texera holds. A double
past
+ | # 1e7 or under 1e-3 is written in E notation, where Python's str()
+ | # waits until 1e16 and 1e-4. A java.sql.Timestamp writes every
digit of
+ | # its nanoseconds, trailing zeros dropped but never all of them,
where
+ | # Python writes no fraction on a whole second and six digits
otherwise.
+ | # A boolean is written in lower case.
+ | import datetime
+ | import decimal
+ |
+ | if pd.api.types.is_bool(x):
+ | return "true" if x else "false"
+ | if isinstance(x, datetime.datetime):
+ | nanos = x.microsecond * 1000 + getattr(x, "nanosecond", 0)
+ | return x.strftime("%Y-%m-%d %H:%M:%S") + "." +
(f"{nanos:09d}".rstrip("0") or "0")
+ | if pd.api.types.is_integer(x):
+ | return str(int(x))
+ | if pd.api.types.is_float(x):
+ | value = float(x)
+ | if value != value:
+ | return "NaN"
+ | if value in (float("inf"), float("-inf")):
+ | return "Infinity" if value > 0 else "-Infinity"
+ | if value == 0 or 1e-3 <= abs(value) < 1e7:
+ | return repr(value)
+ | sign, digits, exponent = decimal.Decimal(repr(value)).as_tuple()
Review Comment:
Confirmed on JDK 17. Matching it exactly means reproducing the digit
selection in OpenJDK's FloatingDecimal, which is GPL code, so is it OK to write
a Python version of it here, or should the helper keep the shortest form that
JDK 19+ gives?
--
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]