-
Notifications
You must be signed in to change notification settings - Fork 5
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
Use new document store search api #255
Changes from 1 commit
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 |
---|---|---|
|
@@ -40,6 +40,13 @@ | |
import org.hypertrace.core.documentstore.OrderBy; | ||
import org.hypertrace.core.documentstore.Query; | ||
import org.hypertrace.core.documentstore.UpdateResult; | ||
import org.hypertrace.core.documentstore.expression.impl.ConstantExpression; | ||
import org.hypertrace.core.documentstore.expression.impl.IdentifierExpression; | ||
import org.hypertrace.core.documentstore.expression.impl.LogicalExpression; | ||
import org.hypertrace.core.documentstore.expression.impl.RelationalExpression; | ||
import org.hypertrace.core.documentstore.expression.operators.RelationalOperator; | ||
import org.hypertrace.core.documentstore.expression.operators.SortOrder; | ||
import org.hypertrace.core.documentstore.model.options.QueryOptions; | ||
|
||
/** Document store which stores and serves the configurations. */ | ||
@Slf4j | ||
|
@@ -202,12 +209,11 @@ public Map<ConfigResourceContext, ContextSpecificConfig> getContextConfigs( | |
@Override | ||
public List<ContextSpecificConfig> getAllConfigs(ConfigResource configResource) | ||
throws IOException { | ||
Query query = new Query(); | ||
query.setFilter(this.getConfigResourceFilter(configResource)); | ||
query.addOrderBy(new OrderBy(VERSION_FIELD_NAME, false)); | ||
org.hypertrace.core.documentstore.query.Query query = buildQuery(configResource); | ||
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. If we have replaced all instance of 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. Old api was getting some other places also, moved to new one everywhere |
||
List<ContextSpecificConfig> contextSpecificConfigList = new ArrayList<>(); | ||
Set<String> seenContexts = new HashSet<>(); | ||
try (CloseableIterator<Document> documentIterator = collection.search(query)) { | ||
try (CloseableIterator<Document> documentIterator = | ||
collection.query(query, QueryOptions.DEFAULT_QUERY_OPTIONS)) { | ||
while (documentIterator.hasNext()) { | ||
String documentString = documentIterator.next().toJson(); | ||
ConfigDocument configDocument = ConfigDocument.fromJson(documentString); | ||
|
@@ -354,4 +360,28 @@ private ConfigResourceContext buildConfigResourceContext(ConfigDocument configDo | |
configDocument.getTenantId()), | ||
configDocument.getContext()); | ||
} | ||
|
||
private org.hypertrace.core.documentstore.query.Query buildQuery(ConfigResource configResource) { | ||
return org.hypertrace.core.documentstore.query.Query.builder() | ||
.addSort(IdentifierExpression.of(VERSION_FIELD_NAME), SortOrder.DESC) | ||
.setFilter( | ||
org.hypertrace.core.documentstore.query.Filter.builder() | ||
.expression( | ||
LogicalExpression.and( | ||
List.of( | ||
RelationalExpression.of( | ||
IdentifierExpression.of(RESOURCE_FIELD_NAME), | ||
RelationalOperator.EQ, | ||
ConstantExpression.of(configResource.getResourceName())), | ||
RelationalExpression.of( | ||
IdentifierExpression.of(RESOURCE_NAMESPACE_FIELD_NAME), | ||
RelationalOperator.EQ, | ||
ConstantExpression.of(configResource.getResourceNamespace())), | ||
RelationalExpression.of( | ||
IdentifierExpression.of(TENANT_ID_FIELD_NAME), | ||
RelationalOperator.EQ, | ||
ConstantExpression.of(configResource.getTenantId()))))) | ||
.build()) | ||
.build(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
getConfigResourceFilter
isn't getting used anywhere else, can we get rid of it?