def make_kind_stats_query(namespace, kind, latest_timestamp): """Make a Query to fetch the latest kind statistics.""" kind_stat_query = query_pb2.Query() if namespace is None: kind_stat_query.kind.add().name = '__Stat_Kind__' else: kind_stat_query.kind.add().name = '__Stat_Ns_Kind__' kind_filter = datastore_helper.set_property_filter( query_pb2.Filter(), 'kind_name', PropertyFilter.EQUAL, unicode(kind)) timestamp_filter = datastore_helper.set_property_filter( query_pb2.Filter(), 'timestamp', PropertyFilter.EQUAL, latest_timestamp) datastore_helper.set_composite_filter(kind_stat_query.filter, CompositeFilter.AND, kind_filter, timestamp_filter) return kind_stat_query
def make_kind_stats_query(namespace, kind, latest_timestamp): """Make a Query to fetch the latest kind statistics.""" kind_stat_query = query_pb2.Query() if namespace is None: kind_stat_query.kind.add().name = '__Stat_Kind__' else: kind_stat_query.kind.add().name = '__Stat_Ns_Kind__' kind_filter = datastore_helper.set_property_filter( query_pb2.Filter(), 'kind_name', PropertyFilter.EQUAL, unicode(kind)) timestamp_filter = datastore_helper.set_property_filter( query_pb2.Filter(), 'timestamp', PropertyFilter.EQUAL, latest_timestamp) datastore_helper.set_composite_filter(kind_stat_query.filter, CompositeFilter.AND, kind_filter, timestamp_filter) return kind_stat_query
def testFilter(self): f = datastore.Filter() helper.set_composite_filter( f, datastore.CompositeFilter.AND, helper.set_property_filter(datastore.Filter(), 'foo', datastore.PropertyFilter.EQUAL, u'bar'), helper.set_property_filter(datastore.Filter(), 'hop', datastore.PropertyFilter.GREATER_THAN, 2.0)) cf = f.composite_filter pf = cf.filter[0].property_filter self.assertEquals('foo', pf.property.name) self.assertEquals('bar', pf.value.string_value) self.assertEquals(datastore.PropertyFilter.EQUAL, pf.operator) pf = cf.filter[1].property_filter self.assertEquals('hop', pf.property.name) self.assertEquals(2.0, pf.value.double_value) self.assertEquals(datastore.PropertyFilter.GREATER_THAN, pf.operator) self.assertEquals(datastore.CompositeFilter.AND, cf.operator)
def testFilter(self): f = datastore.Filter() helper.set_composite_filter( f, datastore.CompositeFilter.AND, helper.set_property_filter(datastore.Filter(), 'foo', datastore.PropertyFilter.EQUAL, u'bar'), helper.set_property_filter(datastore.Filter(), 'hop', datastore.PropertyFilter.GREATER_THAN, 2.0)) cf = f.composite_filter pf = cf.filter[0].property_filter self.assertEquals('foo', pf.property.name) self.assertEquals('bar', pf.value.string_value) self.assertEquals(datastore.PropertyFilter.EQUAL, pf.operator) pf = cf.filter[1].property_filter self.assertEquals('hop', pf.property.name) self.assertEquals(2.0, pf.value.double_value) self.assertEquals(datastore.PropertyFilter.GREATER_THAN, pf.operator) self.assertEquals(datastore.CompositeFilter.AND, cf.operator)