-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add query building API for the
$densify
aggregation pipeline stage (#…
- Loading branch information
Showing
20 changed files
with
1,079 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
driver-core/src/main/com/mongodb/client/model/densify/DateDensifyRange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUNumber WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mongodb.client.model.densify; | ||
|
||
import com.mongodb.annotations.Evolving; | ||
import com.mongodb.client.model.MongoTimeUnit; | ||
|
||
import java.time.Instant; | ||
|
||
/** | ||
* @see DensifyRange#fullRangeWithStep(long, MongoTimeUnit) | ||
* @see DensifyRange#partitionRangeWithStep(long, MongoTimeUnit) | ||
* @see DensifyRange#rangeWithStep(Instant, Instant, long, MongoTimeUnit) | ||
* @mongodb.server.release 5.1 | ||
* @since 4.7 | ||
*/ | ||
@Evolving | ||
public interface DateDensifyRange extends DensifyRange { | ||
} |
59 changes: 59 additions & 0 deletions
59
driver-core/src/main/com/mongodb/client/model/densify/DensifyConstructibleBson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mongodb.client.model.densify; | ||
|
||
import com.mongodb.internal.client.model.AbstractConstructibleBson; | ||
import org.bson.Document; | ||
import org.bson.conversions.Bson; | ||
|
||
import static com.mongodb.assertions.Assertions.notNull; | ||
import static com.mongodb.internal.client.model.Util.sizeAtLeast; | ||
|
||
final class DensifyConstructibleBson extends AbstractConstructibleBson<DensifyConstructibleBson> implements | ||
NumberDensifyRange, DateDensifyRange, | ||
DensifyOptions { | ||
static final DensifyConstructibleBson EMPTY_IMMUTABLE = new DensifyConstructibleBson(AbstractConstructibleBson.EMPTY_IMMUTABLE); | ||
|
||
DensifyConstructibleBson(final Bson base) { | ||
super(base); | ||
} | ||
|
||
private DensifyConstructibleBson(final Bson base, final Document appended) { | ||
super(base, appended); | ||
} | ||
|
||
@Override | ||
protected DensifyConstructibleBson newSelf(final Bson base, final Document appended) { | ||
return new DensifyConstructibleBson(base, appended); | ||
} | ||
|
||
@Override | ||
public DensifyOptions partitionByFields(final Iterable<String> fields) { | ||
notNull("partitionByFields", fields); | ||
return newMutated(doc -> { | ||
if (sizeAtLeast(fields, 1)) { | ||
doc.append("partitionByFields", fields); | ||
} else { | ||
doc.remove("partitionByFields"); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public DensifyOptions option(final String name, final Object value) { | ||
return newAppended(notNull("name", name), notNull("value", value)); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
driver-core/src/main/com/mongodb/client/model/densify/DensifyOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mongodb.client.model.densify; | ||
|
||
import com.mongodb.annotations.Evolving; | ||
import com.mongodb.client.model.Aggregates; | ||
import com.mongodb.lang.Nullable; | ||
import org.bson.conversions.Bson; | ||
|
||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.emptyList; | ||
|
||
/** | ||
* Represents optional fields of the {@code $densify} pipeline stage of an aggregation pipeline. | ||
* | ||
* @see Aggregates#densify(String, DensifyRange, DensifyOptions) | ||
* @see Aggregates#densify(String, DensifyRange) | ||
* @mongodb.server.release 5.1 | ||
* @since 4.7 | ||
*/ | ||
@Evolving | ||
public interface DensifyOptions extends Bson { | ||
/** | ||
* Creates a new {@link DensifyOptions} with the specified {@code fields} to partition by. | ||
* | ||
* @param fields The fields to partition by. | ||
* If no fields are specified, then the whole sequence is considered to be a single partition. | ||
* @return A new {@link DensifyOptions}. | ||
* @mongodb.driver.manual core/document/#dot-notation Dot notation | ||
*/ | ||
default DensifyOptions partitionByFields(@Nullable final String... fields) { | ||
return partitionByFields(fields == null ? emptyList() : asList(fields)); | ||
} | ||
|
||
/** | ||
* Creates a new {@link DensifyOptions} with the specified {@code fields} to partition by. | ||
* | ||
* @param fields The fields to partition by. | ||
* If no fields are specified, then the whole sequence is considered to be a single partition. | ||
* @return A new {@link DensifyOptions}. | ||
* @mongodb.driver.manual core/document/#dot-notation Dot notation | ||
*/ | ||
DensifyOptions partitionByFields(Iterable<String> fields); | ||
|
||
/** | ||
* Creates a new {@link DensifyOptions} with the specified option in situations when there is no builder method | ||
* that better satisfies your needs. | ||
* This method cannot be used to validate the syntax. | ||
* <p> | ||
* <i>Example</i><br> | ||
* The following code creates two functionally equivalent {@link DensifyOptions} objects, | ||
* though they may not be {@linkplain Object#equals(Object) equal}. | ||
* <pre>{@code | ||
* DensifyOptions options1 = DensifyOptions.densifyOptions() | ||
* .partitionByFields("fieldName"); | ||
* DensifyOptions options2 = DensifyOptions.densifyOptions() | ||
* .option("partitionByFields", Collections.singleton("fieldName")); | ||
* }</pre> | ||
* | ||
* @param name The option name. | ||
* @param value The option value. | ||
* @return A new {@link DensifyOptions}. | ||
*/ | ||
DensifyOptions option(String name, Object value); | ||
|
||
/** | ||
* Returns {@link DensifyOptions} that represents server defaults. | ||
* | ||
* @return {@link DensifyOptions} that represents server defaults. | ||
*/ | ||
static DensifyOptions densifyOptions() { | ||
return DensifyConstructibleBson.EMPTY_IMMUTABLE; | ||
} | ||
} |
Oops, something went wrong.