/** * Returns mapping of all that match the given keySet provided they pass the combinedFilter predicate * for default COLUMN * * @param keySet row key set * @param typeOfT the type of the result * @param limit limit number of result * @param combinedFilter filter for key * @return map of row key to result */ public <T> Map<MDSKey, T> listKV(Set<MDSKey> keySet, Type typeOfT, int limit, @Nullable Predicate<KeyValue<T>> combinedFilter) { // Sort fuzzy keys List<MDSKey> sortedKeys = Lists.newArrayList(keySet); Collections.sort(sortedKeys); // Scan using fuzzy filter byte[] startKey = sortedKeys.get(0).getKey(); byte[] stopKey = Bytes.stopKeyForPrefix(sortedKeys.get(sortedKeys.size() - 1).getKey()); List<ImmutablePair<byte [], byte []>> fuzzyKeys = new ArrayList<>(); for (MDSKey key : sortedKeys) { fuzzyKeys.add(getFuzzyKeyFor(key)); } Scan scan = new Scan(startKey, stopKey, new FuzzyRowFilter(fuzzyKeys)); return listCombinedFilterKV(scan, typeOfT, limit, combinedFilter); }
/** * Returns mapping of all that match the given keySet provided they pass the combinedFilter predicate * for default COLUMN * * @param keySet row key set * @param typeOfT the type of the result * @param limit limit number of result * @param combinedFilter filter for key * @return map of row key to result */ public <T> Map<MDSKey, T> listKV(Set<MDSKey> keySet, Type typeOfT, int limit, @Nullable Predicate<KeyValue<T>> combinedFilter) { // Sort fuzzy keys List<MDSKey> sortedKeys = Lists.newArrayList(keySet); Collections.sort(sortedKeys); // Scan using fuzzy filter byte[] startKey = sortedKeys.get(0).getKey(); byte[] stopKey = Bytes.stopKeyForPrefix(sortedKeys.get(sortedKeys.size() - 1).getKey()); List<ImmutablePair<byte [], byte []>> fuzzyKeys = new ArrayList<>(); for (MDSKey key : sortedKeys) { fuzzyKeys.add(getFuzzyKeyFor(key)); } Scan scan = new Scan(startKey, stopKey, new FuzzyRowFilter(fuzzyKeys)); return listCombinedFilterKV(scan, typeOfT, limit, combinedFilter); }
private FuzzyRowFilter createFuzzyRowFilter(FactScan scan, byte[] startRow) { // we need to always use a fuzzy row filter as it is the only one to do the matching of values // if we are querying only one measure, we will use fixed measureName for filter, // if there are no measures or more than one measures to query we use `ANY` fuzzy filter. String measureName = (scan.getMeasureNames().size() == 1) ? scan.getMeasureNames().iterator().next() : null; byte[] fuzzyRowMask = codec.createFuzzyRowMask(scan.getDimensionValues(), measureName); // note: we can use startRow, as it will contain all "fixed" parts of the key needed return new FuzzyRowFilter(ImmutableList.of(new ImmutablePair<>(startRow, fuzzyRowMask))); }
private FuzzyRowFilter createFuzzyRowFilter(FactScan scan, byte[] startRow) { // we need to always use a fuzzy row filter as it is the only one to do the matching of values // if we are querying only one measure, we will use fixed measureName for filter, // if there are no measures or more than one measures to query we use `ANY` fuzzy filter. String measureName = (scan.getMeasureNames().size() == 1) ? scan.getMeasureNames().iterator().next() : null; byte[] fuzzyRowMask = codec.createFuzzyRowMask(scan.getDimensionValues(), measureName); // note: we can use startRow, as it will contain all "fixed" parts of the key needed return new FuzzyRowFilter(ImmutableList.of(new ImmutablePair<>(startRow, fuzzyRowMask))); }
private FuzzyRowFilter createFuzzyRowFilter(FactScan scan, List<String> measureNames) { List<ImmutablePair<byte[], byte[]>> fuzzyPairsList = new ArrayList<>(); for (String measureName : measureNames) { // add exact fuzzy keys for all the measure names provided in the scan, when constructing fuzzy row filter // its okay to use startTs as timebase part of rowKey is always fuzzy in fuzzy filter byte[] startRow = codec.createStartRowKey(scan.getDimensionValues(), measureName, scan.getStartTs(), false); byte[] fuzzyRowMask = codec.createFuzzyRowMask(scan.getDimensionValues(), measureName); fuzzyPairsList.add(new ImmutablePair<>(startRow, fuzzyRowMask)); } return new FuzzyRowFilter(fuzzyPairsList); }
private FuzzyRowFilter createFuzzyRowFilter(FactScan scan, List<String> measureNames) { List<ImmutablePair<byte[], byte[]>> fuzzyPairsList = new ArrayList<>(); for (String measureName : measureNames) { // add exact fuzzy keys for all the measure names provided in the scan, when constructing fuzzy row filter // its okay to use startTs as timebase part of rowKey is always fuzzy in fuzzy filter byte[] startRow = codec.createStartRowKey(scan.getDimensionValues(), measureName, scan.getStartTs(), false); byte[] fuzzyRowMask = codec.createFuzzyRowMask(scan.getDimensionValues(), measureName); fuzzyPairsList.add(new ImmutablePair<>(startRow, fuzzyRowMask)); } return new FuzzyRowFilter(fuzzyPairsList); }
byte[] start = fuzzyKeys.get(0).getFirst(); byte[] end = Bytes.stopKeyForPrefix(fuzzyKeys.get(fuzzyKeys.size() - 1).getFirst()); try (Scanner scan = indexedTable.scan(new Scan(start, end, new FuzzyRowFilter(fuzzyKeys)))) { Row next; while ((next = scan.next()) != null) {
byte[] start = fuzzyKeys.get(0).getFirst(); byte[] end = Bytes.stopKeyForPrefix(fuzzyKeys.get(fuzzyKeys.size() - 1).getFirst()); try (Scanner scan = indexedTable.scan(new Scan(start, end, new FuzzyRowFilter(fuzzyKeys)))) { Row next; while ((next = scan.next()) != null) {
private static void verifyScanWithFuzzyRowFilter(Table table) { FuzzyRowFilter filter = new FuzzyRowFilter( ImmutableList.of(ImmutablePair.of(new byte[]{'*', 'b', '*', 'b'}, new byte[]{0x01, 0x00, 0x01, 0x00}))); Scanner scanner = table.scan(new Scan(null, null, filter)); int count = 0; while (true) { Row entry = scanner.next(); if (entry == null) { break; } Assert.assertTrue(entry.getRow()[1] == 'b' && entry.getRow()[3] == 'b'); Assert.assertEquals(1, entry.getColumns().size()); Assert.assertTrue(entry.getColumns().containsKey(C1)); Assert.assertArrayEquals(V1, entry.get(C1)); count++; } Assert.assertEquals(9, count); }
FuzzyRowFilter filter = new FuzzyRowFilter( ImmutableList.of(ImmutablePair.of(new byte[] { '*', 'b', '*', 'b' }, new byte[] { 0x01, 0x00, 0x01, 0x00 }))); Scanner scanner = table.scan(null, null, filter);
byte[] mask = codec.createFuzzyRowMask(dimensionValues, "myMetric"); rowKey = codec.createRowKey(dimensionValues, "myMetric", ts); FuzzyRowFilter filter = new FuzzyRowFilter(ImmutableList.of(new ImmutablePair<>(rowKey, mask))); rowKey = codec.createRowKey(dimensionValues, null, ts); mask = codec.createFuzzyRowMask(dimensionValues, null); filter = new FuzzyRowFilter(ImmutableList.of(new ImmutablePair<>(rowKey, mask)));