Parses a query string "m=..." 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 BadRequ
(final String query_string,
TSQuery data_query)
| 632 | * missing components |
| 633 | */ |
| 634 | private static void parseMTypeSubQuery(final String query_string, |
| 635 | TSQuery data_query) { |
| 636 | if (query_string == null || query_string.isEmpty()) { |
| 637 | throw new BadRequestException("The query string was empty"); |
| 638 | } |
| 639 | |
| 640 | // m is of the following forms: |
| 641 | // agg:[interval-agg:][rate:]metric[{tag=value,...}] |
| 642 | // where the parts in square brackets `[' .. `]' are optional. |
| 643 | final String[] parts = Tags.splitString(query_string, ':'); |
| 644 | int i = parts.length; |
| 645 | if (i < 2 || i > 5) { |
| 646 | throw new BadRequestException("Invalid parameter m=" + query_string + " (" |
| 647 | + (i < 2 ? "not enough" : "too many") + " :-separated parts)"); |
| 648 | } |
| 649 | final TSSubQuery sub_query = new TSSubQuery(); |
| 650 | |
| 651 | // the aggregator is first |
| 652 | sub_query.setAggregator(parts[0]); |
| 653 | |
| 654 | i--; // Move to the last part (the metric name). |
| 655 | List<TagVFilter> filters = new ArrayList<TagVFilter>(); |
| 656 | sub_query.setMetric(Tags.parseWithMetricAndFilters(parts[i], filters)); |
| 657 | sub_query.setFilters(filters); |
| 658 | |
| 659 | // parse out the rate and downsampler |
| 660 | for (int x = 1; x < parts.length - 1; x++) { |
| 661 | if (parts[x].toLowerCase().startsWith("rate")) { |
| 662 | sub_query.setRate(true); |
| 663 | if (parts[x].indexOf("{") >= 0) { |
| 664 | sub_query.setRateOptions(QueryRpc.parseRateOptions(true, parts[x])); |
| 665 | } |
| 666 | } else if (Character.isDigit(parts[x].charAt(0))) { |
| 667 | sub_query.setDownsample(parts[x]); |
| 668 | } else if (parts[x].equalsIgnoreCase("pre-agg")) { |
| 669 | sub_query.setPreAggregate(true); |
| 670 | } else if (parts[x].toLowerCase().startsWith("rollup_")) { |
| 671 | sub_query.setRollupUsage(parts[x]); |
| 672 | } else if (parts[x].toLowerCase().startsWith("percentiles")) { |
| 673 | sub_query.setPercentiles(QueryRpc.parsePercentiles(parts[x])); |
| 674 | } else if (parts[x].toLowerCase().startsWith("show-histogram-buckets")) { |
| 675 | sub_query.setShowHistogramBuckets(true); |
| 676 | } else if (parts[x].toLowerCase().startsWith("explicit_tags")) { |
| 677 | sub_query.setExplicitTags(true); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | if (data_query.getQueries() == null) { |
| 682 | final ArrayList<TSSubQuery> subs = new ArrayList<TSSubQuery>(1); |
| 683 | data_query.setQueries(subs); |
| 684 | } |
| 685 | data_query.getQueries().add(sub_query); |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * Parses a "tsuid=..." type query and adds it to the TSQuery. |
no test coverage detected