Caideyipi commented on code in PR #18589:
URL: https://github.com/apache/iotdb/pull/18589#discussion_r4478270779
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/DateTimeUtils.java:
##########
@@ -628,37 +640,46 @@ public static long convertDurationStrToLongForTest(
/** convert duration string to millisecond, microsecond or nanosecond. */
public static long convertDurationStrToLong(
long currentTime, long value, String unit, String timestampPrecision) {
+ try {
+ return convertDurationStrToLongInternal(currentTime, value, unit,
timestampPrecision);
+ } catch (ArithmeticException e) {
+ throw new SemanticException("Time duration is out of range.");
+ }
+ }
+
+ private static long convertDurationStrToLongInternal(
+ long currentTime, long value, String unit, String timestampPrecision) {
DurationUnit durationUnit = DurationUnit.valueOf(unit);
long res = value;
switch (durationUnit) {
case y:
- res *= 365 * 86_400_000L;
+ res = Math.multiplyExact(value, 365 * 86_400_000L);
break;
case mo:
if (currentTime == -1) {
- res *= 30 * 86_400_000L;
+ res = Math.multiplyExact(value, 30 * 86_400_000L);
} else {
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(SessionManager.getInstance().getSessionTimeZone());
calendar.setTimeInMillis(currentTime);
- calendar.add(Calendar.MONTH, (int) (value));
- res = calendar.getTimeInMillis() - currentTime;
+ calendar.add(Calendar.MONTH, Math.toIntExact(value));
+ res = Math.subtractExact(calendar.getTimeInMillis(), currentTime);
Review Comment:
Agreed. The calendar-month subtraction issue is left for a separate
master-first change, as suggested. This update adds fixed-duration regression
coverage; the month-component behavior remains unchanged.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/ai/InferenceOperator.java:
##########
@@ -374,4 +378,34 @@ public long ramBytesUsed() {
? 0
:
targetColumnNames.stream().mapToLong(RamUsageEstimator::sizeOf).sum());
}
+
+ static long calculateGeneratedTimeInterval(long minTimestamp, long
maxTimestamp, long totalRow) {
+ try {
+ BigInteger interval =
+ BigInteger.valueOf(maxTimestamp)
+ .subtract(BigInteger.valueOf(minTimestamp))
+ .divide(BigInteger.valueOf(totalRow));
+ if (interval.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
+ throw new ArithmeticException();
+ }
+ return interval.longValue();
+ } catch (ArithmeticException e) {
+ throw new
ModelInferenceProcessException(GENERATED_TIME_COLUMN_OUT_OF_RANGE_MESSAGE);
+ }
+ }
+
+ static long calculateGeneratedTime(long maxTimestamp, long interval, long
currentRowIndex) {
Review Comment:
Added the negative-base regression in 4c0daa4a997. It checks the 1e18
interval, accepts the valid 6e18 final timestamp at index 10 despite an
overflowing intermediate product, and still rejects the out-of-range final
timestamp at index 14.
--
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]