org.apache.hadoop.hbase.CompareOperator Java Examples

The following examples show how to use org.apache.hadoop.hbase.CompareOperator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompareFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static ArrayList<Object> extractArguments(ArrayList<byte []> filterArguments) {
  Preconditions.checkArgument(filterArguments.size() == 2,
                              "Expected 2 but got: %s", filterArguments.size());
  CompareOperator op = ParseFilter.createCompareOperator(filterArguments.get(0));
  ByteArrayComparable comparator = ParseFilter.createComparator(
    ParseFilter.removeQuotesFromByteArray(filterArguments.get(1)));

  if (comparator instanceof RegexStringComparator ||
      comparator instanceof SubstringComparator) {
    if (op != CompareOperator.EQUAL &&
        op != CompareOperator.NOT_EQUAL) {
      throw new IllegalArgumentException ("A regexstring comparator and substring comparator" +
                                          " can only be used with EQUAL and NOT_EQUAL");
    }
  }
  ArrayList<Object> arguments = new ArrayList<>(2);
  arguments.add(op);
  arguments.add(comparator);
  return arguments;
}
 
Example #2
Source File: FamilyFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * @param pbBytes A pb serialized {@link FamilyFilter} instance
 * @return An instance of {@link FamilyFilter} made from <code>bytes</code>
 * @throws DeserializationException
 * @see #toByteArray
 */
public static FamilyFilter parseFrom(final byte [] pbBytes)
throws DeserializationException {
  FilterProtos.FamilyFilter proto;
  try {
    proto = FilterProtos.FamilyFilter.parseFrom(pbBytes);
  } catch (InvalidProtocolBufferException e) {
    throw new DeserializationException(e);
  }
  final CompareOperator valueCompareOp =
    CompareOperator.valueOf(proto.getCompareFilter().getCompareOp().name());
  ByteArrayComparable valueComparator = null;
  try {
    if (proto.getCompareFilter().hasComparator()) {
      valueComparator = ProtobufUtil.toComparator(proto.getCompareFilter().getComparator());
    }
  } catch (IOException ioe) {
    throw new DeserializationException(ioe);
  }
  return new FamilyFilter(valueCompareOp,valueComparator);
}
 
Example #3
Source File: ColumnValueFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Creating this filter by reflection, it is used by {@link ParseFilter},
 * @param filterArguments arguments for creating a ColumnValueFilter
 * @return a ColumnValueFilter
 */
public static Filter createFilterFromArguments(ArrayList<byte[]> filterArguments) {
  Preconditions.checkArgument(filterArguments.size() == 4,
    "Expect 4 arguments: %s", filterArguments.size());
  byte[] family = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0));
  byte[] qualifier = ParseFilter.removeQuotesFromByteArray(filterArguments.get(1));
  CompareOperator operator = ParseFilter.createCompareOperator(filterArguments.get(2));
  ByteArrayComparable comparator =
    ParseFilter.createComparator(ParseFilter.removeQuotesFromByteArray(filterArguments.get(3)));

  if (comparator instanceof RegexStringComparator ||
      comparator instanceof SubstringComparator) {
    if (operator != CompareOperator.EQUAL &&
        operator != CompareOperator.NOT_EQUAL) {
      throw new IllegalArgumentException("A regexstring comparator and substring comparator " +
          "can only be used with EQUAL and NOT_EQUAL");
    }
  }

  return new ColumnValueFilter(family, qualifier, operator, comparator);
}
 
Example #4
Source File: TestThriftConnection.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void testScanWithFilters(Connection connection, String tableName) throws IOException {
  createTable(thriftAdmin, tableName);
  try (Table table = connection.getTable(TableName.valueOf(tableName))){
    FilterList filterList = new FilterList();
    PrefixFilter prefixFilter = new PrefixFilter(Bytes.toBytes("testrow"));
    ColumnValueFilter columnValueFilter = new ColumnValueFilter(FAMILYA, QUALIFIER_1,
        CompareOperator.EQUAL, VALUE_1);
    filterList.addFilter(prefixFilter);
    filterList.addFilter(columnValueFilter);
    Scan scan = new Scan();
    scan.readVersions(2);
    scan.setFilter(filterList);
    ResultScanner scanner = table.getScanner(scan);
    Iterator<Result> iterator = scanner.iterator();
    assertTrue(iterator.hasNext());
    int counter = 0;
    while (iterator.hasNext()) {
      Result result = iterator.next();
      counter += result.size();
    }
    assertEquals(2, counter);
  }
}
 
