Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the arithmetic long overflow exception with null date values. #16796

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions server/src/main/java/org/opensearch/common/time/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ public static Instant clampToNanosRange(Instant instant) {
return instant;
}

public static Instant clampToMillisRange(Instant instant) {
if (instant.isBefore(Instant.ofEpochMilli(Long.MIN_VALUE))) {
return Instant.ofEpochMilli(Long.MIN_VALUE);
}
if (instant.isAfter(Instant.ofEpochMilli(Long.MAX_VALUE))) {
return Instant.ofEpochMilli(Long.MAX_VALUE);
}
return instant;
}

/**
* convert a long value to a java time instant
* the long value resembles the nanoseconds since the epoch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public enum Resolution {
MILLISECONDS(CONTENT_TYPE, NumericType.DATE) {
@Override
public long convert(Instant instant) {
return instant.toEpochMilli();
return clampToValidRange(instant).toEpochMilli();
}

@Override
Expand All @@ -133,7 +133,7 @@ public Instant toInstant(long value) {

@Override
public Instant clampToValidRange(Instant instant) {
return instant;
return DateUtils.clampToMillisRange(instant);
}

@Override
Expand Down Expand Up @@ -612,6 +612,7 @@ public Relation isFieldWithinQuery(
if (isSearchable() == false && hasDocValues()) {
return Relation.INTERSECTS;
}

if (dateParser == null) {
dateParser = this.dateMathParser;
}
Expand Down
Loading