/** * @return greater byte array than given (row) which satisfies the fuzzy rule if it exists, * null otherwise */ private static byte[] getNextForFuzzyRule(byte[] row, int offset, int length, byte[] fuzzyKeyBytes, byte[] fuzzyKeyMeta) { // To find out the next "smallest" byte array that satisfies fuzzy rule and "greater" than // the given one we do the following: // 1. setting values on all "fixed" positions to the values from fuzzyKeyBytes // 2. if during the first step given row did not increase, then we increase the value at // the first "non-fixed" position (where it is not maximum already) // It is easier to perform this by using fuzzyKeyBytes copy and setting "non-fixed" position // values than otherwise. byte[] result = Arrays.copyOf(fuzzyKeyBytes, length > fuzzyKeyBytes.length ? length : fuzzyKeyBytes.length); int toInc = -1; boolean increased = false; for (int i = 0; i < result.length; i++) { if (i >= fuzzyKeyMeta.length || fuzzyKeyMeta[i] == 1) { result[i] = row[offset + i]; if (!isMax(row[i])) { // this is "non-fixed" position and is not at max value, hence we can increase it toInc = i; } } else if (i < fuzzyKeyMeta.length && fuzzyKeyMeta[i] == 0) { if ((row[i + offset] & 0xFF) < (fuzzyKeyBytes[i] & 0xFF)) { // if setting value for any fixed position increased the original array, // we are OK
/** * @return greater byte array than given (row) which satisfies the fuzzy rule if it exists, * null otherwise */ private static byte[] getNextForFuzzyRule(byte[] row, int offset, int length, byte[] fuzzyKeyBytes, byte[] fuzzyKeyMeta) { // To find out the next "smallest" byte array that satisfies fuzzy rule and "greater" than // the given one we do the following: // 1. setting values on all "fixed" positions to the values from fuzzyKeyBytes // 2. if during the first step given row did not increase, then we increase the value at // the first "non-fixed" position (where it is not maximum already) // It is easier to perform this by using fuzzyKeyBytes copy and setting "non-fixed" position // values than otherwise. byte[] result = Arrays.copyOf(fuzzyKeyBytes, length > fuzzyKeyBytes.length ? length : fuzzyKeyBytes.length); int toInc = -1; boolean increased = false; for (int i = 0; i < result.length; i++) { if (i >= fuzzyKeyMeta.length || fuzzyKeyMeta[i] == 1) { result[i] = row[offset + i]; if (!isMax(row[i])) { // this is "non-fixed" position and is not at max value, hence we can increase it toInc = i; } } else if (i < fuzzyKeyMeta.length && fuzzyKeyMeta[i] == 0) { if ((row[i + offset] & 0xFF) < (fuzzyKeyBytes[i] & 0xFF)) { // if setting value for any fixed position increased the original array, // we are OK
public byte[] getNextRowHint(byte[] rowKey) { byte[] nextRowKey = null; // Searching for the "smallest" row key that satisfies at least one fuzzy row key for (ImmutablePair<byte[], byte[]> fuzzyData : fuzzyKeysData) { byte[] nextRowKeyCandidate = getNextForFuzzyRule(rowKey, fuzzyData.getFirst(), fuzzyData.getSecond()); if (nextRowKeyCandidate == null) { continue; } if (nextRowKey == null || Bytes.compareTo(nextRowKeyCandidate, nextRowKey) < 0) { nextRowKey = nextRowKeyCandidate; } } if (nextRowKey == null) { // SHOULD NEVER happen // TODO: is there a better way than throw exception? (stop the scanner?) throw new IllegalStateException("No next row key that satisfies fuzzy exists when" + " getNextKeyHint() is invoked." + " Filter: " + this.toString() + " RowKey: " + Bytes.toStringBinary(rowKey)); } return nextRowKey; }
public byte[] getNextRowHint(byte[] rowKey) { byte[] nextRowKey = null; // Searching for the "smallest" row key that satisfies at least one fuzzy row key for (ImmutablePair<byte[], byte[]> fuzzyData : fuzzyKeysData) { byte[] nextRowKeyCandidate = getNextForFuzzyRule(rowKey, fuzzyData.getFirst(), fuzzyData.getSecond()); if (nextRowKeyCandidate == null) { continue; } if (nextRowKey == null || Bytes.compareTo(nextRowKeyCandidate, nextRowKey) < 0) { nextRowKey = nextRowKeyCandidate; } } if (nextRowKey == null) { // SHOULD NEVER happen // TODO: is there a better way than throw exception? (stop the scanner?) throw new IllegalStateException("No next row key that satisfies fuzzy exists when" + " getNextKeyHint() is invoked." + " Filter: " + this.toString() + " RowKey: " + Bytes.toStringBinary(rowKey)); } return nextRowKey; }