MCPcopy
hub / github.com/OpenTSDB/opentsdb / getRowKeyTSUIDRegex

Method getRowKeyTSUIDRegex

src/query/QueryUtil.java:502–544  ·  view source on GitHub ↗

Creates a regular expression with a list of or'd TUIDs to compare against the rows in storage. @param tsuids The list of TSUIDs to scan for @return A regular expression string to pass to the storage layer.

(final List<String> tsuids)

Source from the content-addressed store, hash-verified

500 * @return A regular expression string to pass to the storage layer.
501 */
502 public static String getRowKeyTSUIDRegex(final List<String> tsuids) {
503 Collections.sort(tsuids);
504
505 // first, convert the tags to byte arrays and count up the total length
506 // so we can allocate the string builder
507 final short metric_width = TSDB.metrics_width();
508 int tags_length = 0;
509 final ArrayList<byte[]> uids = new ArrayList<byte[]>(tsuids.size());
510 for (final String tsuid : tsuids) {
511 final String tags = tsuid.substring(metric_width * 2);
512 final byte[] tag_bytes = UniqueId.stringToUid(tags);
513 tags_length += tag_bytes.length;
514 uids.add(tag_bytes);
515 }
516
517 // Generate a regexp for our tags based on any metric and timestamp (since
518 // those are handled by the row start/stop) and the list of TSUID tagk/v
519 // pairs. The generated regex will look like: ^.{7}(tags|tags|tags)$
520 // where each "tags" is similar to \\Q\000\000\001\000\000\002\\E
521 final StringBuilder buf = new StringBuilder(
522 13 // "(?s)^.{N}(" + ")$"
523 + (tsuids.size() * 11) // "\\Q" + "\\E|"
524 + tags_length); // total # of bytes in tsuids tagk/v pairs
525
526 // Alright, let's build this regexp. From the beginning...
527 buf.append("(?s)" // Ensure we use the DOTALL flag.
528 + "^.{")
529 // ... start by skipping the metric ID and timestamp.
530 .append(Const.SALT_WIDTH() + metric_width + Const.TIMESTAMP_BYTES)
531 .append("}(");
532
533 for (final byte[] tags : uids) {
534 // quote the bytes
535 buf.append("\\Q");
536 addId(buf, tags, true);
537 buf.append('|');
538 }
539
540 // Replace the pipe of the last iteration, close and set
541 buf.setCharAt(buf.length() - 1, ')');
542 buf.append("$");
543 return buf.toString();
544 }
545
546 /**
547 * Compiles an HBase scanner against the main data table

Callers 1

Calls 8

metrics_widthMethod · 0.95
stringToUidMethod · 0.95
SALT_WIDTHMethod · 0.95
addIdMethod · 0.95
sizeMethod · 0.65
addMethod · 0.45
appendMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected