RowFilterAdapter extends TypedFilterAdapterBase<org.apache.hadoop.hbase.filter.RowFilter> { @Override public Filter adapt(FilterAdapterContext context, org.apache.hadoop.hbase.filter.RowFilter filter) throws IOException { CompareOp compareOp = filter.getOperator(); if (compareOp != CompareFilter.CompareOp.EQUAL) { throw new IllegalStateException( String.format( "Cannot adapt operator %s", compareOp == null ? null : compareOp.getClass().getCanonicalName())); } ByteArrayComparable comparator = filter.getComparator(); ByteString regexValue; if (comparator == null) { throw new IllegalStateException("Comparator cannot be null"); } else if (comparator instanceof RegexStringComparator) { regexValue = ByteString.copyFrom(comparator.getValue()); } else if (comparator instanceof BinaryComparator) { regexValue = ReaderExpressionHelper.quoteRegularExpression(comparator.getValue()); } else { throw new IllegalStateException( String.format("Cannot adapt comparator %s", comparator.getClass().getCanonicalName())); } return FILTERS.key().regex(regexValue); }  @Override Filter adapt(FilterAdapterContext context, org.apache.hadoop.hbase.filter.RowFilter filter); @Override FilterSupportStatus isFilterSupported(
      FilterAdapterContext context, org.apache.hadoop.hbase.filter.RowFilter filter);  }
@Test public void testAdapt_RegexAndEquals() throws IOException { String regexp = "^.*hello world.*$"; RegexStringComparator comparator = new RegexStringComparator(regexp); org.apache.hadoop.hbase.filter.RowFilter filter = new org.apache.hadoop.hbase.filter.RowFilter(CompareFilter.CompareOp.EQUAL, comparator); Assert.assertEquals( FILTERS.key().regex(regexp).toProto(), adapter.adapt(context, filter).toProto()); }
@Test public void testAdapt_BinaryAndEquals() throws IOException { byte[] bytes = new byte[] {0, 1, 2}; BinaryComparator comparator = new BinaryComparator(bytes); org.apache.hadoop.hbase.filter.RowFilter filter = new org.apache.hadoop.hbase.filter.RowFilter(CompareFilter.CompareOp.EQUAL, comparator); Assert.assertEquals( FILTERS.key().regex(ReaderExpressionHelper.quoteRegularExpression(bytes)).toProto(), adapter.adapt(context, filter).toProto()); }
@Test public void testAdapt_EmptyRegex() throws IOException { String regexp = ""; RegexStringComparator comparator = new RegexStringComparator(regexp); org.apache.hadoop.hbase.filter.RowFilter filter = new org.apache.hadoop.hbase.filter.RowFilter(CompareFilter.CompareOp.EQUAL, comparator); Assert.assertEquals( FILTERS.key().regex(regexp).toProto(), adapter.adapt(context, filter).toProto()); }
@Test public void testAdapt_EmptyBinary() throws IOException { BinaryComparator comparator = new BinaryComparator(new byte[0]); org.apache.hadoop.hbase.filter.RowFilter filter = new org.apache.hadoop.hbase.filter.RowFilter(CompareFilter.CompareOp.EQUAL, comparator); Assert.assertEquals( FILTERS.key().regex(ByteString.copyFrom(new byte[0])).toProto(), adapter.adapt(context, filter).toProto()); }