def _IndexesFromIndexDict(self, index_dict): """Convert a query dictionary into the corresponding required indexes. Args: index_dict: Index usage history, a dict mapping composite index descriptors to a count of the number of times that queries needing such an index have been executed Returns: a tuple (indexes, counts) where indexes and counts are lists of the same size, with each entry in indexes being a datastore_index.Index and each entry in indexes being the count of the number of times the corresponding query appeared in the history. """ indexes = [] counts = [] for (kind, ancestor, props), count in sorted(index_dict.iteritems()): properties = [] for prop in props: if prop.direction is None: direction = None else: direction = ( 'desc' if prop.direction == datastore_index.DESCENDING else 'asc') mode = ( 'geospatial' if prop.mode == datastore_index.GEOSPATIAL else None) properties.append(datastore_index.Property( name=prop.name, direction=direction, mode=mode)) indexes.append(datastore_index.Index( kind=kind, ancestor=bool(ancestor), properties=properties)) counts.append(count) return indexes, counts
def _IndexesFromIndexDict(self, index_dict): """Convert a query dictionary into the corresponding required indexes. Args: index_dict: Query history, a dict mapping datastore_pb.Query to a count of the number of times that query has been issued. Returns: a tuple (indexes, counts) where indexes and counts are lists of the same size, with each entry in indexes being a datastore_index.Index and each entry in indexes being the count of the number of times the corresponding query appeared in the history. """ indexes = [] counts = [] for (kind, ancestor, props), count in sorted(index_dict.iteritems()): properties = [] for prop in props: direction = ('asc' if prop.direction == datastore_index.ASCENDING else 'desc') properties.append( datastore_index.Property(name=prop.name, direction=direction)) indexes.append( datastore_index.Index(kind=kind, ancestor=bool(ancestor), properties=properties)) counts.append(count) return indexes, counts
def ProtoToIndexDefinition(proto): """Transform individual index protocol buffer to index definition. Args: proto: An instance of entity_pb.CompositeIndex to transform. Returns: A new instance of datastore_index.Index. """ properties = [] proto_index = proto.definition() for prop_proto in proto_index.property_list(): prop_definition = datastore_index.Property(name=prop_proto.name()) if prop_proto.direction() == entity_pb.Index_Property.DESCENDING: prop_definition.direction = 'descending' properties.append(prop_definition) index = datastore_index.Index(kind=proto_index.entity_type(), properties=properties) if proto_index.ancestor(): index.ancestor = True return index