Example #5
Source File: RequestConverter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Create a protocol buffer Condition
 *
 * @return a Condition
 * @throws IOException
 */
public static Condition buildCondition(final byte[] row, final byte[] family,
  final byte[] qualifier, final CompareOperator op, final byte[] value, final Filter filter,
  final TimeRange timeRange) throws IOException {

  Condition.Builder builder = Condition.newBuilder().setRow(UnsafeByteOperations.unsafeWrap(row));

  if (filter != null) {
    builder.setFilter(ProtobufUtil.toFilter(filter));
  } else {
    builder.setFamily(UnsafeByteOperations.unsafeWrap(family))
      .setQualifier(UnsafeByteOperations.unsafeWrap(
        qualifier == null ? HConstants.EMPTY_BYTE_ARRAY : qualifier))
      .setComparator(ProtobufUtil.toComparator(new BinaryComparator(value)))
      .setCompareType(CompareType.valueOf(op.name()));
  }

  return builder.setTimeRange(ProtobufUtil.toTimeRange(timeRange)).build();
}
 
Example #6
Source File: ValueFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * @param pbBytes A pb serialized {@link ValueFilter} instance
 * @return An instance of {@link ValueFilter} made from <code>bytes</code>
 * @throws DeserializationException
 * @see #toByteArray
 */
public static ValueFilter parseFrom(final byte [] pbBytes)
throws DeserializationException {
  FilterProtos.ValueFilter proto;
  try {
    proto = FilterProtos.ValueFilter.parseFrom(pbBytes);
  } catch (InvalidProtocolBufferException e) {
    throw new DeserializationException(e);
  }
  final CompareOperator valueCompareOp =
    CompareOperator.valueOf(proto.getCompareFilter().getCompareOp().name());
  ByteArrayComparable valueComparator = null;
  try {
    if (proto.getCompareFilter().hasComparator()) {
      valueComparator = ProtobufUtil.toComparator(proto.getCompareFilter().getComparator());
    }
  } catch (IOException ioe) {
    throw new DeserializationException(ioe);
  }
  return new ValueFilter(valueCompareOp,valueComparator);
}
 
Example #7
Source File: SingleColumnValueFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * @param pbBytes A pb serialized {@link SingleColumnValueFilter} instance
 * @return An instance of {@link SingleColumnValueFilter} made from <code>bytes</code>
 * @throws org.apache.hadoop.hbase.exceptions.DeserializationException
 * @see #toByteArray
 */
public static SingleColumnValueFilter parseFrom(final byte [] pbBytes)
throws DeserializationException {
  FilterProtos.SingleColumnValueFilter proto;
  try {
    proto = FilterProtos.SingleColumnValueFilter.parseFrom(pbBytes);
  } catch (InvalidProtocolBufferException e) {
    throw new DeserializationException(e);
  }

  final CompareOperator compareOp =
    CompareOperator.valueOf(proto.getCompareOp().name());
  final org.apache.hadoop.hbase.filter.ByteArrayComparable comparator;
  try {
    comparator = ProtobufUtil.toComparator(proto.getComparator());
  } catch (IOException ioe) {
    throw new DeserializationException(ioe);
  }

  return new SingleColumnValueFilter(proto.hasColumnFamily() ? proto.getColumnFamily()
      .toByteArray() : null, proto.hasColumnQualifier() ? proto.getColumnQualifier()
      .toByteArray() : null, compareOp, comparator, proto.getFilterIfMissing(), proto
      .getLatestVersionOnly());
}
 
