MCPcopy Index your code
hub / github.com/OpenTSDB/opentsdb / parseTsuidTypeSubQuery

Method parseTsuidTypeSubQuery

src/tsd/QueryRpc.java:697–743  ·  view source on GitHub ↗

Parses a "tsuid=..." type query and adds it to the TSQuery. This will generate a TSSubQuery and add it to the TSQuery if successful @param query_string The value of the m query string parameter, i.e. what comes after the equals sign @param data_query The query we're building @throws BadRequestExcept

(final String query_string, 
      TSQuery data_query)

Source from the content-addressed store, hash-verified

695 * missing components
696 */
697 private static void parseTsuidTypeSubQuery(final String query_string,
698 TSQuery data_query) {
699 if (query_string == null || query_string.isEmpty()) {
700 throw new BadRequestException("The tsuid query string was empty");
701 }
702
703 // tsuid queries are of the following forms:
704 // agg:[interval-agg:][rate:]tsuid[,s]
705 // where the parts in square brackets `[' .. `]' are optional.
706 final String[] parts = Tags.splitString(query_string, ':');
707 int i = parts.length;
708 if (i < 2 || i > 5) {
709 throw new BadRequestException("Invalid parameter m=" + query_string + " ("
710 + (i < 2 ? "not enough" : "too many") + " :-separated parts)");
711 }
712
713 final TSSubQuery sub_query = new TSSubQuery();
714
715 // the aggregator is first
716 sub_query.setAggregator(parts[0]);
717
718 i--; // Move to the last part (the metric name).
719 final List<String> tsuid_array = Arrays.asList(parts[i].split(","));
720 sub_query.setTsuids(tsuid_array);
721
722 // parse out the rate and downsampler
723 for (int x = 1; x < parts.length - 1; x++) {
724 if (parts[x].toLowerCase().startsWith("rate")) {
725 sub_query.setRate(true);
726 if (parts[x].indexOf("{") >= 0) {
727 sub_query.setRateOptions(QueryRpc.parseRateOptions(true, parts[x]));
728 }
729 } else if (Character.isDigit(parts[x].charAt(0))) {
730 sub_query.setDownsample(parts[x]);
731 } else if (parts[x].toLowerCase().startsWith("percentiles")) {
732 sub_query.setPercentiles(QueryRpc.parsePercentiles(parts[x]));
733 } else if (parts[x].toLowerCase().startsWith("show-histogram-buckets")) {
734 sub_query.setShowHistogramBuckets(true);
735 }
736 }
737
738 if (data_query.getQueries() == null) {
739 final ArrayList<TSSubQuery> subs = new ArrayList<TSSubQuery>(1);
740 data_query.setQueries(subs);
741 }
742 data_query.getQueries().add(sub_query);
743 }
744
745 /**
746 * Parses the "rate" section of the query string and returns an instance

Callers 1

parseQueryMethod · 0.95

Calls 15

splitStringMethod · 0.95
setAggregatorMethod · 0.95
setTsuidsMethod · 0.95
setRateMethod · 0.95
setRateOptionsMethod · 0.95
parseRateOptionsMethod · 0.95
setDownsampleMethod · 0.95
setPercentilesMethod · 0.95
parsePercentilesMethod · 0.95
isEmptyMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected