def update(self, *args, **kwargs): log.debug('update') log.debug(f'self: {self}') log.debug(f'args: {args}') kwargs['return_changes'] = True log.debug(f'kwargs: {kwargs}') return ast.Update(self, *[ast.func_wrap(arg) for arg in args], **kwargs)
def http(url, **kwargs): """ Retrieve data from the specified URL over HTTP. The return type depends on the result_format option, which checks the Content-Type of the response by default. Make sure that you never use this command for user provided URLs. """ return ast.Http(ast.func_wrap(url), **kwargs)
def desc(*arguments): """ Sort the sequence by document values of the given key(s). To specify the ordering, wrap the attribute with either r.asc or r.desc (defaults to ascending). """ return ast.Desc(*[ast.func_wrap(arg) for arg in arguments])
def distinct(*arguments): """ Removes duplicate elements from a sequence. The distinct command can be called on any sequence or table with an index. """ return ast.Distinct(*[ast.func_wrap(arg) for arg in arguments])
def contains(*arguments): """ When called with values, returns True if a sequence contains all the specified values. When called with predicate functions, returns True if for each predicate there exists at least one element of the stream where that predicate returns True. Values and predicates may be mixed freely in the argument list. """ return ast.Contains(*[ast.func_wrap(arg) for arg in arguments])
def sum(*arguments): # pylint: disable=redefined-builtin """ Sums all the elements of a sequence. If called with a field name, sums all the values of that field in the sequence, skipping elements of the sequence that lack that field. If called with a function, calls that function on every element of the sequence and sums the results, skipping elements of the sequence where that function returns None or a non-existence error. Returns 0 when called on an empty sequence. """ return ast.Sum(*[ast.func_wrap(arg) for arg in arguments])
def group(*arguments): """ Takes a stream and partitions it into multiple groups based on the fields or functions provided. With the multi flag single documents can be assigned to multiple groups, similar to the behavior of multi-indexes. When multi is True and the grouping value is an array, documents will be placed in each group that corresponds to the elements of the array. If the array is empty the row will be ignored. """ return ast.Group(*[ast.func_wrap(arg) for arg in arguments])
def avg(*arguments): """ Averages all the elements of a sequence. If called with a field name, averages all the values of that field in the sequence, skipping elements of the sequence that lack that field. If called with a function, calls that function on every element of the sequence and averages the results, skipping elements of the sequence where that function returns None or a non-existence error. Produces a non-existence error when called on an empty sequence. You can handle this case with default. """ return ast.Avg(*[ast.func_wrap(arg) for arg in arguments])
def count(*arguments): """ Counts the number of elements in a sequence or key/value pairs in an object, or returns the size of a string or binary object. When count is called on a sequence with a predicate value or function, it returns the number of elements in the sequence equal to that value or where the function returns True. On a binary object, count returns the size of the object in bytes; on strings, count returns the string’s length. This is determined by counting the number of Unicode codepoints in the string, counting combining codepoints separately. """ return ast.Count(*[ast.func_wrap(arg) for arg in arguments])
def map(*arguments): # pylint: disable=redefined-builtin """ Transform each element of one or more sequences by applying a mapping function to them. If map is run with two or more sequences, it will iterate for as many items as there are in the shortest sequence. Note that map can only be applied to sequences, not single values. If you wish to apply a function to a single value/selection (including an array), use the do command. """ if len(arguments) > 0: # `func_wrap` only the last argument return ast.Map(*(arguments[:-1] + (ast.func_wrap(arguments[-1]),))) return ast.Map()
def max(*arguments): # pylint: disable=redefined-builtin """ Finds the maximum element of a sequence. """ return ast.Max(*[ast.func_wrap(arg) for arg in arguments])
def reduce(*arguments): """ Produce a single value from a sequence through repeated application of a reduction function. """ return ast.Reduce(*[ast.func_wrap(arg) for arg in arguments])