Example #8
Source File: RegionsMerger.java    From hbase-operator-tools with Apache License 2.0 6 votes vote down vote up
private List<RegionInfo> getOpenRegions(Connection connection, TableName table) throws Exception {
  List<RegionInfo> regions = new ArrayList<>();
  Table metaTbl = connection.getTable(META_TABLE_NAME);
  String tblName = table.getNameAsString();
  RowFilter rowFilter = new RowFilter(CompareOperator.EQUAL,
    new SubstringComparator(tblName+","));
  SingleColumnValueFilter colFilter = new SingleColumnValueFilter(CATALOG_FAMILY,
    STATE_QUALIFIER, CompareOperator.EQUAL, Bytes.toBytes("OPEN"));
  Scan scan = new Scan();
  FilterList filter = new FilterList(FilterList.Operator.MUST_PASS_ALL);
  filter.addFilter(rowFilter);
  filter.addFilter(colFilter);
  scan.setFilter(filter);
  try(ResultScanner rs = metaTbl.getScanner(scan)){
    Result r;
    while ((r = rs.next()) != null) {
      RegionInfo region = RegionInfo.parseFrom(r.getValue(CATALOG_FAMILY, REGIONINFO_QUALIFIER));
      regions.add(region);
    }
  }
  return regions;
}
 
Example #9
Source File: TestScannersFromClientSide.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testScanWithColumnsAndFilterAndVersion() throws IOException {
  TableName tableName = name.getTableName();
  long now = System.currentTimeMillis();
  try (Table table = TEST_UTIL.createTable(tableName, FAMILY, 4)) {
    for (int i = 0; i < 4; i++) {
      Put put = new Put(ROW);
      put.addColumn(FAMILY, QUALIFIER, now + i, VALUE);
      table.put(put);
    }

    Scan scan = new Scan();
    scan.addColumn(FAMILY, QUALIFIER);
    scan.setFilter(new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(QUALIFIER)));
    scan.readVersions(3);

    try (ResultScanner scanner = table.getScanner(scan)) {
      Result result = scanner.next();
      assertEquals(3, result.size());
    }
  }
}
 
Example #10
Source File: RequestConverter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Create a protocol buffer MutateRequest for a conditioned put/delete
 *
 * @return a mutate request
 * @throws IOException
 */
public static MutateRequest buildMutateRequest(final byte[] regionName, final byte[] row,
  final byte[] family, final byte[] qualifier, final CompareOperator op, final byte[] value,
  final Filter filter, final TimeRange timeRange, final Mutation mutation) throws IOException {
  MutationType type;
  if (mutation instanceof Put) {
    type = MutationType.PUT;
  } else {
    type = MutationType.DELETE;
  }
  return MutateRequest.newBuilder()
    .setRegion(buildRegionSpecifier(RegionSpecifierType.REGION_NAME, regionName))
    .setMutation(ProtobufUtil.toMutation(type, mutation))
    .setCondition(buildCondition(row, family, qualifier, op, value, filter, timeRange))
    .build();
}
 
Example #11
Source File: SingleColumnValueExcludeFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * @param pbBytes A pb serialized {@link SingleColumnValueExcludeFilter} instance
 * @return An instance of {@link SingleColumnValueExcludeFilter} made from <code>bytes</code>
 * @throws DeserializationException
 * @see #toByteArray
 */
public static SingleColumnValueExcludeFilter parseFrom(final byte [] pbBytes)
throws DeserializationException {
  FilterProtos.SingleColumnValueExcludeFilter proto;
  try {
    proto = FilterProtos.SingleColumnValueExcludeFilter.parseFrom(pbBytes);
  } catch (InvalidProtocolBufferException e) {
    throw new DeserializationException(e);
  }

  FilterProtos.SingleColumnValueFilter parentProto = proto.getSingleColumnValueFilter();
  final CompareOperator compareOp =
    CompareOperator.valueOf(parentProto.getCompareOp().name());
  final ByteArrayComparable comparator;
  try {
    comparator = ProtobufUtil.toComparator(parentProto.getComparator());
  } catch (IOException ioe) {
    throw new DeserializationException(ioe);
  }

  return new SingleColumnValueExcludeFilter(parentProto.hasColumnFamily() ? parentProto
      .getColumnFamily().toByteArray() : null, parentProto.hasColumnQualifier() ? parentProto
      .getColumnQualifier().toByteArray() : null, compareOp, comparator, parentProto
      .getFilterIfMissing(), parentProto.getLatestVersionOnly());
}
 
Example #12
Source File: ColumnValueFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Parse protobuf bytes to a ColumnValueFilter
 * @param pbBytes pbBytes
 * @return a ColumnValueFilter
 * @throws DeserializationException deserialization exception
 */
