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))
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))
def __init__(self, tree: Node): #do query for element in tree.get_children(): if element.get_type() == TK.TOK_FROM: (self._index, self._type) = parse_tok_table_name(element.get_child(0)) if element.get_children_count() == 2: self.route = parse_value(element.get_child(1)) if element.get_type() == TK.TOK_SELECT: self.selexpr = parse_tok_selexpr(element) if element.get_type() == TK.TOK_WHERE: self.query_body = QueryBody(element.get_child(0)) if element.get_type() == TK.TOK_LIMIT: (self._from, self._size) = parse_tok_limit(element) if element.get_type() == TK.TOK_ORDERBY: self.sorts = parse_tok_sorts(element) #do aggregations for element in tree.get_children(): if element.get_type() == TK.TOK_GROUPBY: agg_size = -1 if hasattr(self, '_size'): agg_size = self._size self.groupby = AggBuckets(element, agg_size)
def parse_insert_row(tree: Node): retval = [] for e in tree.get_children(): if e.get_type() == TK.TOK_VALUE: retval.append(parse_value(e)) elif e.get_type() in (TK.TOK_DICT, TK.TOK_LIST): retval.append(parse_object(e)) return retval
def bucket_field(tree: Node, _size): bucket = {} bucket['terms'] = {} field = parse_value(tree) bucket['terms']['field'] = field if _size != -1: bucket['terms']['size'] = _size aggs = {"aggs": {}} aggs['aggs'][field] = bucket return (field, aggs)
def parse_insert_columns(tree: Node): retval = [] for e in tree.get_children(): if e.get_type() == TK.TOK_VALUE: retval.append(parse_value(e)) return retval