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

Improve Time-Series Bucketing Scalability #1137

Merged
merged 8 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
stIncMale marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @mongodb.driver.manual core/timeseries-collections/ Time-series collections
*/
public final class TimeSeriesOptions {
private static final String PARAMETER_TIME_UNIT = "timeUnit";
stIncMale marked this conversation as resolved.
Show resolved Hide resolved
private final String timeField;
private String metaField;
private TimeSeriesGranularity granularity;
Expand Down Expand Up @@ -124,6 +125,7 @@ public TimeSeriesOptions granularity(@Nullable final TimeSeriesGranularity granu
*/
@Nullable
public Long getBucketMaxSpan(final TimeUnit timeUnit) {
notNull(PARAMETER_TIME_UNIT, timeUnit);
if (bucketMaxSpanSeconds == null) {
return null;
}
Expand All @@ -147,7 +149,7 @@ public Long getBucketMaxSpan(final TimeUnit timeUnit) {
* @see #getBucketMaxSpan(TimeUnit)
*/
public TimeSeriesOptions bucketMaxSpan(@Nullable final Long bucketMaxSpan, final TimeUnit timeUnit) {
Copy link
Member Author

@vbabanin vbabanin Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for now, TimeUnit is used in order to maintain consistency within the driver since this approach ensures a unified way of handling time intervals throughout the codebase.

There is a task JAVA-4191 for introducing Duration for the API, which will enhance the functionality further

notNull("timeUnit", timeUnit);
notNull(PARAMETER_TIME_UNIT, timeUnit);
if (bucketMaxSpan == null) {
this.bucketMaxSpanSeconds = null;
} else {
Expand All @@ -169,6 +171,7 @@ public TimeSeriesOptions bucketMaxSpan(@Nullable final Long bucketMaxSpan, final
*/
@Nullable
public Long getBucketRounding(final TimeUnit timeUnit) {
notNull(PARAMETER_TIME_UNIT, timeUnit);
if (bucketRoundingSeconds == null) {
return null;
}
Expand All @@ -192,7 +195,7 @@ public Long getBucketRounding(final TimeUnit timeUnit) {
* @see #getBucketRounding(TimeUnit)
*/
public TimeSeriesOptions bucketRounding(@Nullable final Long bucketRounding, final TimeUnit timeUnit) {
notNull("timeUnit", timeUnit);
notNull(PARAMETER_TIME_UNIT, timeUnit);
if (bucketRounding == null) {
this.bucketRoundingSeconds = null;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ void shouldThrowErrorWhenGranularityIsAlreadySet() {
assertThrows(IllegalStateException.class, () -> timeSeriesOptions.bucketMaxSpan(1L, TimeUnit.SECONDS));
}

@Test
void shouldThrowErrorWhenGetWithNullParameter() {
assertThrows(IllegalArgumentException.class, () -> timeSeriesOptions.getBucketMaxSpan(null));
assertThrows(IllegalArgumentException.class, () -> timeSeriesOptions.getBucketRounding(null));
}

@ParameterizedTest
@MethodSource("args")
void shouldThrowErrorWhenInvalidArgumentProvided(@Nullable final Long valueToSet, @Nullable final TimeUnit timeUnit) {
Expand Down