public static ColumnValueFilter parseFrom(final byte[] pbBytes) throws DeserializationException {
  FilterProtos.ColumnValueFilter proto;
  try {
    proto = FilterProtos.ColumnValueFilter.parseFrom(pbBytes);
  } catch (InvalidProtocolBufferException e) {
    throw new DeserializationException(e);
  }

  final CompareOperator compareOp = CompareOperator.valueOf(proto.getCompareOp().name());
  final ByteArrayComparable comparator;
  try {
    comparator = ProtobufUtil.toComparator(proto.getComparator());
  } catch (IOException ioe) {
    throw new DeserializationException(ioe);
  }

  return new ColumnValueFilter(proto.getFamily().toByteArray(),
    proto.getQualifier().toByteArray(), compareOp, comparator);
}
 
Example #13
Source File: RegionCoprocessorHost.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Supports Coprocessor 'bypass'.
 * @param row row to check
 * @param family column family
 * @param qualifier column qualifier
 * @param op the comparison operation
 * @param comparator the comparator
 * @param put data to put if check succeeds
 * @return true or false to return to client if default processing should be bypassed, or null
 * otherwise
 */
public Boolean preCheckAndPut(final byte [] row, final byte [] family,
    final byte [] qualifier, final CompareOperator op,
    final ByteArrayComparable comparator, final Put put)
    throws IOException {
  boolean bypassable = true;
  boolean defaultResult = false;
  if (coprocEnvironments.isEmpty()) {
    return null;
  }
  return execOperationWithResult(
      new ObserverOperationWithResult<RegionObserver, Boolean>(regionObserverGetter,
          defaultResult,  bypassable) {
        @Override
        public Boolean call(RegionObserver observer) throws IOException {
          return observer.preCheckAndPut(this, row, family, qualifier,
              op, comparator, put, getResult());
        }
      });
}
 
Example #14
Source File: RegionCoprocessorHost.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Supports Coprocessor 'bypass'.
 * @param row row to check
 * @param family column family
 * @param qualifier column qualifier
 * @param op the comparison operation
 * @param comparator the comparator
 * @param put data to put if check succeeds
 * @return true or false to return to client if default processing should be bypassed, or null
 *   otherwise
 */
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="NP_BOOLEAN_RETURN_NULL",
    justification="Null is legit")
public Boolean preCheckAndPutAfterRowLock(
    final byte[] row, final byte[] family, final byte[] qualifier, final CompareOperator op,
    final ByteArrayComparable comparator, final Put put) throws IOException {
  boolean bypassable = true;
  boolean defaultResult = false;
  if (coprocEnvironments.isEmpty()) {
    return null;
  }
  return execOperationWithResult(
      new ObserverOperationWithResult<RegionObserver, Boolean>(regionObserverGetter,
          defaultResult, bypassable) {
        @Override
        public Boolean call(RegionObserver observer) throws IOException {
          return observer.preCheckAndPutAfterRowLock(this, row, family, qualifier,
              op, comparator, put, getResult());
        }
      });
}
 
Example #15
Source File: RegionCoprocessorHost.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * @param row row to check
 * @param family column family
 * @param qualifier column qualifier
 * @param op the comparison operation
 * @param comparator the comparator
 * @param put data to put if check succeeds
 * @throws IOException e
 */
public boolean postCheckAndPut(final byte [] row, final byte [] family,
    final byte [] qualifier, final CompareOperator op,
    final ByteArrayComparable comparator, final Put put,
    boolean result) throws IOException {
  if (this.coprocEnvironments.isEmpty()) {
    return result;
  }
  return execOperationWithResult(
      new ObserverOperationWithResult<RegionObserver, Boolean>(regionObserverGetter, result) {
        @Override
        public Boolean call(RegionObserver observer) throws IOException {
          return observer.postCheckAndPut(this, row, family, qualifier,
              op, comparator, put, getResult());
        }
      });
}
 
Example #16
Source File: RegionCoprocessorHost.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Supports Coprocessor 'bypass'.
 * @param row row to check
 * @param family column family
 * @param qualifier column qualifier
 * @param op the comparison operation
 * @param comparator the comparator
 * @param delete delete to commit if check succeeds
 * @return true or false to return to client if default processing should be bypassed, or null
 *   otherwise
 */
