Beispiel #1
0
 def __init__(self, tree: Node):
     self.compare = tree.get_value().lower()
     if tree.get_child(0).get_type() == TK.TOK_EXPRESSION_LEFT:
         self.left_values = parse_left_values(
             tree.get_child(0).get_children())
     if tree.get_child(1).get_type() == TK.TOK_EXPRESSION_RIGHT:
         self.right_value = parse_value(tree.get_child(1).get_child(0))
Beispiel #2
0
 def __init__(self, tree: Node):
     if tree.get_child(0).get_type() == TK.TOK_FUNCTION:
         self.selexpr = FunctionXpr(tree.get_child(0))
     else:
         self.selexpr = parse_value(tree.get_child(0))
     if tree.get_children_count() == 2:
         self.alias = parse_value(tree.get_child(1))
Beispiel #3
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)
Beispiel #4
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
Beispiel #5
0
def parse_tok_limit(tree: Node):
    _from = 0
    _size = 0

    if tree.get_children_count() == 2:
        _from = tree.get_child(0).get_value()
        _size = tree.get_child(1).get_value()
    else:
        _from = 0
        _size = tree.get_child(0).get_value()
    return (_from, _size)
Beispiel #6
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}
Beispiel #7
0
def bucket_function(tree: Node, _size):
    bucket = {}
    bucket[tree.get_value()] = {}
    for i in range(0, tree.get_children_count()):
        if tree.get_child(i).get_type() == TK.TOK_DICT:
            bucket[tree.get_value()].update(parse_object(tree.get_child(i)))
    if _size != -1:
        bucket[tree.get_value()]['size'] = _size
    aggs = {"aggs": {}}
    field = bucket[tree.get_value()]['field']
    aggs['aggs'][field] = bucket
    return (field, aggs)
Beispiel #8
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)
Beispiel #9
0
    def __init__(self, tree: Node):

        exec_node = tree.get_child(0)

        stmt = None
        self.dsl_body = {}
        self.curl_str = ''

        es_url = 'http://localhost:9200/'

        if exec_node.get_type() == TK.TOK_QUERY:
            stmt = Query(exec_node)
            self.curl_str = 'curl -XPOST ' + es_url + stmt._index + '/' + stmt._type + '/_search'
            self.dsl_body = stmt.dsl()
Beispiel #10
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
Beispiel #11
0
def parse_conditions(tree: Node):
    query_body = QueryBody(tree.get_child(0))
    condition = {}
    query_body_travel(query_body, condition)
    return condition
Beispiel #12
0
def parse_tok_value(tree: Node):
    if tree.children != None:
        if tree.get_child(0).get_type() == TK.TOK_DQ_VALUE:
            return '"' + tree.get_value() + '"'
    return tree.get_value()