private Query . Builder createScatterQuery ( Query query , int numSplits ) { // TODO(pcostello): We can potentially support better splits with equality filters in our query // if there exists a composite index on property, __scatter__, __key__. Until an API for // metadata exists, this isn't possible. Note that ancestor and inequality queries fall into // the same category. Query . Builder scatterPointQuery = Query . newBuilder ( ) ; scatterPointQuery . addAllKind ( query . getKindList ( ) ) ; scatterPointQuery . addOrder ( DatastoreHelper . makeOrder ( DatastoreHelper . SCATTER_PROPERTY_NAME , Direction . ASCENDING ) ) ; // There is a split containing entities before and after each scatter entity: // ||---*------*------*------*------*------*------*---|| = scatter entity // If we represent each split as a region before a scatter entity, there is an extra region // following the last scatter point. Thus, we do not need the scatter entities for the last // region. scatterPointQuery . getLimitBuilder ( ) . setValue ( ( numSplits - 1 ) * KEYS_PER_SPLIT ) ; scatterPointQuery . addProjection ( Projection . newBuilder ( ) . setProperty ( PropertyReference . newBuilder ( ) . setName ( "__key__" ) ) ) ; return scatterPointQuery ; }
Creates a scatter query from the given user query