public Boolean preCheckAndDelete(final byte [] row, final byte [] family,
    final byte [] qualifier, final CompareOperator op,
    final ByteArrayComparable comparator, final Delete delete)
    throws IOException {
  boolean bypassable = true;
  boolean defaultResult = false;
  if (coprocEnvironments.isEmpty()) {
    return null;
  }
  return execOperationWithResult(
      new ObserverOperationWithResult<RegionObserver, Boolean>(regionObserverGetter,
          defaultResult, bypassable) {
        @Override
        public Boolean call(RegionObserver observer) throws IOException {
          return observer.preCheckAndDelete(this, row, family,
              qualifier, op, comparator, delete, getResult());
        }
      });
}
 
Example #17
Source File: RegionCoprocessorHost.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * @param row row to check
 * @param family column family
 * @param qualifier column qualifier
 * @param op the comparison operation
 * @param comparator the comparator
 * @param delete delete to commit if check succeeds
 * @throws IOException e
 */
public boolean postCheckAndDelete(final byte [] row, final byte [] family,
    final byte [] qualifier, final CompareOperator op,
    final ByteArrayComparable comparator, final Delete delete,
    boolean result) throws IOException {
  if (this.coprocEnvironments.isEmpty()) {
    return result;
  }
  return execOperationWithResult(
      new ObserverOperationWithResult<RegionObserver, Boolean>(regionObserverGetter, result) {
        @Override
        public Boolean call(RegionObserver observer) throws IOException {
          return observer.postCheckAndDelete(this, row, family,
              qualifier, op, comparator, delete, getResult());
        }
      });
}
 
Example #18
Source File: QualifierFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * @param pbBytes A pb serialized {@link QualifierFilter} instance
 * @return An instance of {@link QualifierFilter} made from <code>bytes</code>
 * @throws org.apache.hadoop.hbase.exceptions.DeserializationException
 * @see #toByteArray
 */
public static QualifierFilter parseFrom(final byte [] pbBytes)
throws DeserializationException {
  FilterProtos.QualifierFilter proto;
  try {
    proto = FilterProtos.QualifierFilter.parseFrom(pbBytes);
  } catch (InvalidProtocolBufferException e) {
    throw new DeserializationException(e);
  }
  final CompareOperator valueCompareOp =
    CompareOperator.valueOf(proto.getCompareFilter().getCompareOp().name());
  ByteArrayComparable valueComparator = null;
  try {
    if (proto.getCompareFilter().hasComparator()) {
      valueComparator = ProtobufUtil.toComparator(proto.getCompareFilter().getComparator());
    }
  } catch (IOException ioe) {
    throw new DeserializationException(ioe);
  }
  return new QualifierFilter(valueCompareOp,valueComparator);
}
 
Example #19
Source File: TestTableInputFormat.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(JobConf job) {
  try {
    Connection connection = ConnectionFactory.createConnection(HBaseConfiguration.create(job));
    TableName tableName = TableName.valueOf("exampleJobConfigurableTable");
    // mandatory
    initializeTable(connection, tableName);
    byte[][] inputColumns = new byte [][] { Bytes.toBytes("columnA"),
      Bytes.toBytes("columnB") };
    //optional
    Scan scan = new Scan();
    for (byte[] family : inputColumns) {
      scan.addFamily(family);
    }
    Filter exampleFilter =
      new RowFilter(CompareOperator.EQUAL, new RegexStringComparator("aa.*"));
    scan.setFilter(exampleFilter);
    setScan(scan);
  } catch (IOException exception) {
    throw new RuntimeException("Failed to initialize.", exception);
  }
}
 
Example #20
Source File: TestFilterSerialization.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleColumnValueFilter() throws Exception {
  // null family/column SingleColumnValueFilter
  SingleColumnValueFilter singleColumnValueFilter =
    new SingleColumnValueFilter(null, null,
    CompareOperator.LESS, Bytes.toBytes("value"));
  assertTrue(singleColumnValueFilter.areSerializedFieldsEqual(
    ProtobufUtil.toFilter(ProtobufUtil.toFilter(singleColumnValueFilter))));

  // non-null family/column SingleColumnValueFilter
  singleColumnValueFilter =
    new SingleColumnValueFilter(Bytes.toBytes("family"), Bytes.toBytes("qualifier"),
     CompareOperator.NOT_EQUAL, new NullComparator(), true, true);
  assertTrue(singleColumnValueFilter.areSerializedFieldsEqual(
    ProtobufUtil.toFilter(ProtobufUtil.toFilter(singleColumnValueFilter))));
}
 
