use of com.google.storage.onestore.v3.OnestoreEntity.Index in project appengine-java-standard by GoogleCloudPlatform.
the class AdminDatastoreService method minimumCompositeIndexesForQuery.
public Set<Index> minimumCompositeIndexesForQuery(Query query, Collection<Index> indexes) {
List<DatastoreV3Pb.Query> pbQueries = convertQueryToPbs(query, FetchOptions.Builder.withDefaults());
List<OnestoreEntity.Index> indexPbs = Lists.newArrayListWithCapacity(indexes.size());
for (Index index : indexes) {
indexPbs.add(IndexTranslator.convertToPb(index));
}
Set<Index> resultSet = new HashSet<Index>();
for (DatastoreV3Pb.Query queryProto : pbQueries) {
IndexComponentsOnlyQuery indexQuery = new IndexComponentsOnlyQuery(queryProto);
OnestoreEntity.Index index = factory.getCompositeIndexManager().minimumCompositeIndexForQuery(indexQuery, indexPbs);
if (index != null) {
resultSet.add(IndexTranslator.convertFromPb(index));
}
}
return resultSet;
}
use of com.google.storage.onestore.v3.OnestoreEntity.Index in project appengine-java-standard by GoogleCloudPlatform.
the class AdminDatastoreService method compositeIndexesForQuery.
public Set<Index> compositeIndexesForQuery(Query query) {
List<DatastoreV3Pb.Query> pbQueries = convertQueryToPbs(query, FetchOptions.Builder.withDefaults());
Set<Index> resultSet = new HashSet<Index>();
for (DatastoreV3Pb.Query queryProto : pbQueries) {
IndexComponentsOnlyQuery indexQuery = new IndexComponentsOnlyQuery(queryProto);
OnestoreEntity.Index index = factory.getCompositeIndexManager().compositeIndexForQuery(indexQuery);
if (index != null) {
resultSet.add(IndexTranslator.convertFromPb(index));
}
}
return resultSet;
}
use of com.google.storage.onestore.v3.OnestoreEntity.Index in project appengine-java-standard by GoogleCloudPlatform.
the class AdminDatastoreServiceTest method testMinimumCompositeIndexWithOr.
@SuppressWarnings("deprecation")
@Test
public void testMinimumCompositeIndexWithOr() {
Query query = new Query("kind1");
query.setFilter(CompositeFilterOperator.and(CompositeFilterOperator.or(new FilterPredicate("a", FilterOperator.EQUAL, 1), new FilterPredicate("b", FilterOperator.EQUAL, 1)), new FilterPredicate("c", FilterOperator.LESS_THAN, 2)));
Query firstQuery = new Query("kind1");
firstQuery.addFilter("a", FilterOperator.EQUAL, 1);
firstQuery.addFilter("c", FilterOperator.LESS_THAN, 2);
Query secondQuery = new Query("kind1");
secondQuery.addFilter("b", FilterOperator.EQUAL, 1);
secondQuery.addFilter("c", FilterOperator.LESS_THAN, 2);
Collection<Index> indexList = ImmutableList.of();
Collection<OnestoreEntity.Index> indexPbList = ImmutableList.of();
Index expectedFirstIndex = new Index(0, "kind1", true, Lists.newArrayList(new Index.Property("a", Query.SortDirection.DESCENDING), new Index.Property("c", Query.SortDirection.DESCENDING)));
OnestoreEntity.Index expectedFirstIndexPb = IndexTranslator.convertToPb(expectedFirstIndex);
Index expectedSecondIndex = new Index(0, "kind1", true, Lists.newArrayList(new Index.Property("b", Query.SortDirection.DESCENDING), new Index.Property("c", Query.SortDirection.DESCENDING)));
OnestoreEntity.Index expectedSecondIndexPb = IndexTranslator.convertToPb(expectedSecondIndex);
// We cannot predict the order of predicates in the IndexComponentsOnlyQuery.
when(indexManager.minimumCompositeIndexForQuery(notNull(), eq(indexPbList))).thenReturn(expectedFirstIndexPb).thenReturn(expectedSecondIndexPb);
Set<Index> minimumIndexes = adminDsWithMockDelegate.minimumCompositeIndexesForQuery(query, indexList);
assertThat(minimumIndexes).containsExactly(expectedFirstIndex, expectedSecondIndex);
}
use of com.google.storage.onestore.v3.OnestoreEntity.Index in project appengine-java-standard by GoogleCloudPlatform.
the class LocalDatastoreService method createIndexOnlyQueryResults.
/**
* Converts a normal result set into the results seen in an index-only query (a projection).
*
* @param queryEntities the results to convert
* @param entityComparator the comparator derived from the query
* @return the converted results
*/
private List<EntityProto> createIndexOnlyQueryResults(List<EntityProto> queryEntities, EntityProtoComparator entityComparator) {
Set<String> postfixProps = Sets.newHashSetWithExpectedSize(entityComparator.getAdjustedOrders().size());
for (Query.Order order : entityComparator.getAdjustedOrders()) {
postfixProps.add(order.getProperty());
}
List<EntityProto> results = Lists.newArrayListWithExpectedSize(queryEntities.size());
for (EntityProto entity : queryEntities) {
List<EntityProto> indexEntities = createIndexEntities(entity, postfixProps, entityComparator);
results.addAll(indexEntities);
}
return results;
}
use of com.google.storage.onestore.v3.OnestoreEntity.Index in project appengine-java-standard by GoogleCloudPlatform.
the class LocalCompositeIndexManager method buildIndexMapFromQueryHistory.
// @VisibleForTesting
Map<Index, Integer> buildIndexMapFromQueryHistory() {
// LinkedHashMap gives us repeatable results in our tests and
// minimizes file churn.
Map<Index, Integer> indexMap = Maps.newLinkedHashMap();
synchronized (queryHistory) {
for (Map.Entry<IndexComponentsOnlyQuery, AtomicInteger> entry : queryHistory.entrySet()) {
Index index = compositeIndexForQuery(entry.getKey());
if (index == null) {
// not interested in queries that don't need an index
continue;
}
Integer count = indexMap.get(index);
if (count == null) {
count = 0;
}
count += entry.getValue().intValue();
indexMap.put(index, count);
}
}
return indexMap;
}
Aggregations