/** * @param o the other filter to compare with * @return true if and only if the fields of the filter that are serialized * are equal to the corresponding fields in other. Used for testing. */ @Override boolean areSerializedFieldsEqual(Filter o) { if (o == this) return true; if (!(o instanceof PrefixFilter)) return false; PrefixFilter other = (PrefixFilter)o; return Bytes.equals(this.getPrefix(), other.getPrefix()); }
@Override public int hashCode() { return Bytes.hashCode(this.getPrefix()); } }
@Test public void testCompoundFilter1() throws IOException { String filterString = " (PrefixFilter ('realtime')AND FirstKeyOnlyFilter())"; FilterList filterList = doTestFilter(filterString, FilterList.class); ArrayList<Filter> filters = (ArrayList<Filter>) filterList.getFilters(); assertTrue(filters.get(0) instanceof PrefixFilter); assertTrue(filters.get(1) instanceof FirstKeyOnlyFilter); PrefixFilter PrefixFilter = (PrefixFilter) filters.get(0); byte [] prefix = PrefixFilter.getPrefix(); assertEquals("realtime", new String(prefix, StandardCharsets.UTF_8)); FirstKeyOnlyFilter firstKeyOnlyFilter = (FirstKeyOnlyFilter) filters.get(1); }
@Test public void testPrefixFilter() throws IOException { String filterString = " PrefixFilter('row' ) "; PrefixFilter prefixFilter = doTestFilter(filterString, PrefixFilter.class); byte [] prefix = prefixFilter.getPrefix(); assertEquals("row", new String(prefix, StandardCharsets.UTF_8)); filterString = " PrefixFilter(row)"; try { doTestFilter(filterString, PrefixFilter.class); assertTrue(false); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } }
case PrefixFilter: this.value = Bytes.toString(Base64.getEncoder().encode( ((PrefixFilter)filter).getPrefix())); break; case FamilyFilter:
@Test public void testPrecedence1() throws IOException { String filterString = " (PrefixFilter ('realtime')AND FirstKeyOnlyFilter()" + " OR KeyOnlyFilter())"; FilterList filterList = doTestFilter(filterString, FilterList.class); ArrayList<Filter> filters = (ArrayList<Filter>) filterList.getFilters(); assertTrue(filters.get(0) instanceof FilterList); assertTrue(filters.get(1) instanceof KeyOnlyFilter); filterList = (FilterList) filters.get(0); filters = (ArrayList<Filter>) filterList.getFilters(); assertTrue(filters.get(0) instanceof PrefixFilter); assertTrue(filters.get(1) instanceof FirstKeyOnlyFilter); PrefixFilter prefixFilter = (PrefixFilter)filters.get(0); byte [] prefix = prefixFilter.getPrefix(); assertEquals("realtime", new String(prefix, StandardCharsets.UTF_8)); }
@Test public void testPrecedence2() throws IOException { String filterString = " PrefixFilter ('realtime')AND SKIP FirstKeyOnlyFilter()" + "OR KeyOnlyFilter()"; FilterList filterList = doTestFilter(filterString, FilterList.class); ArrayList<Filter> filters = (ArrayList<Filter>) filterList.getFilters(); assertTrue(filters.get(0) instanceof FilterList); assertTrue(filters.get(1) instanceof KeyOnlyFilter); filterList = (FilterList) filters.get(0); filters = (ArrayList<Filter>) filterList.getFilters(); assertTrue(filters.get(0) instanceof PrefixFilter); assertTrue(filters.get(1) instanceof SkipFilter); PrefixFilter prefixFilter = (PrefixFilter)filters.get(0); byte [] prefix = prefixFilter.getPrefix(); assertEquals("realtime", new String(prefix, StandardCharsets.UTF_8)); SkipFilter skipFilter = (SkipFilter)filters.get(1); assertTrue(skipFilter.getFilter() instanceof FirstKeyOnlyFilter); }
@Test public void testCompoundFilter2() throws IOException { String filterString = "(PrefixFilter('realtime') AND QualifierFilter (>=, 'binary:e'))" + "OR FamilyFilter (=, 'binary:qualifier') "; FilterList filterList = doTestFilter(filterString, FilterList.class); ArrayList<Filter> filterListFilters = (ArrayList<Filter>) filterList.getFilters(); assertTrue(filterListFilters.get(0) instanceof FilterList); assertTrue(filterListFilters.get(1) instanceof FamilyFilter); assertEquals(FilterList.Operator.MUST_PASS_ONE, filterList.getOperator()); filterList = (FilterList) filterListFilters.get(0); FamilyFilter familyFilter = (FamilyFilter) filterListFilters.get(1); filterListFilters = (ArrayList<Filter>)filterList.getFilters(); assertTrue(filterListFilters.get(0) instanceof PrefixFilter); assertTrue(filterListFilters.get(1) instanceof QualifierFilter); assertEquals(FilterList.Operator.MUST_PASS_ALL, filterList.getOperator()); assertEquals(CompareOperator.EQUAL, familyFilter.getCompareOperator()); assertTrue(familyFilter.getComparator() instanceof BinaryComparator); BinaryComparator binaryComparator = (BinaryComparator) familyFilter.getComparator(); assertEquals("qualifier", new String(binaryComparator.getValue(), StandardCharsets.UTF_8)); PrefixFilter prefixFilter = (PrefixFilter) filterListFilters.get(0); byte [] prefix = prefixFilter.getPrefix(); assertEquals("realtime", new String(prefix, StandardCharsets.UTF_8)); QualifierFilter qualifierFilter = (QualifierFilter) filterListFilters.get(1); assertEquals(CompareOperator.GREATER_OR_EQUAL, qualifierFilter.getCompareOperator()); assertTrue(qualifierFilter.getComparator() instanceof BinaryComparator); binaryComparator = (BinaryComparator) qualifierFilter.getComparator(); assertEquals("e", new String(binaryComparator.getValue(), StandardCharsets.UTF_8)); }
/** * @param o the other filter to compare with * @return true if and only if the fields of the filter that are serialized * are equal to the corresponding fields in other. Used for testing. */ @Override boolean areSerializedFieldsEqual(Filter o) { if (o == this) return true; if (!(o instanceof PrefixFilter)) return false; PrefixFilter other = (PrefixFilter)o; return Bytes.equals(this.getPrefix(), other.getPrefix()); }
assertEquals(endTime, scan.getTimeRange().getMax()); assertEquals(true, (scan.getFilter() instanceof PrefixFilter)); assertEquals(0, Bytes.compareTo(((PrefixFilter) scan.getFilter()).getPrefix(), Bytes.toBytesBinary(prefix))); String[] argsWithLabels = { "-D " + ExportUtils.EXPORT_VISIBILITY_LABELS + "=" + label_0 + "," + label_1, assertEquals(endTime, scanWithLabels.getTimeRange().getMax()); assertEquals(true, (scanWithLabels.getFilter() instanceof PrefixFilter)); assertEquals(0, Bytes.compareTo(((PrefixFilter) scanWithLabels.getFilter()).getPrefix(), Bytes.toBytesBinary(prefix))); assertEquals(2, scanWithLabels.getAuthorizations().getLabels().size()); assertEquals(label_0, scanWithLabels.getAuthorizations().getLabels().get(0));
/** * @param o the other filter to compare with * @return true if and only if the fields of the filter that are serialized * are equal to the corresponding fields in other. Used for testing. */ @Override boolean areSerializedFieldsEqual(Filter o) { if (o == this) return true; if (!(o instanceof PrefixFilter)) return false; PrefixFilter other = (PrefixFilter)o; return Bytes.equals(this.getPrefix(), other.getPrefix()); }
/** * @param other * @return true if and only if the fields of the filter that are serialized * are equal to the corresponding fields in other. Used for testing. */ boolean areSerializedFieldsEqual(Filter o) { if (o == this) return true; if (!(o instanceof PrefixFilter)) return false; PrefixFilter other = (PrefixFilter)o; return Bytes.equals(this.getPrefix(), other.getPrefix()); }
@Override public Optional<String> decodeScannerFilterPrefix(MockScanner scanner) { final Filter filter; try { filter = ScannerModel.buildFilter(scanner.getFilter()); } catch (Exception e) { throw new RuntimeException(e); } if (filter instanceof PrefixFilter) { final String prefix = Bytes.toString(((PrefixFilter) filter).getPrefix()); return Optional.of(prefix); } return empty(); }
@Override public RangeSet<RowKeyWrapper> getIndexScanHint(PrefixFilter filter) { if (filter.getPrefix().length == 0) { return ImmutableRangeSet.of(Range.<RowKeyWrapper>all()); } else { ByteString start = ByteString.copyFrom(filter.getPrefix()); ByteString end = ByteString.copyFrom( RowKeyUtil.calculateTheClosestNextRowKeyForPrefix(filter.getPrefix()) ); return ImmutableRangeSet.of( Range.closedOpen(new RowKeyWrapper(start), new RowKeyWrapper(end)) ); } } }
@Override public RangeSet<RowKeyWrapper> getIndexScanHint(PrefixFilter filter) { if (filter.getPrefix().length == 0) { return ImmutableRangeSet.of(Range.<RowKeyWrapper>all()); } else { ByteString start = ByteString.copyFrom(filter.getPrefix()); ByteString end = ByteString.copyFrom( RowKeyUtil.calculateTheClosestNextRowKeyForPrefix(filter.getPrefix()) ); return ImmutableRangeSet.of( Range.closedOpen(new RowKeyWrapper(start), new RowKeyWrapper(end)) ); } } }
/** * {@inheritDoc} */ @Override public Filter adapt(FilterAdapterContext context, PrefixFilter filter) throws IOException { ByteString.Output output = ByteString.newOutput(filter.getPrefix().length * 2); ReaderExpressionHelper.writeQuotedRegularExpression(output, filter.getPrefix()); // Unquoted all bytes: output.write(ReaderExpressionHelper.ALL_QUALIFIERS_BYTES); return FILTERS.key().regex(output.toByteString()); }
/** * {@inheritDoc} */ @Override public Filter adapt(FilterAdapterContext context, PrefixFilter filter) throws IOException { ByteString.Output output = ByteString.newOutput(filter.getPrefix().length * 2); ReaderExpressionHelper.writeQuotedRegularExpression(output, filter.getPrefix()); // Unquoted all bytes: output.write(ReaderExpressionHelper.ALL_QUALIFIERS_BYTES); return FILTERS.key().regex(output.toByteString()); }
@Test public void testCompoundFilter1() throws IOException { String filterString = " (PrefixFilter ('realtime')AND FirstKeyOnlyFilter())"; FilterList filterList = doTestFilter(filterString, FilterList.class); ArrayList<Filter> filters = (ArrayList<Filter>) filterList.getFilters(); assertTrue(filters.get(0) instanceof PrefixFilter); assertTrue(filters.get(1) instanceof FirstKeyOnlyFilter); PrefixFilter PrefixFilter = (PrefixFilter) filters.get(0); byte [] prefix = PrefixFilter.getPrefix(); assertEquals("realtime", new String(prefix, StandardCharsets.UTF_8)); FirstKeyOnlyFilter firstKeyOnlyFilter = (FirstKeyOnlyFilter) filters.get(1); }
@Test public void testPrefixFilter() throws IOException { String filterString = " PrefixFilter('row' ) "; PrefixFilter prefixFilter = doTestFilter(filterString, PrefixFilter.class); byte [] prefix = prefixFilter.getPrefix(); assertEquals("row", new String(prefix, StandardCharsets.UTF_8)); filterString = " PrefixFilter(row)"; try { doTestFilter(filterString, PrefixFilter.class); assertTrue(false); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } }
@Test public void testPrecedence1() throws IOException { String filterString = " (PrefixFilter ('realtime')AND FirstKeyOnlyFilter()" + " OR KeyOnlyFilter())"; FilterList filterList = doTestFilter(filterString, FilterList.class); ArrayList<Filter> filters = (ArrayList<Filter>) filterList.getFilters(); assertTrue(filters.get(0) instanceof FilterList); assertTrue(filters.get(1) instanceof KeyOnlyFilter); filterList = (FilterList) filters.get(0); filters = (ArrayList<Filter>) filterList.getFilters(); assertTrue(filters.get(0) instanceof PrefixFilter); assertTrue(filters.get(1) instanceof FirstKeyOnlyFilter); PrefixFilter prefixFilter = (PrefixFilter)filters.get(0); byte [] prefix = prefixFilter.getPrefix(); assertEquals("realtime", new String(prefix, StandardCharsets.UTF_8)); }