public static String getRowKeyTSUIDRegex ( final List < String > tsuids ) { Collections . sort ( tsuids ) ; // first, convert the tags to byte arrays and count up the total length // so we can allocate the string builder final short metric_width = TSDB . metrics_width ( ) ; int tags_length = 0 ; final ArrayList < byte [ ] > uids = new ArrayList < byte [ ] > ( tsuids . size ( ) ) ; for ( final String tsuid : tsuids ) { final String tags = tsuid . substring ( metric_width * 2 ) ; final byte [ ] tag_bytes = UniqueId . stringToUid ( tags ) ; tags_length += tag_bytes . length ; uids . add ( tag_bytes ) ; } // Generate a regexp for our tags based on any metric and timestamp (since // those are handled by the row start/stop) and the list of TSUID tagk/v // pairs. The generated regex will look like: ^.{7}(tags|tags|tags)$ // where each "tags" is similar to \\Q\000\000\001\000\000\002\\E final StringBuilder buf = new StringBuilder ( 13 // "(?s)^.{N}(" + ")$" + ( tsuids . size ( ) * 11 ) // "\\Q" + "\\E|" + tags_length ) ; // total # of bytes in tsuids tagk/v pairs // Alright, let's build this regexp. From the beginning... buf . append ( "(?s)" // Ensure we use the DOTALL flag. + "^.{" ) // ... start by skipping the metric ID and timestamp. . append ( Const . SALT_WIDTH ( ) + metric_width + Const . TIMESTAMP_BYTES ) . append ( "}(" ) ; for ( final byte [ ] tags : uids ) { // quote the bytes buf . append ( "\\Q" ) ; addId ( buf , tags , true ) ; buf . append ( ' ' ) ; } // Replace the pipe of the last iteration, close and set buf . setCharAt ( buf . length ( ) - 1 , ' ' ) ; buf . append ( "$" ) ; return buf . toString ( ) ; }
Creates a regular expression with a list of or d TUIDs to compare against the rows in storage .