def testQuery(self):
   q = datastore.Query()
   helper.set_kind(q, 'Foo')
   self.assertEquals('Foo', q.kind[0].name)
   helper.add_property_orders(q, '-bar', 'foo')
   self.assertEquals(datastore.PropertyOrder.DESCENDING,
                     q.order[0].direction)
   self.assertEquals('bar', q.order[0].property.name)
   self.assertEquals(datastore.PropertyOrder.ASCENDING,
                     q.order[1].direction)
   self.assertEquals('foo', q.order[1].property.name)
   helper.add_projection(q, '__key__', 'bar')
   self.assertEquals('__key__', q.projection[0].property.name)
   self.assertEquals('bar', q.projection[1].property.name)
 def testQuery(self):
     q = datastore.Query()
     helper.set_kind(q, 'Foo')
     self.assertEquals('Foo', q.kind[0].name)
     helper.add_property_orders(q, '-bar', 'foo')
     self.assertEquals(datastore.PropertyOrder.DESCENDING,
                       q.order[0].direction)
     self.assertEquals('bar', q.order[0].property.name)
     self.assertEquals(datastore.PropertyOrder.ASCENDING,
                       q.order[1].direction)
     self.assertEquals('foo', q.order[1].property.name)
     helper.add_projection(q, '__key__', 'bar')
     self.assertEquals('__key__', q.projection[0].property.name)
     self.assertEquals('bar', q.projection[1].property.name)
Пример #3
0
def _create_scatter_query(query, num_splits):
    """Creates a scatter query from the given user query."""

    scatter_query = query_pb2.Query()
    for kind in query.kind:
        scatter_kind = scatter_query.kind.add()
        scatter_kind.CopyFrom(kind)

    # ascending order
    datastore_helper.add_property_orders(scatter_query, SCATTER_PROPERTY_NAME)

    # 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 entity for the last region.
    scatter_query.limit.value = (num_splits - 1) * KEYS_PER_SPLIT
    datastore_helper.add_projection(scatter_query, KEY_PROPERTY_NAME)

    return scatter_query
Пример #4
0
def _create_scatter_query(query, num_splits):
  """Creates a scatter query from the given user query."""

  scatter_query = query_pb2.Query()
  for kind in query.kind:
    scatter_kind = scatter_query.kind.add()
    scatter_kind.CopyFrom(kind)

  # ascending order
  datastore_helper.add_property_orders(scatter_query, SCATTER_PROPERTY_NAME)

  # 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 entity for the last region.
  scatter_query.limit.value = (num_splits - 1) * KEYS_PER_SPLIT
  datastore_helper.add_projection(scatter_query, KEY_PROPERTY_NAME)

  return scatter_query