Constructs a row key regular expression to pass to HBase if the user gave some tags in the query @return The regular expression to use.
()
| 439 | * @return The regular expression to use. |
| 440 | */ |
| 441 | private String getRowKeyRegex() { |
| 442 | final StringBuilder tagv_buffer = new StringBuilder(); |
| 443 | // remember, tagks are sorted in the row key so we need to supply a sorted |
| 444 | // regex or matching will fail. |
| 445 | Collections.sort(pairs); |
| 446 | |
| 447 | final short name_width = TSDB.tagk_width(); |
| 448 | final short value_width = TSDB.tagv_width(); |
| 449 | final short tagsize = (short) (name_width + value_width); |
| 450 | |
| 451 | int index = 0; |
| 452 | final StringBuilder buf = new StringBuilder( |
| 453 | 22 // "^.{N}" + "(?:.{M})*" + "$" + wiggle |
| 454 | + ((13 + tagsize) // "(?:.{M})*\\Q" + tagsize bytes + "\\E" |
| 455 | * (pairs.size()))); |
| 456 | buf.append("(?s)^.{").append(query.useMeta() ? TSDB.metrics_width() : |
| 457 | TSDB.metrics_width() + Const.SALT_WIDTH()) |
| 458 | .append("}"); |
| 459 | if (!query.useMeta()) { |
| 460 | buf.append("(?:.{").append(Const.TIMESTAMP_BYTES).append("})*"); |
| 461 | } |
| 462 | buf.append("(?:.{").append(tagsize).append("})*"); |
| 463 | |
| 464 | // at the top of the list will be the null=tagv pairs. We want to compile |
| 465 | // a separate regex for them. |
| 466 | for (; index < pairs.size(); index++) { |
| 467 | if (pairs.get(index).getKey() != null) { |
| 468 | break; |
| 469 | } |
| 470 | |
| 471 | if (index > 0) { |
| 472 | buf.append("|"); |
| 473 | } |
| 474 | buf.append("(?:.{").append(name_width).append("})"); |
| 475 | buf.append("\\Q"); |
| 476 | QueryUtil.addId(buf, pairs.get(index).getValue(), true); |
| 477 | } |
| 478 | buf.append("(?:.{").append(tagsize).append("})*") |
| 479 | .append("$"); |
| 480 | |
| 481 | if (index > 0 && index < pairs.size()) { |
| 482 | // we had one or more tagvs to lookup AND we have tagk or tag pairs to |
| 483 | // filter on, so we dump the previous regex into the tagv_filter and |
| 484 | // continue on with a row key |
| 485 | tagv_buffer.append(buf.toString()); |
| 486 | LOG.debug("Setting tagv filter: " + QueryUtil.byteRegexToString(buf.toString())); |
| 487 | } else if (index >= pairs.size()) { |
| 488 | // in this case we don't have any tagks to deal with so we can just |
| 489 | // pass the previously compiled regex to the rowkey filter of the |
| 490 | // scanner |
| 491 | LOG.debug("Setting scanner row key filter with tagvs only: " + |
| 492 | QueryUtil.byteRegexToString(buf.toString())); |
| 493 | if (tagv_buffer.length() > 0) { |
| 494 | tagv_filter = tagv_buffer.toString(); |
| 495 | } |
| 496 | return buf.toString(); |
| 497 | } |
| 498 |
no test coverage detected