Beispiel #1
0
 def check_type(old_type, new_type):
     if new_type == old_type:
         return old_type
     elif new_type == u.String():
         if must_be_number:
             raise exception.BananaTypeError(expected_type=u.Number,
                                             found_type=new_type)
         if old_type is None:
             return new_type
         elif u.can_to_str(old_type):
             return new_type
         else:
             raise exception.BananaTypeError(expected_type=old_type,
                                             found_type=new_type)
     elif new_type == u.Number():
         if old_type is None:
             return new_type
         elif old_type == u.String():
             return old_type
         elif not old_type == u.Number():
             raise exception.BananaTypeError(expected_type=old_type,
                                             found_type=new_type)
     else:
         raise exception.BananaTypeError(expected_type=old_type,
                                         found_type=new_type)
 def get_params():
     return [
         params.ParamDescriptor('host', type_util.String(), 'localhost'),
         params.ParamDescriptor('port', type_util.Number(), 9092),
         params.ParamDescriptor('topic', type_util.String(),
                                'transformed_alerts')
     ]
Beispiel #3
0
 def get_params():
     return [
         params.ParamDescriptor('zk_host', type_util.String(), 'localhost'),
         params.ParamDescriptor('zk_port', type_util.Number(), 2181),
         params.ParamDescriptor('group_id', type_util.String(),
                                'my_group_id'),
         params.ParamDescriptor('topics',
                                type_util.Object(strict_checking=False))
     ]
Beispiel #4
0
 def get_params():
     return [
         params.ParamDescriptor('metric', type_util.String(),
                                'cpu.logcal_cores_actives'),
         params.ParamDescriptor('period', type_util.Number(), 1),
         params.ParamDescriptor('lambda', type_util.String(), 'a * b'),
         params.ParamDescriptor('bindings', type_util.Any(), {
             'a': 'cpu.ilde_perc',
             'b': 'cpu.total_logical_cores'
         })
     ]
Beispiel #5
0
def typeck_rhs(ast_value, type_table):
    """
    Type-check the provided ast value. And returns its type.
    This function does not support assignment,
    :type ast_value: ast.ASTNode
    :param ast_value: The ast_value to type check.
    :type type_table: typetbl.TypeTable
    :param type_table: The type table. Used for type lookup.
    :rtype: u.Component | u.Object | u.Number | u.String
    :return: Returns the computed type.
    """
    if isinstance(ast_value, ast.Number):
        return u.Number()
    if isinstance(ast_value, ast.StringLit):
        return u.String()
    if isinstance(ast_value, ast.Ident):
        return type_table.get_type(ast_value)
    if isinstance(ast_value, ast.DotPath):
        return type_table.get_type(ast_value)
    if isinstance(ast_value, ast.Expr):
        return typeck_expr(ast_value, type_table)
    if isinstance(ast_value, ast.JsonObj):
        return typeck_jsonobj(ast_value, type_table)
    if isinstance(ast_value, ast.Component):
        return typeck_component(ast_value, type_table)
    raise Exception("Unhandled ast value type {}!!".format(ast_value))
 def get_params():
     return [
         params.ParamDescriptor(
             "db_name",
             type_util.String(),
             "sqlite_sink.db"
         )
     ]
 def get_params():
     return [
         params.ParamDescriptor('host', type_util.String(), 'localhost'),
         params.ParamDescriptor('port', type_util.Number(), 1010),
         params.ParamDescriptor(
             'model',
             type_util.Object({
                 'name':
                 type_util.String(),
                 'params':
                 type_util.Object({
                     'origin_types':
                     type_util.Object(strict_checking=False)
                 })
             })),
         params.ParamDescriptor('alert_per_burst', type_util.Number(), 1),
         params.ParamDescriptor('idle_time_between_bursts',
                                type_util.Number(), 1.0),
     ]
Beispiel #8
0
 def allowed_symbol(current_type):
     if current_type == u.String():
         return ['+']
     else:
         return ['+', '-', '*', '/']
Beispiel #9
0
def typeck_expr(expr, type_table):
    """
    Type-check the given expression. If the typecheck
    pass, the resulting type will be used for the strategy
    to use when evaluating this expression.
    :type expr: ast.Expr
    :param expr: The expression to typecheck.
    :type type_table: typetbl.TypeTable
    :param type_table: Type of the table
    :rtype: u.Number | u.String
    :return: Returns the type of the expression if possible
    :raise: Raise an exception
    """
    # In the case where we are just wrapping around
    # only one expression, the logic below
    # needs to be skipped.
    if len(expr.expr_tree) == 1:
        return typeck_rhs(expr.expr_tree[0], type_table)

    _type = None
    must_be_number = False

    def check_type(old_type, new_type):
        if new_type == old_type:
            return old_type
        elif new_type == u.String():
            if must_be_number:
                raise exception.BananaTypeError(expected_type=u.Number,
                                                found_type=new_type)
            if old_type is None:
                return new_type
            elif u.can_to_str(old_type):
                return new_type
            else:
                raise exception.BananaTypeError(expected_type=old_type,
                                                found_type=new_type)
        elif new_type == u.Number():
            if old_type is None:
                return new_type
            elif old_type == u.String():
                return old_type
            elif not old_type == u.Number():
                raise exception.BananaTypeError(expected_type=old_type,
                                                found_type=new_type)
        else:
            raise exception.BananaTypeError(expected_type=old_type,
                                            found_type=new_type)

    def allowed_symbol(current_type):
        if current_type == u.String():
            return ['+']
        else:
            return ['+', '-', '*', '/']

    for el in expr.expr_tree:
        if isinstance(el, ast.StringLit):
            _type = check_type(_type, u.String())
        elif isinstance(el, ast.Number):
            _type = check_type(_type, u.Number())
        elif isinstance(el, ast.Ident):
            ident_type = type_table.get_type(el)
            _type = check_type(_type, ident_type)
        elif isinstance(el, ast.DotPath):
            dotpath_type = type_table.get_type(el)
            _type = check_type(_type, dotpath_type)
        elif isinstance(el, ast.Expr):
            _type = check_type(_type, typeck_expr(el, type_table))
        elif isinstance(el, basestring):
            if el not in allowed_symbol(_type):
                raise exception.BananaUnknownOperator(expr.span, el, _type)
            if el in ['-', '*', '/']:
                must_be_number = True
        else:
            raise exception.BananaTypeError(expected_type=[
                u.Number.__name__, u.String.__name__, u.Object.__name__
            ], )

    # The final type if we made until here!
    return _type
 def get_params():
     return [
         params.ParamDescriptor('db_name', type_util.String(),
                                'sqlite_sink.db')
     ]
 def get_params():
     return [params.ParamDescriptor('path', type_util.String())]