-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Improve Time-Series Bucketing Scalability #1137
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
Changes from 3 commits
c633293
91af5e2
132a840
2a86297
d874af0
85c85d2
48f2189
698f599
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ | |
|
||
import com.mongodb.lang.Nullable; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import static com.mongodb.assertions.Assertions.isTrueArgument; | ||
import static com.mongodb.assertions.Assertions.notNull; | ||
|
||
/** | ||
|
@@ -31,6 +34,8 @@ public final class TimeSeriesOptions { | |
private final String timeField; | ||
private String metaField; | ||
private TimeSeriesGranularity granularity; | ||
private Long bucketMaxSpanSeconds; | ||
private Long bucketRoundingSeconds; | ||
|
||
/** | ||
* Construct a new instance. | ||
|
@@ -104,12 +109,102 @@ public TimeSeriesOptions granularity(@Nullable final TimeSeriesGranularity granu | |
return this; | ||
} | ||
|
||
/** | ||
* Returns the maximum time span between measurements in a bucket. | ||
* | ||
* @param timeUnit the time unit. | ||
* @return time span between measurements. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: add "or null if not set." |
||
* @since 4.10 | ||
* @mongodb.server.release 6.3 | ||
stIncMale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @mongodb.driver.manual core/timeseries-collections/ Time-series collections | ||
stIncMale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @see #bucketMaxSpan(Long, TimeUnit) | ||
*/ | ||
@Nullable | ||
public Long getBucketMaxSpan(final TimeUnit timeUnit) { | ||
if (bucketMaxSpanSeconds == null) { | ||
return null; | ||
} | ||
return timeUnit.convert(bucketMaxSpanSeconds, TimeUnit.SECONDS); | ||
} | ||
|
||
/** | ||
* Sets the maximum time span between measurements in a bucket. | ||
* <p> | ||
* The value of {@code bucketMaxSpanSeconds} must be the same as {@code bucketRoundingSeconds}. | ||
stIncMale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* If you set the {@code bucketMaxSpanSeconds}, parameter, you can't set the granularity parameter. | ||
stIncMale marked this conversation as resolved.
Show resolved
Hide resolved
stIncMale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* </p> | ||
* | ||
* @param bucketMaxSpan time span between measurements. After conversion to seconds using {@link TimeUnit#convert(long, java.util.concurrent.TimeUnit)}, | ||
* the value must be >= 1. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Also accepts |
||
* @param timeUnit the time unit. | ||
stIncMale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @return this | ||
* @since 4.10 | ||
* @mongodb.server.release 6.3 | ||
* @mongodb.driver.manual core/timeseries-collections/ Time-series collections | ||
* @see #getBucketMaxSpan(TimeUnit) | ||
*/ | ||
public TimeSeriesOptions bucketMaxSpan(@Nullable final Long bucketMaxSpan, final TimeUnit timeUnit) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As for now, There is a task JAVA-4191 for introducing |
||
if (bucketMaxSpan == null) { | ||
this.bucketMaxSpanSeconds = null; | ||
} else { | ||
this.bucketMaxSpanSeconds = TimeUnit.SECONDS.convert(bucketMaxSpan, timeUnit); | ||
isTrueArgument("bucketMaxSpan, after conversion to seconds, must be >= 1", bucketMaxSpanSeconds > 0); | ||
} | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns the time interval that determines the starting timestamp for a new bucket. | ||
* | ||
* @param timeUnit the time unit. | ||
* @return the time interval. | ||
* @since 4.10 | ||
* @mongodb.server.release 6.3 | ||
* @mongodb.driver.manual core/timeseries-collections/ Time-series collections | ||
* @see #bucketRounding(Long, TimeUnit) | ||
*/ | ||
@Nullable | ||
public Long getBucketRounding(final TimeUnit timeUnit) { | ||
if (bucketRoundingSeconds == null) { | ||
return null; | ||
} | ||
return timeUnit.convert(bucketRoundingSeconds, TimeUnit.SECONDS); | ||
} | ||
|
||
/** | ||
* Specifies the time interval that determines the starting timestamp for a new bucket. | ||
* <p> | ||
* The value of {@code bucketRoundingSeconds} must be the same as {@code bucketMaxSpanSeconds}. | ||
* If you set the {@code bucketRoundingSeconds}, parameter, you can't set the granularity parameter. | ||
* </p> | ||
* | ||
* @param bucketRounding time interval. After conversion to seconds using {@link TimeUnit#convert(long, java.util.concurrent.TimeUnit)}, | ||
* the value must be >= 1. | ||
* @param timeUnit the time unit. | ||
* @return this | ||
* @since 4.10 | ||
* @mongodb.server.release 6.3 | ||
* @mongodb.driver.manual core/timeseries-collections/ Time-series collections | ||
* @see #getBucketRounding(TimeUnit) | ||
*/ | ||
public TimeSeriesOptions bucketRounding(@Nullable final Long bucketRounding, final TimeUnit timeUnit) { | ||
if (bucketRounding == null) { | ||
this.bucketRoundingSeconds = null; | ||
} else { | ||
this.bucketRoundingSeconds = TimeUnit.SECONDS.convert(bucketRounding, timeUnit); | ||
isTrueArgument("bucketRounding, after conversion to seconds, must be >= 1", bucketMaxSpanSeconds > 0); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TimeSeriesOptions{" | ||
+ "timeField='" + timeField + '\'' | ||
+ ", metaField='" + metaField + '\'' | ||
+ ", granularity=" + granularity | ||
+ ", bucketMaxSpanSeconds=" + bucketMaxSpanSeconds | ||
+ ", bucketRoundingSeconds=" + bucketRoundingSeconds | ||
+ '}'; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.