def _get_parent_branch_series(self, query, limit=LOADER_LIMIT, offset=0): """Iterate through parent branches, find cached series for parent branch and return series matching query""" root_branch_query = False _pattern = ".".join(query.pattern.split('.')[:-1]) if not _pattern: _pattern = '*' root_branch_query = True parent_branch_series = self.get_all_cached_series( _pattern, limit=limit, offset=offset) while not parent_branch_series and not root_branch_query: logger.debug("No cached series list for parent branch query %s, " "continuing with more parents", _pattern) _pattern = ".".join(_pattern.split('.')[:-1]) if not _pattern: _pattern = '*' root_branch_query = True parent_branch_series = self.get_all_cached_series( _pattern, limit=limit, offset=offset) if not parent_branch_series: return logger.debug("Found cached parent branch series for parent query %s " "limit %s offset %s", _pattern, limit, offset) series = match_entries(parent_branch_series, query.pattern) \ if is_pattern(query.pattern) \ else [b for b in parent_branch_series if b.startswith(query.pattern)] return series
def search(self, node, split_query, split_path): """Return matching children for each query part in split query starting from given node""" sub_query = split_query[0] keys = [_decode_str(key) for (key, _) in node.children] \ if node.children is not None else [] matched_paths = match_entries(keys, sub_query) matched_children = ( (_decode_str(path), _node) for (path, _node) in node.children if _decode_str(path) in matched_paths) \ if node.children is not None and is_pattern(sub_query) \ else [(sub_query, [n for (k, n) in node.children if _decode_str(k) == sub_query][0])] \ if node.children is not None \ and sub_query in keys else [] for child_name, child_node in matched_children: child_path = split_path[:] child_path.append(child_name) child_query = split_query[1:] if len(child_query) > 0: for sub in self.search(child_node, child_query, child_path): yield sub else: yield (child_path, child_node)
def make_regex_string(self, query): """Make InfluxDB regex strings from Graphite wildcard queries""" if not is_pattern(query.pattern): return "^%s" % (query.pattern,) if query.pattern == '*': return pat = "^%s" % (query.pattern.replace('.', r'\.').replace( '*', '([a-zA-Z0-9-_:#]+(\.)?)+').replace( '{', '(').replace(',', '|').replace('}', ')')) if not self.is_suffix_pattern(query.pattern): return "%s$" % (pat) return pat
def _get_matched_children(self, sub_query, node): keys = [_decode_str(key) for (key, _) in node.children] \ if node.children is not None else [] matched_paths = match_entries(keys, sub_query) if node.children is not None and is_pattern(sub_query): matched_children = self._get_children_from_matched_paths( matched_paths, node) else: matched_children = [(sub_query, self._get_child_from_string_query( sub_query, node))] \ if node.children is not None \ and sub_query in keys else [] return matched_children
def make_regex_string(self, query): """Make InfluxDB regex strings from Graphite wildcard queries""" if not is_pattern(query.pattern): return "^%s" % (query.pattern,) if query.pattern == "*": return pat = "^%s" % ( query.pattern.replace(".", r"\.") .replace("*", "([a-zA-Z0-9-_:#]+(\.)?)+") .replace("{", "(") .replace(",", "|") .replace("}", ")") ) if not self.is_suffix_pattern(query.pattern): return "%s$" % (pat) return pat