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_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
def __init__(self, tree: Node): for element in tree.get_children(): if element.get_type() == TK.TOK_TABLE_NAME: (self._index, self._type) = parse_tok_table_name(element) if element.get_type() == TK.TOK_SET_COLUMNS_CLAUSE: self.update_sets = parse_update_sets(element) if element.get_type() == TK.TOK_WHERE: self.conditions = parse_conditions(element)
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 parse_tok_sorts(tree: Node): sorts = {} for sort in tree.get_children(): if sort.get_type() == TK.TOK_SORT: order = 'asc' if sort.get_children_count() == 2: order = sort.get_child(1).get_value() sorts[sort.get_child(0).get_value()] = {'order': order} return sorts
def __init__(self, tree: Node): self.insert_columns = [] self.bulk_rows = [] for element in tree.get_children(): if element.get_type() == TK.TOK_TABLE_NAME: (self._index, self._type) = parse_tok_table_name(element) elif element.get_type() == TK.TOK_INSERT_COLUMNS: self.insert_columns = parse_insert_columns(element) elif element.get_type() == TK.TOK_INSERT_ROWS: self.bulk_rows = parse_bulk_rows(element)
def __init__(self, tree: Node): self.insert_columns = [] self.insert_row = [] self.metas = {} for element in tree.get_children(): if element.get_type() == TK.TOK_TABLE_NAME: (self._index, self._type) = parse_tok_table_name(element) elif element.get_type() == TK.TOK_INSERT_COLUMNS: self.insert_columns = parse_insert_columns(element) elif element.get_type() == TK.TOK_INSERT_ROW: self.insert_row = parse_insert_row(element) for i in range(0, len(self.insert_columns)): if self.insert_columns[i] in [ '_id', '_parent', '_routing', '_type' ]: self.metas[self.insert_columns[i][1:]] = self.insert_row[i]
def __init__(self, tree: Node): for element in tree.get_children(): if element.get_type() == TK.TOK_TABLE_NAME: (self._index, self._type) = parse_tok_table_name(element) if element.get_type() == TK.TOK_WHERE: self.conditions = QueryBody(element.get_child(0))
def __init__(self, tree: Node, _size, root=True): self.buckets = [] for element in tree.get_children(): self.buckets.append(bucket(element, _size))
def __init__(self, tree: Node): for element in tree.get_children(): if element.get_type() == TK.TOK_TABLE_NAME: (self._index, self._type) = parse_tok_table_name(element)
def parse_update_sets(tree: Node): retval = {} for e in tree.get_children(): retval.update(parse_kv(e)) return retval
def parse_bulk_rows(tree: Node): retval = [] for e in tree.get_children(): retval.append(parse_insert_row(e)) return retval
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
def __init__(self, tree: Node): self.function_name = tree.get_value() self.function_parms = tree.get_children()
def parse_tok_selexpr(tree: Node): retval = [] for e in tree.get_children(): retval.append(Selexpr(e)) return retval