-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94b544d
commit 294eaa0
Showing
31 changed files
with
1,196 additions
and
122 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
21 changes: 21 additions & 0 deletions
21
src/main/java/io/stargate/sgv2/jsonapi/api/model/command/impl/CountDocumentsCommands.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,21 @@ | ||
package io.stargate.sgv2.jsonapi.api.model.command.impl; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import io.stargate.sgv2.jsonapi.api.model.command.Filterable; | ||
import io.stargate.sgv2.jsonapi.api.model.command.ReadCommand; | ||
import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.FilterClause; | ||
import javax.annotation.Nullable; | ||
import javax.validation.Valid; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
@Schema( | ||
description = | ||
"Command that returns count of documents in a collection based on the collection.") | ||
@JsonTypeName("countDocuments") | ||
public record CountDocumentsCommands( | ||
@Valid @JsonProperty("filter") FilterClause filterClause, @Valid @Nullable Options options) | ||
implements ReadCommand, Filterable { | ||
|
||
public record Options() {} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/CountOperation.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,51 @@ | ||
package io.stargate.sgv2.jsonapi.service.operation.model; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
import io.stargate.bridge.proto.QueryOuterClass; | ||
import io.stargate.sgv2.api.common.cql.builder.BuiltCondition; | ||
import io.stargate.sgv2.api.common.cql.builder.QueryBuilder; | ||
import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; | ||
import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; | ||
import io.stargate.sgv2.jsonapi.exception.ErrorCode; | ||
import io.stargate.sgv2.jsonapi.exception.JsonApiException; | ||
import io.stargate.sgv2.jsonapi.service.bridge.executor.QueryExecutor; | ||
import io.stargate.sgv2.jsonapi.service.operation.model.impl.CountOperationPage; | ||
import io.stargate.sgv2.jsonapi.service.operation.model.impl.DBFilterBase; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Operation that returns count of documents based on the filter condition. Written with the | ||
* assumption that all variables to be indexed. | ||
*/ | ||
public record CountOperation(CommandContext commandContext, List<DBFilterBase> filters) | ||
implements ReadOperation { | ||
|
||
@Override | ||
public Uni<Supplier<CommandResult>> execute(QueryExecutor queryExecutor) { | ||
QueryOuterClass.Query query = buildSelectQuery(); | ||
return countDocuments(queryExecutor, query) | ||
.onItem() | ||
.transform(docs -> new CountOperationPage(docs.count())); | ||
} | ||
|
||
private QueryOuterClass.Query buildSelectQuery() { | ||
List<BuiltCondition> conditions = new ArrayList<>(filters.size()); | ||
for (DBFilterBase filter : filters) { | ||
conditions.add(filter.get()); | ||
} | ||
return new QueryBuilder() | ||
.select() | ||
.count("key") | ||
.as("count") | ||
.from(commandContext.namespace(), commandContext.collection()) | ||
.where(conditions) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public Uni<FindResponse> getDocuments(QueryExecutor queryExecutor) { | ||
return Uni.createFrom().failure(new JsonApiException(ErrorCode.UNSUPPORTED_OPERATION)); | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/ReadType.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,19 @@ | ||
package io.stargate.sgv2.jsonapi.service.operation.model; | ||
|
||
/** | ||
* Read type specifies what data needs to be read and returned as part of the response for | ||
* operations | ||
*/ | ||
public enum ReadType { | ||
/** | ||
* Return documents and transaction id which satisfies the filter conditions as part of response | ||
*/ | ||
DOCUMENT, | ||
/** | ||
* Return only document id and transaction id of documents which satisfies the filter conditions | ||
* as part of response | ||
*/ | ||
KEY, | ||
/** Return only count of documents which satisfies the filter condition */ | ||
COUNT | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/CountOperationPage.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,13 @@ | ||
package io.stargate.sgv2.jsonapi.service.operation.model.impl; | ||
|
||
import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; | ||
import io.stargate.sgv2.jsonapi.api.model.command.CommandStatus; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
public record CountOperationPage(int count) implements Supplier<CommandResult> { | ||
@Override | ||
public CommandResult get() { | ||
return new CommandResult(Map.of(CommandStatus.COUNTED_DOCUMENT, count())); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...a/io/stargate/sgv2/jsonapi/service/resolver/model/impl/CountDocumentsCommandResolver.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,36 @@ | ||
package io.stargate.sgv2.jsonapi.service.resolver.model.impl; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.stargate.sgv2.jsonapi.api.model.command.CommandContext; | ||
import io.stargate.sgv2.jsonapi.api.model.command.impl.CountDocumentsCommands; | ||
import io.stargate.sgv2.jsonapi.service.operation.model.Operation; | ||
import io.stargate.sgv2.jsonapi.service.operation.model.ReadType; | ||
import io.stargate.sgv2.jsonapi.service.resolver.model.CommandResolver; | ||
import io.stargate.sgv2.jsonapi.service.resolver.model.impl.matcher.FilterableResolver; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
/** Resolves the {@link CountDocumentsCommands } */ | ||
@ApplicationScoped | ||
public class CountDocumentsCommandResolver extends FilterableResolver<CountDocumentsCommands> | ||
implements CommandResolver<CountDocumentsCommands> { | ||
@Inject | ||
public CountDocumentsCommandResolver(ObjectMapper objectMapper) { | ||
super(objectMapper); | ||
} | ||
|
||
@Override | ||
public Class<CountDocumentsCommands> getCommandClass() { | ||
return CountDocumentsCommands.class; | ||
} | ||
|
||
@Override | ||
public Operation resolveCommand(CommandContext ctx, CountDocumentsCommands command) { | ||
return resolve(ctx, command); | ||
} | ||
|
||
@Override | ||
protected FilteringOptions getFilteringOption(CountDocumentsCommands command) { | ||
return new FilteringOptions(Integer.MAX_VALUE, null, 1, ReadType.COUNT); | ||
} | ||
} |
Oops, something went wrong.