desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Constructor.
Args:
orders: A list of Orders which are applied in order.'
| def __init__(self, orders):
| if (not isinstance(orders, (list, tuple))):
raise datastore_errors.BadArgumentError(('orders argument should be list or tuple (%r)' % (orders,)))
super(CompositeOrder, self).__init__()
flattened = []
for order in orders:
if isinstance(order, CompositeOrder):
... |
'Returns the number of sub-orders the instance contains.'
| def size(self):
| return len(self._orders)
|
'Returns an ordered list of internal only pb representations.'
| def _to_pbs(self):
| return [order._to_pb() for order in self._orders]
|
'If a Cursor should be returned with the fetched results.
Raises:
datastore_errors.BadArgumentError if value is not a bool.'
| @datastore_rpc.ConfigOption
def produce_cursors(value):
| if (not isinstance(value, bool)):
raise datastore_errors.BadArgumentError(('produce_cursors argument should be bool (%r)' % (value,)))
return value
|
'The number of results to skip before returning the first result.
Only applies to the first request it is used with and is ignored if present
on datastore_rpc.Connection.config.
Raises:
datastore_errors.BadArgumentError if value is not a integer or is less
than zero.'
| @datastore_rpc.ConfigOption
def offset(value):
| datastore_types.ValidateInteger(value, 'offset', datastore_errors.BadArgumentError, zero_ok=True)
return value
|
'The number of results to attempt to retrieve in a batch.
Raises:
datastore_errors.BadArgumentError if value is not a integer or is not
greater than zero.'
| @datastore_rpc.ConfigOption
def batch_size(value):
| datastore_types.ValidateInteger(value, 'batch_size', datastore_errors.BadArgumentError)
return value
|
'If the query should only return keys.
Raises:
datastore_errors.BadArgumentError if value is not a bool.'
| @datastore_rpc.ConfigOption
def keys_only(value):
| if (not isinstance(value, bool)):
raise datastore_errors.BadArgumentError(('keys_only argument should be bool (%r)' % (value,)))
return value
|
'A list or tuple of property names to project.
If None, the entire entity is returned.
Specifying a projection:
- may change the index requirements for the given query;
- will cause a partial entity to be returned;
- will cause only entities that contain those properties to be returned;
A partial entities only contain ... | @datastore_rpc.ConfigOption
def projection(value):
| if isinstance(value, list):
value = tuple(value)
elif (not isinstance(value, tuple)):
raise datastore_errors.BadArgumentError(('projection argument should be a list or tuple (%r)' % (value,)))
if (not value):
raise datastore_errors.BadArgumentError('projection... |
'Limit on the number of results to return.
Raises:
datastore_errors.BadArgumentError if value is not an integer or is less
than zero.'
| @datastore_rpc.ConfigOption
def limit(value):
| datastore_types.ValidateInteger(value, 'limit', datastore_errors.BadArgumentError, zero_ok=True)
return value
|
'Number of results to attempt to return on the initial request.
Raises:
datastore_errors.BadArgumentError if value is not an integer or is not
greater than zero.'
| @datastore_rpc.ConfigOption
def prefetch_size(value):
| datastore_types.ValidateInteger(value, 'prefetch_size', datastore_errors.BadArgumentError, zero_ok=True)
return value
|
'Cursor to use a start position.
Ignored if present on datastore_rpc.Connection.config.
Raises:
datastore_errors.BadArgumentError if value is not a Cursor.'
| @datastore_rpc.ConfigOption
def start_cursor(value):
| if (not isinstance(value, Cursor)):
raise datastore_errors.BadArgumentError(('start_cursor argument should be datastore_query.Cursor (%r)' % (value,)))
return value
|
'Cursor to use as an end position.
Ignored if present on datastore_rpc.Connection.config.
Raises:
datastore_errors.BadArgumentError if value is not a Cursor.'
| @datastore_rpc.ConfigOption
def end_cursor(value):
| if (not isinstance(value, Cursor)):
raise datastore_errors.BadArgumentError(('end_cursor argument should be datastore_query.Cursor (%r)' % (value,)))
return value
|
'Hint on how the datastore should plan the query.
Raises:
datastore_errors.BadArgumentError if value is not a known hint.'
| @datastore_rpc.ConfigOption
def hint(value):
| if (value not in QueryOptions._HINTS):
raise datastore_errors.BadArgumentError(('Unknown query hint (%r)' % (value,)))
return value
|
'Constructor.
A Cursor constructed with no arguments points the first result of any
query. If such a Cursor is used as an end_cursor no results will ever be
returned.'
| @datastore_rpc._positional(1)
def __init__(self, _cursor_pb=None, urlsafe=None):
| super(Cursor, self).__init__()
if (urlsafe is not None):
if (_cursor_pb is not None):
raise datastore_errors.BadArgumentError('Do not use _cursor_pb and urlsafe together')
_cursor_pb = self._bytes_to_cursor_pb(self._urlsafe_to_bytes(urlsafe))
if (_cursor_pb is n... |
'Creates a cursor for use in a query with a reversed sort order.'
| def reversed(self):
| for pos in self.__compiled_cursor.position_list():
if pos.has_start_key():
raise datastore_errors.BadRequestError('Cursor cannot be reversed.')
rev_pb = datastore_pb.CompiledCursor()
rev_pb.CopyFrom(self.__compiled_cursor)
for pos in rev_pb.position_list():
pos.set_s... |
'Serialize cursor as a byte string.'
| def to_bytes(self):
| return self.__compiled_cursor.Encode()
|
'Gets a Cursor given its byte string serialized form.
The serialized form of a cursor may change in a non-backwards compatible
way. In this case cursors must be regenerated from a new Query request.
Args:
cursor: A serialized cursor as returned by .to_bytes.
Returns:
A Cursor.
Raises:
datastore_errors.BadValueError if ... | @staticmethod
def from_bytes(cursor):
| cursor_pb = Cursor._bytes_to_cursor_pb(cursor)
return Cursor(_cursor_pb=cursor_pb)
|
'Serialize cursor as a websafe string.
Returns:
A base64-encoded serialized cursor.'
| def urlsafe(self):
| return base64.urlsafe_b64encode(self.to_bytes())
|
'Gets a Cursor given its websafe serialized form.
The serialized form of a cursor may change in a non-backwards compatible
way. In this case cursors must be regenerated from a new Query request.
Args:
cursor: A serialized cursor as returned by .to_websafe_string.
Returns:
A Cursor.
Raises:
datastore_errors.BadValueErro... | @staticmethod
def from_websafe_string(cursor):
| decoded_bytes = Cursor._urlsafe_to_bytes(cursor)
return Cursor.from_bytes(decoded_bytes)
|
'Advances a Cursor by the given offset.
Args:
offset: The amount to advance the current query.
query: A Query identical to the one this cursor was created from.
conn: The datastore_rpc.Connection to use.
Returns:
A new cursor that is advanced by offset using the given query.'
| def advance(self, offset, query, conn):
| datastore_types.ValidateInteger(offset, 'offset', datastore_errors.BadArgumentError)
if (not isinstance(query, Query)):
raise datastore_errors.BadArgumentError(('query argument should be datastore_query.Query (%r)' % (query,)))
query_options = QueryOptions(start_cursor=self, offset=of... |
'Returns the internal only pb representation.'
| def _to_pb(self):
| return self.__compiled_cursor
|
'Constructs a _QueryKeyFilter.
If app/namespace and ancestor are not defined, the app/namespace set in the
environment is used.
Args:
app: a string representing the required app id or None.
namespace: a string representing the required namespace or None.
kind: a string representing the required kind or None.
ancestor: ... | @datastore_rpc._positional(1)
def __init__(self, app=None, namespace=None, kind=None, ancestor=None):
| if (kind is not None):
datastore_types.ValidateString(kind, 'kind', datastore_errors.BadArgumentError)
if (ancestor is not None):
if (not isinstance(ancestor, entity_pb.Reference)):
raise datastore_errors.BadArgumentError(('ancestor argument should be entity_pb.Reference ... |
'Apply the filter.
Accepts either an entity or a reference to avoid the need to extract keys
from entities when we have a list of entities (which is a common case).
Args:
entity_or_reference: Either an entity_pb.EntityProto or
entity_pb.Reference.'
| def __call__(self, entity_or_reference):
| if isinstance(entity_or_reference, entity_pb.Reference):
key = entity_or_reference
elif isinstance(entity_or_reference, entity_pb.EntityProto):
key = entity_or_reference.key()
else:
raise datastore_errors.BadArgumentError(('entity_or_reference argument must be an entit... |
'Runs the query using provided datastore_rpc.Connection.
Args:
conn: The datastore_rpc.Connection to use
query_options: Optional query options to use
Returns:
A Batcher that implicitly fetches query results asynchronously.
Raises:
datastore_errors.BadArgumentError if any of the arguments are invalid.'
| def run(self, conn, query_options=None):
| return Batcher(query_options, self.run_async(conn, query_options))
|
'Runs the query using the provided datastore_rpc.Connection.
Args:
conn: the datastore_rpc.Connection on which to run the query.
query_options: Optional QueryOptions with which to run the query.
Returns:
An async object that can be used to grab the first Batch. Additional
batches can be retrieved by calling Batch.next_... | def run_async(self, conn, query_options=None):
| raise NotImplementedError
|
'Constructor.
Args:
app: Optional app to query, derived from the environment if not specified.
namespace: Optional namespace to query, derived from the environment if
not specified.
kind: Optional kind to query.
ancestor: Optional ancestor to query, an entity_pb.Reference.
filter_predicate: Optional FilterPredicate by ... | @datastore_rpc._positional(1)
def __init__(self, app=None, namespace=None, kind=None, ancestor=None, filter_predicate=None, group_by=None, order=None):
| super(Query, self).__init__()
if ((filter_predicate is not None) and (not isinstance(filter_predicate, FilterPredicate))):
raise datastore_errors.BadArgumentError(('filter_predicate should be datastore_query.FilterPredicate (%r)' % (ancestor,)))
if isinstance(order, CompositeOrder):
... |
'Returns the internal only pb representation.'
| def _to_pb(self, conn, query_options):
| pb = self._key_filter._to_pb()
if self._filter_predicate:
for f in self._filter_predicate._to_pbs():
pb.add_filter().CopyFrom(f)
if self._order:
for order in self._order._to_pbs():
pb.add_order().CopyFrom(order)
if self._group_by:
pb.group_by_property_name... |
'Constructor for _AugmentedQuery.
Do not call directly. Use the utility functions instead (e.g.
datastore_query.inject_results)
Args:
query: A datastore_query.Query object to augment.
in_memory_results: a list of pre- sorted and filtered result to add to the
stream of datastore results or None .
in_memory_filter: a set... | @datastore_rpc._positional(2)
def __init__(self, query, in_memory_results=None, in_memory_filter=None, max_filtered_count=None):
| if (not isinstance(query, Query)):
raise datastore_errors.BadArgumentError(('query argument should be datastore_query.Query (%r)' % (query,)))
if ((in_memory_filter is not None) and (not isinstance(in_memory_filter, FilterPredicate))):
raise datastore_errors.BadArgumentError(('in_... |
'Returns the list of indexes used by the query.
Possibly None when the adapter does not implement pb_to_index.'
| @property
def index_list(self):
| return self.__index_list
|
'Constructor.
This class is constructed in stages (one when an RPC is sent and another
when an rpc is completed) and should not be constructed directly!!
Use Query.run_async().get_result() to create a Batch or Query.run()
to use a batcher.
This constructor does not perform verification.
Args:
batch_shared: Data shared ... | @datastore_rpc._positional(2)
def __init__(self, batch_shared, start_cursor=Cursor()):
| self._batch_shared = batch_shared
self.__start_cursor = start_cursor
|
'The QueryOptions used to retrieve the first batch.'
| @property
def query_options(self):
| return self._batch_shared.query_options
|
'The query the current batch came from.'
| @property
def query(self):
| return self._batch_shared.query
|
'A list of entities in this batch.'
| @property
def results(self):
| return self.__results
|
'Whether the entities in this batch only contain keys.'
| @property
def keys_only(self):
| return self._batch_shared.keys_only
|
'Returns the list of indexes used to peform this batch\'s query.
Possibly None when the adapter does not implement pb_to_index.'
| @property
def index_list(self):
| return self._batch_shared.index_list
|
'A cursor that points to the position just before the current batch.'
| @property
def start_cursor(self):
| return self.__start_cursor
|
'A cursor that points to the position just after the current batch.'
| @property
def end_cursor(self):
| return self.__end_cursor
|
'The number of results skipped because of an offset in the request.
An offset is satisfied before any results are returned. The start_cursor
points to the position in the query before the skipped results.'
| @property
def skipped_results(self):
| return self._skipped_results
|
'Whether more results can be retrieved from the query.'
| @property
def more_results(self):
| return self.__more_results
|
'Synchronously get the next batch or None if there are no more batches.
Args:
fetch_options: Optional fetch options to use when fetching the next batch.
Merged with both the fetch options on the original call and the
connection.
Returns:
A new Batch of results or None if either the next batch has already been
fetched o... | def next_batch(self, fetch_options=None):
| async = self.next_batch_async(fetch_options)
if (async is None):
return None
return async.get_result()
|
'Gets the cursor that points to the result at the given index.
The index is relative to first result in .results. Since start_cursor
points to the position before the first skipped result and the end_cursor
points to the position after the last result, the range of indexes this
function supports is limited to [-skipped... | def cursor(self, index):
| if (not isinstance(index, (int, long))):
raise datastore_errors.BadArgumentError(('index argument should be entity_pb.Reference (%r)' % (index,)))
if (not ((- self._skipped_results) <= index <= len(self.__results))):
raise datastore_errors.BadArgumentError(('index argument m... |
'Asynchronously get the next batch or None if there are no more batches.
Args:
fetch_options: Optional fetch options to use when fetching the next batch.
Merged with both the fetch options on the original call and the
connection.
Returns:
An async object that can be used to get the next Batch or None if either
the next... | def next_batch_async(self, fetch_options=None):
| if (not self.__datastore_cursor):
return None
(fetch_options, next_batch) = self._make_next_batch(fetch_options)
req = self._to_pb(fetch_options)
config = self._batch_shared.query_options.merge(fetch_options)
return next_batch._make_query_result_rpc_call('Next', config, req)
|
'Combines the current batch with the next one. Called by batcher.'
| def _extend(self, next_batch):
| self.__datastore_cursor = next_batch.__datastore_cursor
next_batch.__datastore_cursor = None
self.__more_results = next_batch.__more_results
self.__results.extend(next_batch.__results)
self.__end_cursor = next_batch.__end_cursor
self._skipped_results += next_batch._skipped_results
|
'Makes either a RunQuery or Next call that will modify the instance.
Args:
name: A string, the name of the call to invoke.
config: The datastore_rpc.Configuration to use for the call.
req: The request to send with the call.
Returns:
A UserRPC object that can be used to fetch the result of the RPC.'
| def _make_query_result_rpc_call(self, name, config, req):
| return self._batch_shared.conn.make_rpc_call(config, name, req, datastore_pb.QueryResult(), self.__query_result_hook)
|
'Internal method used as get_result_hook for RunQuery/Next operation.'
| def __query_result_hook(self, rpc):
| try:
self._batch_shared.conn.check_rpc_success(rpc)
except datastore_errors.NeedIndexError as exc:
if isinstance(rpc.request, datastore_pb.Query):
(_, kind, ancestor, props) = datastore_index.CompositeIndexForQuery(rpc.request)
props = datastore_index.GetRecommendedIndexP... |
'Changes the internal state so that no more batches can be produced.'
| def _end(self):
| self.__datastore_cursor = None
self.__more_results = False
|
'Creates the object to store the next batch.
Args:
fetch_options: The datastore_query.FetchOptions passed in by the user or
None.
Returns:
A tuple containing the fetch options that should be used internally and
the object that should be used to contain the next batch.'
| def _make_next_batch(self, fetch_options):
| return (fetch_options, Batch(self._batch_shared, start_cursor=self.__end_cursor))
|
'Converts the datastore results into results returned to the user.
Args:
results: A list of entity_pb.EntityProto\'s returned by the datastore
Returns:
A list of results that should be returned to the user.'
| def _process_results(self, results):
| pb_to_query_result = self._batch_shared.conn.adapter.pb_to_query_result
return [pb_to_query_result(result, self._batch_shared.query_options) for result in results]
|
'A Constructor for datastore_query._AugmentedBatch.
Constructed by datastore_query._AugmentedQuery. Should not be called
directly.'
| @datastore_rpc._positional(2)
def __init__(self, batch_shared, in_memory_offset=None, in_memory_limit=None, next_index=0, start_cursor=Cursor()):
| super(_AugmentedBatch, self).__init__(batch_shared, start_cursor=start_cursor)
self.__in_memory_offset = in_memory_offset
self.__in_memory_limit = in_memory_limit
self.__next_index = next_index
|
'The query the current batch came from.'
| @property
def query(self):
| return self._batch_shared.augmented_query
|
'Constructor.
Although this class can be manually constructed, it is preferable to use
Query.run(query_options).
Args:
query_options: The QueryOptions used to create the first batch.
first_async_batch: The first batch produced by
Query.run_async(query_options).'
| def __init__(self, query_options, first_async_batch):
| self.__next_batch = first_async_batch
self.__initial_offset = (QueryOptions.offset(query_options) or 0)
self.__skipped_results = 0
|
'Get the next batch. See .next_batch().'
| def next(self):
| return self.next_batch(self.AT_LEAST_ONE)
|
'Get the next batch.
The batch returned by this function cannot be used to fetch the next batch
(through Batch.next_batch()). Instead this function will always return None.
To retrieve the next batch use .next() or .next_batch(N).
This function may return a batch larger than min_to_fetch, but will never
return smaller ... | def next_batch(self, min_batch_size):
| if (min_batch_size in (Batcher.ASYNC_ONLY, Batcher.AT_LEAST_OFFSET, Batcher.AT_LEAST_ONE)):
exact = False
else:
exact = True
datastore_types.ValidateInteger(min_batch_size, 'min_batch_size', datastore_errors.BadArgumentError)
if (not self.__next_batch):
raise StopIteration
... |
'Constructor.
Args:
batcher: A datastore_query.Batcher'
| def __init__(self, batcher):
| if (not isinstance(batcher, Batcher)):
raise datastore_errors.BadArgumentError(('batcher argument should be datastore_query.Batcher (%r)' % (batcher,)))
self.__batcher = batcher
self.__current_batch = None
self.__current_pos = 0
|
'Returns the list of indexes used to perform the query.
Possibly None when the adapter does not implement pb_to_index.'
| def index_list(self):
| return self._ensure_current_batch().index_list
|
'Returns a cursor that points just after the last result returned.'
| def cursor(self):
| return self._ensure_current_batch().cursor(self.__current_pos)
|
'Returns the compiled query associated with the iterator.
Internal only do not use.'
| def _compiled_query(self):
| if (not self.__current_batch):
self.__current_batch = self.__batcher.next()
self.__current_pos = 0
return self.__current_batch._compiled_query()
|
'Returns the next query result.'
| def next(self):
| while ((not self.__current_batch) or (self.__current_pos >= len(self.__current_batch.results))):
next_batch = self.__batcher.next()
if (not next_batch):
raise StopIteration
self.__current_pos = 0
self.__current_batch = next_batch
result = self.__current_batch.results[... |
'Constructor.
Args:
root_path: Path to the app\'s root directory.'
| def __init__(self, root_path):
| self.root_path = root_path
|
'Update index.yaml.
Args:
openfile: Used for dependency injection.
We only ever write to index.yaml if either:
- it doesn\'t exist yet; or
- it contains an \'AUTOGENERATED\' comment.
All indexes *before* the AUTOGENERATED comment will be written
back unchanged. All indexes *after* the AUTOGENERATED comment
will be upd... | def UpdateIndexYaml(self, openfile=open):
| index_yaml_file = os.path.join(self.root_path, 'index.yaml')
try:
index_yaml_mtime = os.path.getmtime(index_yaml_file)
except os.error:
index_yaml_mtime = None
index_yaml_changed = (index_yaml_mtime != self.index_yaml_mtime)
self.index_yaml_mtime = index_yaml_mtime
datastore_stub... |
'Constructor.
Creates an unlimited range.'
| def __init__(self):
| self.__start = self.__end = None
self.__start_inclusive = self.__end_inclusive = False
|
'Filter the range by \'rel_op limit\'.
Args:
rel_op: relational operator from datastore_pb.Query_Filter.
limit: the value to limit the range by.'
| def Update(self, rel_op, limit):
| if (rel_op == datastore_pb.Query_Filter.LESS_THAN):
if ((self.__end is None) or (limit <= self.__end)):
self.__end = limit
self.__end_inclusive = False
elif ((rel_op == datastore_pb.Query_Filter.LESS_THAN_OR_EQUAL) or (rel_op == datastore_pb.Query_Filter.EQUAL)):
if ((sel... |
'Check if the range contains a specific value.
Args:
value: the value to check.
Returns:
True iff value is contained in this range.'
| def Contains(self, value):
| if (self.__start is not None):
if (self.__start_inclusive and (value < self.__start)):
return False
if ((not self.__start_inclusive) and (value <= self.__start)):
return False
if (self.__end is not None):
if (self.__end_inclusive and (value > self.__end)):
... |
'Transforms the range extremes with a function.
The function mapper must preserve order, i.e.
x rel_op y iff mapper(x) rel_op y
Args:
mapper: function to apply to the range extremes.'
| def Remap(self, mapper):
| self.__start = (self.__start and mapper(self.__start))
self.__end = (self.__end and mapper(self.__end))
|
'Evaluate a function on the range extremes.
Args:
mapper: function to apply to the range extremes.
Returns:
(x, y) where x = None if the range has no start,
mapper(start, start_inclusive, False) otherwise
y = None if the range has no end,
mapper(end, end_inclusive, True) otherwise'
| def MapExtremes(self, mapper):
| return ((self.__start and mapper(self.__start, self.__start_inclusive, False)), (self.__end and mapper(self.__end, self.__end_inclusive, True)))
|
'Constructor.
Args:
app: The app this cursor is being created for.'
| def __init__(self, app):
| self.app = app
self.cursor = self._AcquireCursorID()
|
'Creates cursor for the given query result.'
| def PopulateCursor(self, query_result):
| if query_result.more_results():
cursor = query_result.mutable_cursor()
cursor.set_app(self.app)
cursor.set_cursor(self.cursor)
|
'Acquires the next cursor id in a thread safe manner.'
| @classmethod
def _AcquireCursorID(cls):
| cls._next_cursor_lock.acquire()
try:
cursor_id = cls._next_cursor
cls._next_cursor += 1
finally:
cls._next_cursor_lock.release()
return cursor_id
|
'Constructor.
Args:
query: A Query PB.
results: A list of EntityProtos.
last_ent: The last entity (used for cursors).'
| def __init__(self, query, results, last_ent):
| self.__order_property_names = order_property_names(query)
self.__results = results
self.__query = query
self.__last_ent = last_ent
self.app = query.app()
if query.has_limit():
self.limit = (query.limit() + query.offset())
else:
self.limit = None
|
'Converts the current state of the cursor into a compiled_cursor.
Args:
query: the datastore_pb.Query this cursor is related to
compiled_cursor: an empty datstore_pb.CompiledCursor'
| def _EncodeCompiledCursor(self, compiled_cursor):
| last_result = None
if self.__results:
last_result = self.__results[(-1)]
elif self.__last_ent:
last_result = entity_pb.EntityProto()
last_result.ParseFromString(self.__last_ent)
if (last_result is not None):
position = compiled_cursor.add_position()
position.mutab... |
'Populates a QueryResult PB with results from the cursor.
Args:
count: The number of results to retrieve.
offset: The number of results to skip.
result: out: A query_result PB.'
| def PopulateQueryResult(self, count, offset, result):
| result.set_skipped_results(min(count, offset))
result_list = result.result_list()
if self.__results:
if self.__query.keys_only():
for entity in self.__results:
entity.clear_property()
entity.clear_raw_property()
result_list.append(entity)
... |
'Constructor.
Args:
query: the query request proto'
| def __init__(self, query):
| super(ListCursor, self).__init__(query.app())
self.__order_property_names = order_property_names(query)
if (query.has_compiled_cursor() and query.compiled_cursor().position_list()):
(self.__last_result, _) = self._DecodeCompiledCursor(query.compiled_cursor())
else:
self.__last_result = N... |
'Protected access to private member.'
| def _GetLastResult(self):
| return self.__last_result
|
'Protected access to private member for last entity.'
| def _GetEndResult(self):
| return self.__end_result
|
'Converts a cursor entity into a offset into the result set even if the
cursor_entity no longer exists.
Args:
results: the query\'s results (sequence of datastore_pb.EntityProto)
cursor_entity: the datastore_pb.EntityProto from the compiled query
inclusive: boolean that specifies if to offset past the cursor_entity
com... | @staticmethod
def _GetCursorOffset(results, cursor_entity, inclusive, compare):
| lo = 0
hi = len(results)
if inclusive:
while (lo < hi):
mid = ((lo + hi) // 2)
if (compare(results[mid], cursor_entity) < 0):
lo = (mid + 1)
else:
hi = mid
else:
while (lo < hi):
mid = ((lo + hi) // 2)
... |
'Converts a compiled_cursor into a cursor_entity.
Args:
compiled_cursor: The datastore_pb.CompiledCursor to decode.
Returns:
(cursor_entity, inclusive): a datastore_pb.EntityProto and if it should
be included in the result set.'
| def _DecodeCompiledCursor(self, compiled_cursor):
| assert (len(compiled_cursor.position_list()) == 1)
position = compiled_cursor.position(0)
remaining_properties = self.__order_property_names.copy()
cursor_entity = datastore_pb.EntityProto()
cursor_entity.mutable_key().CopyFrom(position.key())
for indexvalue in position.indexvalue_list():
... |
'Counts results, up to the query\'s limit.
Note this method does not deduplicate results, so the query it was generated
from should have the \'distinct\' clause applied.
Returns:
int: Result count.'
| def Count(self):
| return self.__count
|
'Scans all the namespaces and processes each namespace.'
| def __ScanAllNamespaces(self):
| namespace_query = datastore.Query('__namespace__', _app=self.app_id)
for namespace_entity in namespace_query.Run():
name = namespace_entity.key().name()
if (name is None):
name = ''
self.__ProcessNamespace(name)
|
'Process all the entities in a given namespace.'
| def __ProcessNamespace(self, namespace):
| all_query = datastore.Query(namespace=namespace, _app=self.app_id)
for entity in all_query.Run():
self.found_non_empty_namespace |= (namespace != '')
proto = entity.ToPb()
proto_size = len(proto.SerializeToString())
if (entity.key().kind() in stats._DATASTORE_STATS_CLASSES_BY_KIN... |
'Return the size and count of indexes for a property of an EntityProto.'
| def __GetPropertyIndexStat(self, namespace, kind_name, entity_key_size, prop):
| property_index_size = ((((len(self.app_id) + len(kind_name)) + len(prop.value().SerializeToString())) + len(namespace)) + entity_key_size)
return (property_index_size, 2)
|
'Return the size and count of indexes by type of an EntityProto.'
| def __GetTypeIndexStat(self, namespace, kind_name, entity_key_size):
| type_index_size = (((len(self.app_id) + len(kind_name)) + entity_key_size) + len(namespace))
return (type_index_size, 1)
|
'Increment datastore stats for a non stats record.'
| def __ProcessUserEntity(self, proto_size, key, proto, namespace):
| self.__AggregateTotal(proto_size, key, proto, namespace, None)
kind_name = key.kind()
entity_key_size = (((len(proto.key().app()) + len(namespace)) + len(proto.key().path().SerializeToString())) + len(proto.entity_group().SerializeToString()))
self.__AggregateCompositeIndices(proto, namespace, kind_name... |
'Get statistics of composite index for a index definition of an entity.'
| def __GetCompositeIndexStat(self, definition, proto, namespace, kind_name, entity_key_size):
| property_list = proto.property_list()
property_count = []
property_size = []
index_count = 1
for indexed_prop in definition.property_list():
name = indexed_prop.name()
count = 0
prop_size = 0
for prop in property_list:
if (prop.name() == name):
... |
'Aggregate statistics of composite indexes for an entity.'
| def __AggregateCompositeIndices(self, proto, namespace, kind_name, entity_key_size):
| composite_indices = datastore_admin.GetIndices(self.app_id)
for index in composite_indices:
definition = index.definition()
if (kind_name != definition.entity_type()):
continue
(index_size, index_count) = self.__GetCompositeIndexStat(definition, proto, namespace, kind_name, e... |
'Aggregate total datastore stats.'
| def __AggregateTotal(self, size, key, proto, namespace, stat_kind):
| kind_name = key.kind()
entity_key_size = ((len(proto.key().app()) + len(proto.key().path().SerializeToString())) + len(proto.entity_group().SerializeToString()))
(type_index_size, type_index_count) = self.__GetTypeIndexStat(namespace, kind_name, entity_key_size)
property_index_count = 0
property_ind... |
'Increment stats for a particular kind.
Args:
stats_dict: The dictionary where the entities are held.
The entities are keyed by stat_key. e.g. The
__Stat_Total__ entity will be found in stats_dict[_GLOBAL_KEY].
count: The amount to increment the datastore stat by.
stat_key: A tuple of (db.Model of the stat, key value, ... | def __Increment(self, stats_dict, count, stat_key, size, builtin_index_count=0, builtin_index_size=0, composite_index_count=0, composite_index_size=0, **kwds):
| if (stat_key not in stats_dict):
stat_model = stat_key[0](key=datastore_types.Key.from_path(stat_key[0].STORED_KIND_NAME, stat_key[1], namespace=stat_key[2], _app=self.app_id), _app=self.app_id)
stats_dict[stat_key] = stat_model
for (field, value) in kwds.iteritems():
setattr(sta... |
'Finishes processing, deletes all old stats and writes new ones.'
| def __Finalize(self):
| for i in range(0, len(self.old_stat_keys), DELETE_BATCH_SIZE):
datastore.Delete(self.old_stat_keys[i:(i + DELETE_BATCH_SIZE)])
self.written = 0
for stat in self.whole_app_stats.itervalues():
if (stat.count or (not (isinstance(stat, stats.GlobalStat) or isinstance(stat, stats.NamespaceStat)))... |
'Scans the datastore, computes new stats and writes them.'
| def Run(self):
| self.__ScanAllNamespaces()
self.__Finalize()
return self
|
'Produce a small report about the result.'
| def Report(self):
| stat = self.whole_app_stats.get(_GLOBAL_KEY, None)
entity_size = 0
entity_count = 0
builtin_index_size = 0
builtin_index_count = 0
composite_index_size = 0
composite_index_count = 0
if stat:
entity_size = stat.entity_bytes
entity_count = stat.count
builtin_index_s... |
'Turn an entity_pb.Reference into a user-level key.'
| def pb_to_key(self, pb):
| raise NotImplementedError
|
'Turn an entity_pb.EntityProto into a user-level entity.'
| def pb_to_entity(self, pb):
| raise NotImplementedError
|
'Turn an entity_pb.CompositeIndex into a user-level Index
representation.'
| def pb_to_index(self, pb):
| raise NotImplementedError
|
'Turn an entity_pb.EntityProto into a user-level query result.'
| def pb_to_query_result(self, pb, query_options):
| if query_options.keys_only:
return self.pb_to_key(pb.key())
else:
return self.pb_to_entity(pb)
|
'Turn a user-level key into an entity_pb.Reference.'
| def key_to_pb(self, key):
| raise NotImplementedError
|
'Turn a user-level entity into an entity_pb.EntityProto.'
| def entity_to_pb(self, entity):
| raise NotImplementedError
|
'Create a new, empty entity_pb.Reference.'
| def new_key_pb(self):
| return entity_pb.Reference()
|
'Create a new, empty entity_pb.EntityProto.'
| def new_entity_pb(self):
| return entity_pb.EntityProto()
|
'Gets the first non-None value for this option from the given args.
Args:
*arg: Any number of configuration objects or None values.
Returns:
The first value for this ConfigOption found in the given configuration
objects or None.
Raises:
datastore_errors.BadArgumentError if a given in object is not a
configuration objec... | def __call__(self, *args):
| name = self.validator.__name__
for config in args:
if isinstance(config, (type(None), apiproxy_stub_map.UserRPC)):
pass
elif (not isinstance(config, BaseConfiguration)):
raise datastore_errors.BadArgumentError(('invalid config argument (%r)' % (config,)))
... |
'Immutable constructor.
If \'config\' is non-None all configuration options will default to the value
it contains unless the configuration option is explicitly set to \'None\' in
the keyword arguments. If \'config\' is None then all configuration options
default to None.
Args:
config: Optional base configuration provid... | def __new__(cls, config=None, **kwargs):
| if (config is None):
pass
elif isinstance(config, BaseConfiguration):
if ((cls is config.__class__) and config.__is_stronger(**kwargs)):
return config
for (key, value) in config._values.iteritems():
if issubclass(cls, config._options[key]._cls):
kw... |
'Internal helper to ask whether a configuration is stronger than another.
A configuration is stronger when it contains every name/value pair in
kwargs.
Example: a configuration with:
(deadline=5, on_configuration=None, read_policy=EVENTUAL_CONSISTENCY)
is stronger than:
(deadline=5, on_configuration=None)
but not stron... | def __is_stronger(self, **kwargs):
| for (key, value) in kwargs.iteritems():
if ((key not in self._values) or (value != self._values[key])):
return False
return True
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.