Example #1
0
def parse_table_name(tree: Node):
    if tree.get_type() == TK.TOK_DOT:
        _index = parse_value(tree.get_child(0))
        _type = parse_value(tree.get_child(1))
    elif tree.get_type() == TK.TOK_VALUE:
        _index = tree.get_value()
        _type = 'base'
    return (_index,_type)
Example #2
0
def parse_value(tree: Node) -> str:
    if tree.get_type() == TK.TOK_DOT:
        retval = parse_value(tree.get_child(0))
        retval += '.'
        retval += parse_value(tree.get_child(1))
        return retval
    elif tree.get_type() == TK.TOK_VALUE:
        return tree.get_value()
    else:
        pass
Example #3
0
def parse_object(tree: Node):
    retval = None
    if tree.get_type() == TK.TOK_DICT:
        retval = {}
        for element in tree.get_children():
            retval.update(parse_kv(element))
    if tree.get_type() == TK.TOK_LIST:
        retval = []
        for element in tree.get_children():
            if element.get_type() in (TK.TOK_DICT,TK.TOK_LIST):
                retval.append(parse_object(element))
            else:
                retval.append(parse_value(element))
    return retval
Example #4
0
    def __init__(self, tree: Node, root=True):

        if tree.get_type() == TK.TOK_REVERSED:
            tree = tree.get_child(0)
            self.reversed = True

        self.root = root
        self.combine = 'must'
        if tree.get_type() == TK.TOK_COMPOUND:
            self.combine = tree.get_value()
            self.lchild = QueryBody(tree.get_child(0), False)
            self.rchild = QueryBody(tree.get_child(1), False)
        else:
            self.lchild = query_expression(tree)
Example #5
0
def parse_kv(tree: Node):
    right=None
    left=None
    if tree.get_type() == TK.TOK_KEY_VALUE:
        left = parse_value(tree.get_child(0).get_child(0))
        if tree.get_child(1).get_child(0).get_type() in (TK.TOK_DICT,TK.TOK_LIST):
            right = parse_object(tree.get_child(1).get_child(0))
        else:
            right = parse_value(tree.get_child(1).get_child(0))
    else:
        pass
    return {left:right}
Example #6
0
def parse_tok_table_name(tree : Node):
    if tree.get_type() == TK.TOK_TABLE_NAME:
        return  parse_table_name(tree.get_child(0))
    else:
        pass
Example #7
0
def bucket(tree: Node, _size):
    if tree.get_type() == TK.TOK_FUNCTION:
        return bucket_function(tree, _size)
    else:
        return bucket_field(tree, _size)
Example #8
0
def query_expression(tree: Node):
    if tree.get_type() == TK.TOK_COMPARE:
        return CompareExpression(tree)
    if tree.get_type() == TK.TOK_FUNCTION:
        return FunctionExpression(tree)