kz930 commented on code in PR #8597:
URL: https://github.com/apache/texera/pull/8597#discussion_r4434428682
##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/StandaloneHelpers.scala:
##########
@@ -76,97 +70,221 @@ object StandaloneHelpers {
| if fraction:
| return sign * float((digits or "0") + "." + fraction), True
| value = sign * int(digits)
- | # A whole number past long's range comes back as a Double.
| if -(2 ** 63) <= value <= 2 ** 63 - 1:
| return value, False
| return float(value), True
|
- |
- |def _texera_long_value(value, is_double):
- | # Number.longValue(): a Double truncates toward zero and saturates
at
- | # long's bounds, where a Long is already itself.
- | if is_double:
- | return max(-(2 ** 63), min(2 ** 63 - 1, int(value)))
- | return value
- |
+ |def _texera_saturate(value, low, high):
+ | if value != value:
+ | return 0
+ | if value <= low:
+ | return low
+ | if value >= high:
+ | return high
+ | return int(value)
|
|def _texera_cast_integral(x):
- | # The LONG target. Scala's toLong takes no decimal point of its
own, so
- | # a fraction only ever arrives already parsed.
| if isinstance(x, str):
- | return _texera_long_value(*_texera_parse_number(x))
+ | x, is_double = _texera_parse_number(x)
+ | if not is_double:
+ | return x
| if isinstance(x, bool):
| return 1 if x else 0
| if isinstance(x, float):
- | return _texera_long_value(x, True)
+ | return _texera_saturate(x, -(2 ** 63), 2 ** 63 - 1)
| return int(x)
|
- |
|def _texera_cast_int32(x, wrap):
- | # The two 32-bit narrowings differ: Long.toInt keeps the low bits,
so
- | # 2147483648 comes back as -2147483648, while Double.toInt
saturates.
- | #
- | # Text decides by what the parse returned; everything else is told
by the
- | # SOURCE column's declared type, because `Series.apply` hands the
cells of
- | # a nullable integer column over as floats.
| if isinstance(x, str):
| value, is_double = _texera_parse_number(x)
| wrap = not is_double
| elif isinstance(x, bool):
| value = 1 if x else 0
| else:
- | value = int(x)
+ | value = x
| if wrap:
- | return ((value + 2147483648) % 4294967296) - 2147483648
- | # int() first: Double.intValue truncates toward zero before it
clamps.
- | return max(-2147483648, min(2147483647, int(value)))
+ | return ((int(value) + 2147483648) % 4294967296) - 2147483648
+ | return _texera_saturate(value, -2147483648, 2147483647)
|
+ |def _texera_text_to_timestamp(s):
+ | from dateutil.parser import parse as _parse_date
+ |
+ | zone = _texera_local_zone()
+ |
+ | def _one(x):
+ | try:
+ | parsed = _parse_date(str(x).strip())
+ | except (ValueError, OverflowError) as e:
+ | raise ValueError(f"Failed to parse type str to Timestamp:
{x}") from e
+ | if parsed.tzinfo is not None:
+ | parsed = _texera_local_wall_clock(parsed, zone)
+ | return parsed.replace(microsecond=parsed.microsecond // 1000 *
1000)
+ |
+ | text = s.astype(str).str.strip()
+ | plain = s.notna() & text.str.fullmatch(
+ | r"[0-9]{4}-[0-9]{2}-[0-9]{2}([
T][0-9]{2}:[0-9]{2}(:[0-9]{2}(\.[0-9]+)?)?)?"
+ | )
+ | out = pd.Series(pd.NaT, index=s.index, dtype="datetime64[us]")
+ | out[plain] = pd.to_datetime(text[plain], format="ISO8601",
errors="coerce").dt.floor("ms")
Review Comment:
Fixed in 3f85c59c6: a wall clock inside a gap now moves forward by the gap,
the way `ZonedDateTime` does. Two tests in `TypeCastingOpDescSpec` read
`2024-03-10 02:30` in `America/New_York` and `2015-10-04 02:15` in
`Australia/Lord_Howe` and compare with `AttributeTypeUtils`.
--
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]