carloea2 commented on code in PR #8597:
URL: https://github.com/apache/texera/pull/8597#discussion_r4127111356
##########
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:
Reproduced with the generated helper and JDK 17: 1e23 becomes 1.0E23 here,
but Double.toString returns 9.999999999999999E22. String comparisons and joins
after a cast can then differ. Please match Java's digit selection and add a
regression test.
--
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]