Skip to content

Expressions Reference

Fernando Gutierrez edited this page Jan 4, 2017 · 1 revision

scrunch.expressions

This module provides basic support for converting expression strings (defined in a python-like DSL) into crunch expression objects.

For example, the expression 'disposition == 0 or exit_status == 0' would be transformed by this module's parser into:

    {
        'function': 'or',
        'args': [
            {
                'function': '==',
                'args': [
                    {
                        'variable': 'disposition'
                    },
                    {
                        'value': 0
                    }
                ]
            },
            {
                'function': '==',
                'args': [
                    {
                        'variable': 'exit_status'
                    },
                    {
                        'value': 0
                    }
                ]
            }
        ]
    }

Its important to note that the expression objects produced by this module's parser are not ready for being sent to crunch, as they refer to variables by alias rather than by variable_id (which is a URL). So, this module also provides a process_expr function that creates an expression object ready for the crunch API.

Variables

scrunch.expressions.BINARY_FUNC_OPERATORS
scrunch.expressions.BUILTIN_FUNCTIONS
scrunch.expressions.COMPARISSON_FUNCS
scrunch.expressions.COMPARISSON_OPERATORS
scrunch.expressions.CRUNCH_FUNC_MAP
scrunch.expressions.CRUNCH_METHOD_MAP
scrunch.expressions.NOT_IN

Functions

scrunch.expressions.get_dataset_variables(ds)
scrunch.expressions.parse_expr(expr)
scrunch.expressions.prettify(expr, ds=None)

Translate the crunch expression dictionary to the string representation.

  • :param expr: crunch expression
  • :param ds: dataset instance
  • :return: string representation of the expression
scrunch.expressions.process_expr(obj, ds)

Given a Crunch expression object (or objects) and a Dataset entity object (i.e. a Shoji entity), this function returns a new expression object (or a list of new expression objects) with all variable aliases transformed into variable URLs, just as the crunch API needs them to be.

scrunch.expressions.r(lower, upper)
scrunch.expressions.unfold_list(_list)