Example #21
Source File: TestFiltersWithBinaryComponentComparator.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * We have rows with either "abc" or "xyz".
 * We want values which have 'y' at second position
 * of the string.
 * As a result only values with "xyz" shall be returned
*/
private void setValueFilters(FilterList filterList) {
  int offset = 1;
  byte[] y = Bytes.toBytes("y");
  Filter yFilter  = new ValueFilter(CompareOperator.EQUAL,
          new BinaryComponentComparator(y,offset));
  filterList.addFilter(yFilter);
}
 
Example #22
Source File: SimpleRegionObserver.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preCheckAndDelete(ObserverContext<RegionCoprocessorEnvironment> e, byte[] row,
                                 byte[] family, byte[] qualifier, CompareOperator compareOp, ByteArrayComparable comparator,
                                 Delete delete, boolean result) throws IOException {
  ctPreCheckAndDelete.incrementAndGet();
  return true;
}
 
Example #23
Source File: TestRegionObserverInterface.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckAndDeleteHooks() throws IOException {
  final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
  Table table = util.createTable(tableName, new byte[][] { A, B, C });
  try {
    Put p = new Put(Bytes.toBytes(0));
    p.addColumn(A, A, A);
    table.put(p);
    Delete d = new Delete(Bytes.toBytes(0));
    table.delete(d);
    verifyMethodResult(
      SimpleRegionObserver.class, new String[] { "getPreCheckAndDelete",
        "getPreCheckAndDeleteAfterRowLock", "getPostCheckAndDelete",
        "getPreCheckAndDeleteWithFilter", "getPreCheckAndDeleteWithFilterAfterRowLock",
        "getPostCheckAndDeleteWithFilter" },
      tableName, new Integer[] { 0, 0, 0, 0, 0, 0 });

    table.checkAndMutate(Bytes.toBytes(0), A).qualifier(A).ifEquals(A).thenDelete(d);
    verifyMethodResult(
      SimpleRegionObserver.class, new String[] { "getPreCheckAndDelete",
        "getPreCheckAndDeleteAfterRowLock", "getPostCheckAndDelete",
        "getPreCheckAndDeleteWithFilter", "getPreCheckAndDeleteWithFilterAfterRowLock",
        "getPostCheckAndDeleteWithFilter" },
      tableName, new Integer[] { 1, 1, 1, 0, 0, 0 });

    table.checkAndMutate(Bytes.toBytes(0),
        new SingleColumnValueFilter(A, A, CompareOperator.EQUAL, A))
      .thenDelete(d);
    verifyMethodResult(
      SimpleRegionObserver.class, new String[] { "getPreCheckAndDelete",
        "getPreCheckAndDeleteAfterRowLock", "getPostCheckAndDelete",
        "getPreCheckAndDeleteWithFilter", "getPreCheckAndDeleteWithFilterAfterRowLock",
        "getPostCheckAndDeleteWithFilter" },
      tableName, new Integer[] { 1, 1, 1, 1, 1, 1 });
  } finally {
    util.deleteTable(tableName);
    table.close();
  }
}
 
Example #24
Source File: TestPassCustomCellViaRegionObserver.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preCheckAndDelete(ObserverContext<RegionCoprocessorEnvironment> c, byte[] row,
  byte[] family, byte[] qualifier, CompareOperator op, ByteArrayComparable comparator,
  Delete delete, boolean result) throws IOException {
  delete.add(createCustomCell(delete));
  COUNT.incrementAndGet();
  return result;
}
 
