Beispiel #1
0
def get_timeunit(t):
    if not time_units.match(t):
        raise qg.QueryException("Invalid timeunit: %s" % t)
    if t.startswith('d'): return 'days'
    elif t.startswith('h'): return 'hours'
    elif t.startswith('m'): return 'minutes'
    elif t.startswith('s'): return 'seconds'
Beispiel #2
0
def build_setstring(setvals, wherevals):
    #  set tags
    regex = None
    for stmt in wherevals:
        if stmt.op == ast.Statement.OP_REGEX:
            if regex == None:
                regex = stmt
            else:
                raise qg.QueryException(
                    "Too many regexes in set.  Only one supported!")

    if regex == None:
        new_tags = ' || '.join(
            map(
                lambda (t, v): "hstore(%s, %s)" %
                (escape_string(t), escape_string(v)), setvals))
    else:
        new_tags = ' || '.join(
            map(
                lambda (t, v):
                "hstore(%s, regexp_replace(metadata -> %s, '^.*%s.*$', %s))" %
                (escape_string(t), regex.args[0], regex.args[1][1:-1].replace(
                    '\\\\', '\\'), escape_string(v).replace('\\\\', '\\')),
                setvals))
    return new_tags
Beispiel #3
0
def lookup_operator_by_name(name, args, kwargs):
    """Lookup an operator by name and return a closure which will
    instantiate the operator with the given args and kwargs"""
    if not name in installed_ops:
        raise qg.QueryException("No such operator: " + name)
    if len(args) == 0 and len(kwargs) == 0:
        # if the op doesn't take any args, just return the bare operator
        return installed_ops[name]
    else:
        for proto in installed_ops[name].operator_constructors:
            if len(proto) != len(args): continue
            try:
                alist = map(lambda (fn, a): fn(a), zip(proto, args))
                kwargs_ = kwargs
            except ValueError:
                continue

            return lambda inputs: installed_ops[name](inputs, *alist, **kwargs_)
        raise qg.QueryException("No valid constructor for operator %s: %s" % 
                                (name, str(args)))
Beispiel #4
0
def p_error(t):
    raise qg.QueryException("Syntax error at '%s'" % t.value, 400)