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

Migrate from Proto1 to Proto2 #305

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
5 changes: 1 addition & 4 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>proto1</artifactId>
</dependency>

<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-utils</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import com.google.appengine.api.datastore.Index.IndexState;
import com.google.appengine.api.datastore.Query.FilterPredicate;
import com.google.apphosting.api.AppEngineInternal;
import com.google.apphosting.datastore.DatastoreV3Pb;
import com.google.apphosting.datastore.proto2api.DatastoreV3Pb;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.storage.onestore.v3.OnestoreEntity;
import com.google.storage.onestore.v3.proto2api.OnestoreEntity;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -260,16 +260,16 @@ public Index compositeIndexForQuery(Query query) {
}

public Set<Index> compositeIndexesForQuery(Query query) {
List<DatastoreV3Pb.Query> pbQueries =
List<DatastoreV3Pb.Query.Builder> pbQueries =
convertQueryToPbs(query, FetchOptions.Builder.withDefaults());
Set<Index> resultSet = new HashSet<Index>();
for (DatastoreV3Pb.Query queryProto : pbQueries) {
for (DatastoreV3Pb.Query.Builder queryProto : pbQueries) {
IndexComponentsOnlyQuery indexQuery = new IndexComponentsOnlyQuery(queryProto);

OnestoreEntity.Index index =
OnestoreEntity.Index.Builder index =
factory.getCompositeIndexManager().compositeIndexForQuery(indexQuery);
if (index != null) {
resultSet.add(IndexTranslator.convertFromPb(index));
resultSet.add(IndexTranslator.convertFromPb(index.build()));
}
}
return resultSet;
Expand All @@ -281,7 +281,7 @@ public Index minimumCompositeIndexForQuery(Query query, Collection<Index> indexe
}

public Set<Index> minimumCompositeIndexesForQuery(Query query, Collection<Index> indexes) {
List<DatastoreV3Pb.Query> pbQueries =
List<DatastoreV3Pb.Query.Builder> pbQueries =
convertQueryToPbs(query, FetchOptions.Builder.withDefaults());

List<OnestoreEntity.Index> indexPbs = Lists.newArrayListWithCapacity(indexes.size());
Expand All @@ -290,33 +290,34 @@ public Set<Index> minimumCompositeIndexesForQuery(Query query, Collection<Index>
}

Set<Index> resultSet = new HashSet<Index>();
for (DatastoreV3Pb.Query queryProto : pbQueries) {
for (DatastoreV3Pb.Query.Builder queryProto : pbQueries) {
IndexComponentsOnlyQuery indexQuery = new IndexComponentsOnlyQuery(queryProto);

OnestoreEntity.Index index =
OnestoreEntity.Index.Builder index =
factory.getCompositeIndexManager().minimumCompositeIndexForQuery(indexQuery, indexPbs);
if (index != null) {
resultSet.add(IndexTranslator.convertFromPb(index));
resultSet.add(IndexTranslator.convertFromPb(index.build()));
}
}
return resultSet;
}

/** Convert a query to a list of ProtocolBuffer Queries. */
@SuppressWarnings("deprecation")
private static List<DatastoreV3Pb.Query> convertQueryToPbs(
private static List<DatastoreV3Pb.Query.Builder> convertQueryToPbs(
Query query, FetchOptions fetchOptions) {
List<MultiQueryBuilder> queriesToRun = QuerySplitHelper.splitQuery(query);
// All Filters should be in queriesToRun
query.setFilter(null);
query.getFilterPredicates().clear();
List<DatastoreV3Pb.Query> resultQueries = new ArrayList<DatastoreV3Pb.Query>();
// query.getFilterPredicates().clear();
List<DatastoreV3Pb.Query.Builder> resultQueries = new ArrayList<DatastoreV3Pb.Query.Builder>();
for (MultiQueryBuilder multiQuery : queriesToRun) {
for (List<List<FilterPredicate>> parallelQueries : multiQuery) {
for (List<FilterPredicate> singleQuery : parallelQueries) {
Query newQuery = new Query(query);
newQuery.getFilterPredicates().addAll(singleQuery);
DatastoreV3Pb.Query queryProto = QueryTranslator.convertToPb(newQuery, fetchOptions);
// Query newQuery = new Query(query);
query.getFilterPredicates().clear();
query.getFilterPredicates().addAll(singleQuery);
DatastoreV3Pb.Query.Builder queryProto = QueryTranslator.convertToPb(query, fetchOptions);
resultQueries.add(queryProto);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.appengine.api.datastore.FutureHelper.MultiFuture;
import com.google.appengine.api.datastore.Index.IndexState;
import com.google.appengine.api.utils.FutureWrapper;
import com.google.apphosting.datastore.proto2api.DatastoreV3Pb.GetResponse;
import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
Expand Down
Loading
Loading