Example #25
Source File: TestJoinedScanners.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test(expected = DoNotRetryIOException.class)
public void testWithReverseScan() throws Exception {
  try (Connection con = TEST_UTIL.getConnection(); Admin admin = con.getAdmin()) {
    TableName tableName = TableName.valueOf(name.getMethodName());

    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName)
        .setColumnFamily(ColumnFamilyDescriptorBuilder.of("cf1"))
        .setColumnFamily(ColumnFamilyDescriptorBuilder.of("cf2"))
        .build();
    admin.createTable(tableDescriptor);

    try (Table table = con.getTable(tableName)) {
      SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes("cf1"),
        Bytes.toBytes("col"), CompareOperator.EQUAL, Bytes.toBytes("val"));
      filter.setFilterIfMissing(true);

      // Reverse scan with loading CFs on demand
      Scan scan = new Scan();
      scan.setFilter(filter);
      scan.setReversed(true);
      scan.setLoadColumnFamiliesOnDemand(true);

      try (ResultScanner scanner = table.getScanner(scan)) {
        // DoNotRetryIOException should occur
        scanner.next();
      }
    }
  }
}
 
Example #26
Source File: TestFilterSerialization.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testDependentColumnFilter() throws Exception {
  // null column qualifier/family
  DependentColumnFilter dependentColumnFilter = new DependentColumnFilter(null, null);
  assertTrue(dependentColumnFilter.areSerializedFieldsEqual(
    ProtobufUtil.toFilter(ProtobufUtil.toFilter(dependentColumnFilter))));

  // non-null column qualifier/family
  dependentColumnFilter = new DependentColumnFilter(Bytes.toBytes("family"),
    Bytes.toBytes("qual"), true, CompareOperator.GREATER_OR_EQUAL,
    new BitComparator(Bytes.toBytes("bitComparator"), BitComparator.BitwiseOp.OR));
  assertTrue(dependentColumnFilter.areSerializedFieldsEqual(
    ProtobufUtil.toFilter(ProtobufUtil.toFilter(dependentColumnFilter))));
}
 
Example #27
Source File: TestFilterSerialization.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testFamilyFilter() throws Exception {
  FamilyFilter familyFilter = new FamilyFilter(CompareOperator.EQUAL,
    new BinaryPrefixComparator(Bytes.toBytes("testValueOne")));
  assertTrue(familyFilter.areSerializedFieldsEqual(
    ProtobufUtil.toFilter(ProtobufUtil.toFilter(familyFilter))));
}
 
Example #28
Source File: TestDependentColumnFilter.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Test for HBASE-8794. Avoid NullPointerException in DependentColumnFilter.toString().
 */
@Test
public void testToStringWithNullComparator() {
  // Test constructor that implicitly sets a null comparator
  Filter filter = new DependentColumnFilter(FAMILIES[0], QUALIFIER);
  assertNotNull(filter.toString());
  assertTrue("check string contains 'null' as compatator is null",
    filter.toString().contains("null"));

  // Test constructor with explicit null comparator
  filter = new DependentColumnFilter(FAMILIES[0], QUALIFIER, true, CompareOperator.EQUAL, null);
  assertNotNull(filter.toString());
  assertTrue("check string contains 'null' as compatator is null",
    filter.toString().contains("null"));
}
 
Example #29
Source File: TestAsyncTable.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
@Deprecated
public void testCheckAndMutateWithFilterAndTimeRangeForOldApi() throws Throwable {
  AsyncTable<?> table = getTable.get();

  // Put with specifying the timestamp
  table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a")))
    .get();

  // Put with success
  boolean ok = table.checkAndMutate(row, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
      CompareOperator.EQUAL, Bytes.toBytes("a")))
    .timeRange(TimeRange.between(0, 101))
    .thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))
    .get();
  assertTrue(ok);

  Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();
  assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));

  // Put with failure
  ok = table.checkAndMutate(row, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
      CompareOperator.EQUAL, Bytes.toBytes("a")))
    .timeRange(TimeRange.between(0, 100))
    .thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")))
    .get();
  assertFalse(ok);

  assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());
}
 
Example #30
Source File: SimpleRegionObserver.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preCheckAndDeleteAfterRowLock(ObserverContext<RegionCoprocessorEnvironment> e,
    byte[] row, byte[] family, byte[] qualifier, CompareOperator compareOp,
    ByteArrayComparable comparator, Delete delete, boolean result) throws IOException {
  ctPreCheckAndDeleteAfterRowLock.incrementAndGet();
  return true;
}