public static Filter createFilterFromArguments(ArrayList<byte []> filterArguments) { Preconditions.checkArgument(filterArguments.size() == 4, "Expected 4 but got: %s", filterArguments.size()); byte [] minColumn = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0)); boolean minColumnInclusive = ParseFilter.convertByteArrayToBoolean(filterArguments.get(1)); byte [] maxColumn = ParseFilter.removeQuotesFromByteArray(filterArguments.get(2)); boolean maxColumnInclusive = ParseFilter.convertByteArrayToBoolean(filterArguments.get(3)); if (minColumn.length == 0) minColumn = null; if (maxColumn.length == 0) maxColumn = null; return new ColumnRangeFilter(minColumn, minColumnInclusive, maxColumn, maxColumnInclusive); }
@Override public int hashCode() { return Objects.hash(Bytes.hashCode(getMinColumn()), getMinColumnInclusive(), Bytes.hashCode(getMaxColumn()), getMaxColumnInclusive()); } }
@Test public void testColumnRangeFilter() throws IOException { String filterString = "ColumnRangeFilter('abc', true, 'xyz', false)"; ColumnRangeFilter columnRangeFilter = doTestFilter(filterString, ColumnRangeFilter.class); assertEquals("abc", new String(columnRangeFilter.getMinColumn(), StandardCharsets.UTF_8)); assertEquals("xyz", new String(columnRangeFilter.getMaxColumn(), StandardCharsets.UTF_8)); assertTrue(columnRangeFilter.isMinColumnInclusive()); assertFalse(columnRangeFilter.isMaxColumnInclusive()); }
@Test public void testColumnRangeFilter() throws Exception { // null columns ColumnRangeFilter columnRangeFilter = new ColumnRangeFilter(null, true, null, false); assertTrue(columnRangeFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(columnRangeFilter)))); // non-null columns columnRangeFilter = new ColumnRangeFilter(Bytes.toBytes("a"), false, Bytes.toBytes("b"), true); assertTrue(columnRangeFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(columnRangeFilter)))); }
@Test public void testColumnRangeFilter() throws Exception { // null columns ColumnRangeFilter columnRangeFilter = new ColumnRangeFilter(null, true, null, false); assertTrue(columnRangeFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(columnRangeFilter)))); // non-null columns columnRangeFilter = new ColumnRangeFilter(Bytes.toBytes("a"), false, Bytes.toBytes("b"), true); assertTrue(columnRangeFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(columnRangeFilter)))); }
@Test public void testColumnRangeFilter() throws IOException { String filterString = "ColumnRangeFilter('abc', true, 'xyz', false)"; ColumnRangeFilter columnRangeFilter = doTestFilter(filterString, ColumnRangeFilter.class); assertEquals("abc", new String(columnRangeFilter.getMinColumn(), StandardCharsets.UTF_8)); assertEquals("xyz", new String(columnRangeFilter.getMaxColumn(), StandardCharsets.UTF_8)); assertTrue(columnRangeFilter.isMinColumnInclusive()); assertFalse(columnRangeFilter.isMaxColumnInclusive()); }
@Test public void testWhileMatchFilter() throws Exception { WhileMatchFilter whileMatchFilter = new WhileMatchFilter( new ColumnRangeFilter(Bytes.toBytes("c"), false, Bytes.toBytes("d"), true)); assertTrue(whileMatchFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(whileMatchFilter)))); }
/** * @param o filter to serialize. * @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 ColumnRangeFilter)) { return false; } ColumnRangeFilter other = (ColumnRangeFilter) o; return Bytes.equals(this.getMinColumn(), other.getMinColumn()) && this.getMinColumnInclusive() == other.getMinColumnInclusive() && Bytes.equals(this.getMaxColumn(), other.getMaxColumn()) && this.getMaxColumnInclusive() == other.getMaxColumnInclusive(); }
@Test public void testFilterWrapper() throws Exception { FilterWrapper filterWrapper = new FilterWrapper( new ColumnRangeFilter(Bytes.toBytes("e"), false, Bytes.toBytes("f"), true)); assertTrue(filterWrapper.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(filterWrapper)))); }
case ColumnRangeFilter: ColumnRangeFilter crf = (ColumnRangeFilter)filter; this.minColumn = Bytes.toString(Base64.getEncoder().encode(crf.getMinColumn())); this.minColumnInclusive = crf.getMinColumnInclusive(); this.maxColumn = Bytes.toString(Base64.getEncoder().encode(crf.getMaxColumn())); this.maxColumnInclusive = crf.getMaxColumnInclusive(); break; case DependentColumnFilter: {
private void runTest(Table hTable, int cqStart, int expectedSize) throws IOException { // [0, 2, ?, ?, ?, ?, 0, 0, 0, 1] byte[] fuzzyKey = new byte[10]; ByteBuffer buf = ByteBuffer.wrap(fuzzyKey); buf.clear(); buf.putShort((short) 2); for (int i = 0; i < 4; i++) buf.put((byte)63); buf.putInt((short)1); byte[] mask = new byte[] {0 , 0, 1, 1, 1, 1, 0, 0, 0, 0}; Pair<byte[], byte[]> pair = new Pair<>(fuzzyKey, mask); FuzzyRowFilter fuzzyRowFilter = new FuzzyRowFilter(Lists.newArrayList(pair)); ColumnRangeFilter columnRangeFilter = new ColumnRangeFilter(Bytes.toBytes(cqStart), true , Bytes.toBytes(4), true); //regular test runScanner(hTable, expectedSize, fuzzyRowFilter, columnRangeFilter); //reverse filter order test runScanner(hTable, expectedSize, columnRangeFilter, fuzzyRowFilter); }
/** * @param o filter to serialize. * @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 ColumnRangeFilter)) { return false; } ColumnRangeFilter other = (ColumnRangeFilter) o; return Bytes.equals(this.getMinColumn(), other.getMinColumn()) && this.getMinColumnInclusive() == other.getMinColumnInclusive() && Bytes.equals(this.getMaxColumn(), other.getMaxColumn()) && this.getMaxColumnInclusive() == other.getMaxColumnInclusive(); }
/** * Test partial Result re-assembly in the presence of different filters. The Results from the * partial scanner should match the Results returned from a scanner that receives all of the * results in one RPC to the server. The partial scanner is tested with a variety of different * result sizes (all of which are less than the size necessary to fetch an entire row) * @throws Exception */ @Test public void testPartialResultsWithColumnFilter() throws Exception { testPartialResultsWithColumnFilter(new FirstKeyOnlyFilter()); testPartialResultsWithColumnFilter(new ColumnPrefixFilter(Bytes.toBytes("testQualifier5"))); testPartialResultsWithColumnFilter(new ColumnRangeFilter(Bytes.toBytes("testQualifer1"), true, Bytes.toBytes("testQualifier7"), true)); Set<byte[]> qualifiers = new LinkedHashSet<>(); qualifiers.add(Bytes.toBytes("testQualifier5")); testPartialResultsWithColumnFilter(new FirstKeyValueMatchingQualifiersFilter(qualifiers)); }
/** * @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. */ @Override boolean areSerializedFieldsEqual(Filter o) { if (o == this) return true; if (!(o instanceof ColumnRangeFilter)) return false; ColumnRangeFilter other = (ColumnRangeFilter)o; return Bytes.equals(this.getMinColumn(),other.getMinColumn()) && this.getMinColumnInclusive() == other.getMinColumnInclusive() && Bytes.equals(this.getMaxColumn(), other.getMaxColumn()) && this.getMaxColumnInclusive() == other.getMaxColumnInclusive(); }
public static Filter getFilter(SliceQuery query) { byte[] colStartBytes = query.getSliceEnd().length() > 0 ? query.getSliceStart().as(StaticBuffer.ARRAY_FACTORY) : null; byte[] colEndBytes = query.getSliceEnd().length() > 0 ? query.getSliceEnd().as(StaticBuffer.ARRAY_FACTORY) : null; Filter filter = new ColumnRangeFilter(colStartBytes, true, colEndBytes, false); if (query.hasLimit()) { filter = new FilterList(FilterList.Operator.MUST_PASS_ALL, filter, new ColumnPaginationFilter(query.getLimit(), 0)); } logger.debug("Generated HBase Filter {}", filter); return filter; }
/** * @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 ColumnRangeFilter)) return false; ColumnRangeFilter other = (ColumnRangeFilter)o; return Bytes.equals(this.getMinColumn(),other.getMinColumn()) && this.getMinColumnInclusive() == other.getMinColumnInclusive() && Bytes.equals(this.getMaxColumn(), other.getMaxColumn()) && this.getMaxColumnInclusive() == other.getMaxColumnInclusive(); }
break; case ColumnRangeFilter: filter = new ColumnRangeFilter(Base64.getDecoder().decode(minColumn), minColumnInclusive, Base64.getDecoder().decode(maxColumn), maxColumnInclusive);
/** {@inheritDoc} */ @Override public Filter adapt(FilterAdapterContext context, ColumnRangeFilter filter) throws IOException { byte[] familyName = getSingleFamily(context.getScan()); QualifierRangeFilter rangeBuilder = FILTERS.qualifier().rangeWithinFamily(Bytes.toString(familyName)); if (filter.getMinColumn() != null) { ByteString startQualifier = ByteString.copyFrom(filter.getMinColumn()); if (filter.getMinColumnInclusive()) { rangeBuilder.startClosed(startQualifier); } else { rangeBuilder.startOpen(startQualifier); } } if (filter.getMaxColumn() != null) { ByteString endQualifier = ByteString.copyFrom(filter.getMaxColumn()); if (filter.getMaxColumnInclusive()) { rangeBuilder.endClosed(endQualifier); } else { rangeBuilder.endOpen(endQualifier); } } return rangeBuilder; }
scan.setMaxVersions(); for (StringRange s : rangeMap.keySet()) { filter = new ColumnRangeFilter(s.getStart() == null ? null : Bytes.toBytes(s.getStart()), s.isStartInclusive(), s.getEnd() == null ? null : Bytes.toBytes(s.getEnd()), s.isEndInclusive());
/** {@inheritDoc} */ @Override public Filter adapt(FilterAdapterContext context, ColumnRangeFilter filter) throws IOException { byte[] familyName = getSingleFamily(context.getScan()); QualifierRangeFilter rangeBuilder = FILTERS.qualifier().rangeWithinFamily(Bytes.toString(familyName)); if (filter.getMinColumn() != null) { ByteString startQualifier = ByteString.copyFrom(filter.getMinColumn()); if (filter.getMinColumnInclusive()) { rangeBuilder.startClosed(startQualifier); } else { rangeBuilder.startOpen(startQualifier); } } if (filter.getMaxColumn() != null) { ByteString endQualifier = ByteString.copyFrom(filter.getMaxColumn()); if (filter.getMaxColumnInclusive()) { rangeBuilder.endClosed(endQualifier); } else { rangeBuilder.endOpen(endQualifier); } } return rangeBuilder; }