Java 类org.apache.hadoop.hbase.filter.CompareFilter 实例源码

项目:aliyun-tablestore-hbase-client    文件:TablestoreTable.java   
@Override
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value, Delete delete) throws IOException {
    if (!Arrays.equals(delete.getRow(), row)) {
        throw new UnsupportedOperationException("CheckAndDelete does not support check one row but delete other row");
    }


    ODelete odelete = ElementConvertor.toOtsDelete(delete, this.tablestoreColumnMapping);
    Condition condition = ElementConvertor.toOtsCondition(family, qualifier, compareOp, value, this.tablestoreColumnMapping);
    odelete.setCondition(condition);

    try {
        this.tablestoreAdaptor.delete(tableNameStr, odelete);
    } catch (IOException ex) {
        if (ex.getCause().getCause() instanceof TableStoreException) {
            TableStoreException exception = (TableStoreException)ex.getCause().getCause();
            if (exception.getErrorCode().equals("OTSConditionCheckFail")) {
                return false;
            }
        }
        throw ex;
    }
    return true;
}
项目:aliyun-tablestore-hbase-client    文件:TablestoreTable.java   
@Override
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value, Put put) throws IOException {
    if (!Arrays.equals(put.getRow(), row)) {
        throw new UnsupportedOperationException("CheckAndPut does not support check one row but put other row");
    }

    OPut oput = ElementConvertor.toOtsPut(put, this.tablestoreColumnMapping);
    Condition condition = ElementConvertor.toOtsCondition(family, qualifier, compareOp, value, this.tablestoreColumnMapping);
    oput.setCondition(condition);

    try {
        this.tablestoreAdaptor.put(tableNameStr, oput);
    } catch (IOException ex) {
        if (ex.getCause().getCause() instanceof TableStoreException) {
            TableStoreException exception = (TableStoreException)ex.getCause().getCause();
            if (exception.getErrorCode().equals("OTSConditionCheckFail")) {
                return false;
            }
        }
        throw ex;
    }
    return true;
}
项目:aliyun-tablestore-hbase-client    文件:TablestoreTable.java   
@Override
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value, RowMutations mutation) throws IOException {
    if (!Arrays.equals(mutation.getRow(), row)) {
        throw new UnsupportedOperationException("CheckAndMutation does not support check one row but Mutate other row");
    }

    OUpdate oupdate = ElementConvertor.toOtsUpdate(mutation, this.tablestoreColumnMapping);
    Condition condition = ElementConvertor.toOtsCondition(family, qualifier, compareOp, value, this.tablestoreColumnMapping);
    oupdate.setCondition(condition);

    try {
        this.tablestoreAdaptor.update(tableNameStr, oupdate);
    } catch (IOException ex) {
        if (ex.getCause().getCause() instanceof TableStoreException) {
            TableStoreException exception = (TableStoreException)ex.getCause().getCause();
            if (exception.getErrorCode().equals("OTSConditionCheckFail")) {
                return false;
            }
        }
        throw ex;
    }
    return true;
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndMutate.java   
@Test
public void testCheckNullSucceeded() throws IOException {
    clean();

    Put put = new Put(Bytes.toBytes("pk0"));
    put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("col_1_var"));

    RowMutations mutaions = new RowMutations(Bytes.toBytes("pk0"));
    mutaions.add(put);

    table.checkAndMutate(Bytes.toBytes("pk0"), Bytes.toBytes(familyName), Bytes.toBytes("col_1"), CompareFilter.CompareOp.EQUAL,
            null, mutaions);

    Get get = new Get(Bytes.toBytes("pk0"));
    Result result = table.get(get);
    String value = Bytes.toString(result.getValue(Bytes.toBytes(familyName), Bytes.toBytes("col_1")));
    assertEquals("col_1_var", value);
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndMutate.java   
@Test
public void testMutationWithOneDelete() throws IOException {
    clean();

    Put put = new Put(Bytes.toBytes("pk0"));
    put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("col_1_var"));
    put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_2"), Bytes.toBytes("col_2_var"));
    table.put(put);


    Delete delete = new Delete(Bytes.toBytes("pk0"));
    delete.addColumns(Bytes.toBytes(familyName), Bytes.toBytes("col_2"));

    RowMutations mutaions = new RowMutations(Bytes.toBytes("pk0"));
    mutaions.add(delete);

    table.checkAndMutate(Bytes.toBytes("pk0"), Bytes.toBytes(familyName), Bytes.toBytes("col_1"), CompareFilter.CompareOp.GREATER_OR_EQUAL,
            Bytes.toBytes("col_1_var"), mutaions);

    Get get = new Get(Bytes.toBytes("pk0"));
    Result result = table.get(get);
    String value = Bytes.toString(result.getValue(Bytes.toBytes(familyName), Bytes.toBytes("col_1")));
    assertEquals("col_1_var", value);
    byte[] col2 = result.getValue(Bytes.toBytes(familyName), Bytes.toBytes("col_2"));
    assertTrue(col2 == null);
}
项目:aliyun-tablestore-hbase-client    文件:TestFilterList.java   
@Test
public void testTwoFilterWithMustAllPassFailed() throws IOException {
    clean();
    {
        Put put = new Put(Bytes.toBytes(rowPrefix));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("col_1_var"));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_2"), Bytes.toBytes("col_2_var"));
        table.put(put);
    }

    {
        Get get = new Get(Bytes.toBytes(rowPrefix));
        Filter filter1 = new SingleColumnValueFilter(Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
                CompareFilter.CompareOp.EQUAL, Bytes.toBytes("col_1_var"));
        Filter filter2 = new SingleColumnValueFilter(Bytes.toBytes(familyName), Bytes.toBytes("col_2"),
                CompareFilter.CompareOp.NOT_EQUAL, Bytes.toBytes("col_2_var"));
        FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
        filterList.addFilter(filter1);
        filterList.addFilter(filter2);

        get.setFilter(filterList);
        Result result = table.get(get);
        assertTrue(result.getRow() == null);
    }
}
项目:aliyun-tablestore-hbase-client    文件:TestFilterList.java   
@Test
public void testTwoFilterWithMustOnePassFailed() throws IOException {
    clean();
    {
        Put put = new Put(Bytes.toBytes(rowPrefix));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("col_1_var"));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_2"), Bytes.toBytes("col_2_var"));
        table.put(put);
    }

    {
        Get get = new Get(Bytes.toBytes(rowPrefix));
        Filter filter1 = new SingleColumnValueFilter(Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
                CompareFilter.CompareOp.NOT_EQUAL, Bytes.toBytes("col_1_var"));
        Filter filter2 = new SingleColumnValueFilter(Bytes.toBytes(familyName), Bytes.toBytes("col_2"),
                CompareFilter.CompareOp.NOT_EQUAL, Bytes.toBytes("col_2_var"));
        FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
        filterList.addFilter(filter1);
        filterList.addFilter(filter2);

        get.setFilter(filterList);
        Result result = table.get(get);
        assertTrue(result.getRow() == null);
    }
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndDeleteRow.java   
@Test
public void testEqualAndSuccess2() throws IOException {
    clean();

    String row = rowPrefix;
    {
        Put put = new Put(Bytes.toBytes(row));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("val_1"));

        table.put(put);
    }

    Delete delete = new Delete(Bytes.toBytes(row));

    boolean ret = table.checkAndDelete(Bytes.toBytes(row), Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
            CompareFilter.CompareOp.EQUAL, Bytes.toBytes("val_1"), delete);
    assertTrue(ret);

    Get get = new Get(Bytes.toBytes(row));
    byte[] result = table.get(get).getRow();
    assertTrue(result == null);
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndDeleteRow.java   
@Test
public void testEqualAndFailed2() throws IOException {
    clean();

    String row = rowPrefix;
    {
        Put put = new Put(Bytes.toBytes(row));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("val_1"));

        table.put(put);
    }

    Delete delete = new Delete(Bytes.toBytes(row));

    boolean ret = table.checkAndDelete(Bytes.toBytes(row), Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
            CompareFilter.CompareOp.EQUAL, Bytes.toBytes("val_3"), delete);
    assertTrue(!ret);

    Get get = new Get(Bytes.toBytes(row));
    byte[] result = table.get(get).getRow();
    assertTrue(result != null);
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndDeleteRow.java   
@Test
public void testNotEqualAndSuccess() throws IOException {
    clean();

    String row = rowPrefix;
    {
        Put put = new Put(Bytes.toBytes(row));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("val_1"));

        table.put(put);
    }

    Delete delete = new Delete(Bytes.toBytes(row));

    boolean ret = table.checkAndDelete(Bytes.toBytes(row), Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
            CompareFilter.CompareOp.NOT_EQUAL, Bytes.toBytes("val_3"), delete);
    assertTrue(ret);

    Get get = new Get(Bytes.toBytes(row));
    byte[] result = table.get(get).getRow();
    assertTrue(result == null);
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndDeleteRow.java   
@Test
public void testNotEqualAndFailed() throws IOException {
    clean();

    String row = rowPrefix;
    {
        Put put = new Put(Bytes.toBytes(row));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("val_1"));

        table.put(put);
    }

    Delete delete = new Delete(Bytes.toBytes(row));

    boolean ret = table.checkAndDelete(Bytes.toBytes(row), Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
            CompareFilter.CompareOp.NOT_EQUAL, Bytes.toBytes("val_1"), delete);
    assertTrue(!ret);

    Get get = new Get(Bytes.toBytes(row));
    byte[] result = table.get(get).getRow();
    assertTrue(result != null);
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndDeleteRow.java   
@Test
public void testGreaterAndSuccess() throws IOException {
    clean();

    String row = rowPrefix;
    {
        Put put = new Put(Bytes.toBytes(row));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("val_1"));

        table.put(put);
    }

    Delete delete = new Delete(Bytes.toBytes(row));

    boolean ret = table.checkAndDelete(Bytes.toBytes(row), Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
            CompareFilter.CompareOp.GREATER, Bytes.toBytes("val_0"), delete);
    assertTrue(ret);

    Get get = new Get(Bytes.toBytes(row));
    byte[] result = table.get(get).getRow();
    assertTrue(result == null);
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndDeleteRow.java   
@Test
public void testGreaterAndFailed() throws IOException {
    clean();

    String row = rowPrefix;
    {
        Put put = new Put(Bytes.toBytes(row));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("val_1"));

        table.put(put);
    }

    Delete  delete = new Delete(Bytes.toBytes(row));

    boolean ret = table.checkAndDelete(Bytes.toBytes(row), Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
            CompareFilter.CompareOp.GREATER, Bytes.toBytes("val_1"), delete);
    assertTrue(!ret);

    Get get = new Get(Bytes.toBytes(row));
    byte[] result = table.get(get).getRow();
    assertTrue(result != null);
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndDeleteRow.java   
@Test
public void testGreaterOrEqualAndSuccess() throws IOException {
    clean();

    String row = rowPrefix;
    {
        Put put = new Put(Bytes.toBytes(row));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("val_1"));

        table.put(put);
    }

    Delete delete = new Delete(Bytes.toBytes(row));

    boolean ret = table.checkAndDelete(Bytes.toBytes(row), Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
            CompareFilter.CompareOp.GREATER_OR_EQUAL, Bytes.toBytes("val_0"), delete);
    assertTrue(ret);

    Get get = new Get(Bytes.toBytes(row));
    byte[] result = table.get(get).getRow();
    assertTrue(result == null);
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndDeleteRow.java   
@Test
public void testGreaterOrEqualAndFailed() throws IOException {
    clean();

    String row = rowPrefix;
    {
        Put put = new Put(Bytes.toBytes(row));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("val_1"));

        table.put(put);
    }

    Delete delete = new Delete(Bytes.toBytes(row));

    boolean ret = table.checkAndDelete(Bytes.toBytes(row), Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
            CompareFilter.CompareOp.GREATER_OR_EQUAL, Bytes.toBytes("val_4"), delete);
    assertTrue(!ret);

    Get get = new Get(Bytes.toBytes(row));
    byte[] result = table.get(get).getRow();
    assertTrue(result != null);
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndDeleteRow.java   
@Test
public void testLessAndSuccess() throws IOException {
    clean();

    String row = rowPrefix;
    {
        Put put = new Put(Bytes.toBytes(row));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("val_1"));

        table.put(put);
    }

    Delete delete = new Delete(Bytes.toBytes(row));

    boolean ret = table.checkAndDelete(Bytes.toBytes(row), Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
            CompareFilter.CompareOp.LESS, Bytes.toBytes("val_5"), delete);
    assertTrue(ret);

    Get get = new Get(Bytes.toBytes(row));
    byte[] result = table.get(get).getRow();
    assertTrue(result == null);
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndDeleteRow.java   
@Test
public void testLessAndFailed() throws IOException {
    clean();

    String row = rowPrefix;
    {
        Put put = new Put(Bytes.toBytes(row));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("val_1"));

        table.put(put);
    }

    Delete delete = new Delete(Bytes.toBytes(row));

    boolean ret = table.checkAndDelete(Bytes.toBytes(row), Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
            CompareFilter.CompareOp.LESS, Bytes.toBytes("val_0"), delete);
    assertTrue(!ret);

    Get get = new Get(Bytes.toBytes(row));
    byte[] result = table.get(get).getRow();
    assertTrue(result != null);
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndDeleteRow.java   
@Test
public void testLessOrEqualAndSuccess() throws IOException {
    clean();

    String row = rowPrefix;
    {
        Put put = new Put(Bytes.toBytes(row));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("val_1"));

        table.put(put);
    }

    Delete delete = new Delete(Bytes.toBytes(row));

    boolean ret = table.checkAndDelete(Bytes.toBytes(row), Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
            CompareFilter.CompareOp.LESS_OR_EQUAL, Bytes.toBytes("val_5"), delete);
    assertTrue(ret);

    Get get = new Get(Bytes.toBytes(row));
    byte[] result = table.get(get).getRow();
    assertTrue(result == null);
}
项目:aliyun-tablestore-hbase-client    文件:TestCheckAndDeleteRow.java   
@Test
public void testLessOrEqualAndFailed() throws IOException {
    clean();

    String row = rowPrefix;
    {
        Put put = new Put(Bytes.toBytes(row));
        put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_1"), Bytes.toBytes("val_1"));

        table.put(put);
    }

    Delete delete = new Delete(Bytes.toBytes(row));

    boolean ret = table.checkAndDelete(Bytes.toBytes(row), Bytes.toBytes(familyName), Bytes.toBytes("col_1"),
            CompareFilter.CompareOp.LESS_OR_EQUAL, Bytes.toBytes("val_0"), delete);
    assertTrue(!ret);

    Get get = new Get(Bytes.toBytes(row));
    byte[] result = table.get(get).getRow();
    assertTrue(result != null);
}
项目:ditb    文件:LMDTester.java   
private void doRawScan() throws IOException {
  FilterList filterList = new FilterList();
  CompareFilter.CompareOp startOp = CompareFilter.CompareOp.GREATER_OR_EQUAL;
  CompareFilter.CompareOp stopOp = CompareFilter.CompareOp.LESS_OR_EQUAL;
  for (int i = 0; i < indexColumnNames.length && i < scanValues.length; i++) {
    filterList.addFilter(
        new SingleColumnValueFilter(familyName, Bytes.toBytes(indexColumnNames[i]), startOp,
            Bytes.toBytes(scanValues[i][0])));
    filterList.addFilter(
        new SingleColumnValueFilter(familyName, Bytes.toBytes(indexColumnNames[i]), stopOp,
            Bytes.toBytes(scanValues[i][1])));
  }
  Scan scan = new Scan();
  scan.setFilter(filterList);
  scan.setId("raw-scan");
  Table table = conn.getTable(tableName);
  ResultScanner scanner = table.getScanner(scan);
  Result result;
  int count = 0;
  while ((result = scanner.next()) != null) {
    ++count;
    if (PRINT_RESULT) printResult(result);
  }
  scanner.close();
  System.out.println("raw scan has " + count + " records");
}
项目:ditb    文件:AccessController.java   
@Override
public boolean preCheckAndPutAfterRowLock(final ObserverContext<RegionCoprocessorEnvironment> c,
    final byte[] row, final byte[] family, final byte[] qualifier,
    final CompareFilter.CompareOp compareOp, final ByteArrayComparable comparator, final Put put,
    final boolean result) throws IOException {
  if (put.getAttribute(CHECK_COVERING_PERM) != null) {
    // We had failure with table, cf and q perm checks and now giving a chance for cell
    // perm check
    TableName table = c.getEnvironment().getRegion().getRegionInfo().getTable();
    Map<byte[], ? extends Collection<byte[]>> families = makeFamilyMap(family, qualifier);
    AuthResult authResult = null;
    if (checkCoveringPermission(OpType.CHECK_AND_PUT, c.getEnvironment(), row, families,
        HConstants.LATEST_TIMESTAMP, Action.READ)) {
      authResult = AuthResult.allow(OpType.CHECK_AND_PUT.toString(), "Covering cell set",
          getActiveUser(), Action.READ, table, families);
    } else {
      authResult = AuthResult.deny(OpType.CHECK_AND_PUT.toString(), "Covering cell set",
          getActiveUser(), Action.READ, table, families);
    }
    logResult(authResult);
    if (authorizationEnabled && !authResult.isAllowed()) {
      throw new AccessDeniedException("Insufficient permissions " + authResult.toContextString());
    }
  }
  return result;
}
项目:ditb    文件:PerformanceEvaluation.java   
protected Scan constructScan(byte[] valuePrefix) throws IOException {
  FilterList list = new FilterList();
  Filter filter = new SingleColumnValueFilter(
      FAMILY_NAME, COLUMN_ZERO, CompareFilter.CompareOp.EQUAL,
      new BinaryComparator(valuePrefix)
  );
  list.addFilter(filter);
  if(opts.filterAll) {
    list.addFilter(new FilterAllFilter());
  }
  Scan scan = new Scan();
  scan.setCaching(opts.caching);
  if (opts.addColumns) {
    scan.addColumn(FAMILY_NAME, QUALIFIER_NAME);
  } else {
    scan.addFamily(FAMILY_NAME);
  }
  scan.setFilter(list);
  return scan;
}
项目:ditb    文件:TestFromClientSide.java   
@Test
public void testJira6912() throws Exception {
  TableName TABLE = TableName.valueOf("testJira6912");
  Table foo = TEST_UTIL.createTable(TABLE, new byte[][] {FAMILY}, 10);

  List<Put> puts = new ArrayList<Put>();
  for (int i=0;i !=100; i++){
    Put put = new Put(Bytes.toBytes(i));
    put.add(FAMILY, FAMILY, Bytes.toBytes(i));
    puts.add(put);
  }
  foo.put(puts);
  // If i comment this out it works
  TEST_UTIL.flush();

  Scan scan = new Scan();
  scan.setStartRow(Bytes.toBytes(1));
  scan.setStopRow(Bytes.toBytes(3));
  scan.addColumn(FAMILY, FAMILY);
  scan.setFilter(new RowFilter(CompareFilter.CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes(1))));

  ResultScanner scanner = foo.getScanner(scan);
  Result[] bar = scanner.next(100);
  assertEquals(1, bar.length);
}
项目:ditb    文件:TestJoinedScanners.java   
private void runScanner(Table table, boolean slow) throws Exception {
  long time = System.nanoTime();
  Scan scan = new Scan();
  scan.addColumn(cf_essential, col_name);
  scan.addColumn(cf_joined, col_name);

  SingleColumnValueFilter filter = new SingleColumnValueFilter(
      cf_essential, col_name, CompareFilter.CompareOp.EQUAL, flag_yes);
  filter.setFilterIfMissing(true);
  scan.setFilter(filter);
  scan.setLoadColumnFamiliesOnDemand(!slow);

  ResultScanner result_scanner = table.getScanner(scan);
  Result res;
  long rows_count = 0;
  while ((res = result_scanner.next()) != null) {
    rows_count++;
  }

  double timeSec = (System.nanoTime() - time) / 1000000000.0;
  result_scanner.close();
  LOG.info((slow ? "Slow" : "Joined") + " scanner finished in " + Double.toString(timeSec)
    + " seconds, got " + Long.toString(rows_count/2) + " rows");
}
项目:ditb    文件:ScanRange.java   
@Override public void readFields(DataInput in) throws IOException {
  family = Bytes.readByteArray(in);
  qualifier = Bytes.readByteArray(in);
  boolean startNull = Bytes.toBoolean(Bytes.readByteArray(in));
  if (startNull) {
    start = null;
    startOp = CompareFilter.CompareOp.NO_OP;
  } else {
    start = Bytes.readByteArray(in);
    startOp = CompareFilter.CompareOp.valueOf(Bytes.toString(Bytes.readByteArray(in)));
  }
  boolean stopNull = Bytes.toBoolean(Bytes.readByteArray(in));
  if (stopNull) {
    stop = null;
    stopOp = CompareFilter.CompareOp.NO_OP;
  } else {
    stop = Bytes.readByteArray(in);
    stopOp = CompareFilter.CompareOp.valueOf(Bytes.toString(Bytes.readByteArray(in)));
  }
  startTs = in.readLong();
  stopTs = in.readLong();
  dataType = DataType.valueOf(Bytes.toString(Bytes.readByteArray(in)));
}
项目:tephra    文件:HbaseQuery.java   
protected CompareFilter.CompareOp getCompare(Where where) {
    if (where == Where.Equals)
        return CompareFilter.CompareOp.EQUAL;

    if (where == Where.NotEquals)
        return CompareFilter.CompareOp.NOT_EQUAL;

    if (where == Where.Less)
        return CompareFilter.CompareOp.LESS;

    if (where == Where.LessEquals)
        return CompareFilter.CompareOp.LESS_OR_EQUAL;

    if (where == Where.Greater)
        return CompareFilter.CompareOp.GREATER;

    if (where == Where.GreaterEquals)
        return CompareFilter.CompareOp.GREATER_OR_EQUAL;

    return CompareFilter.CompareOp.EQUAL;
}
项目:envelope    文件:DefaultHBaseSerde.java   
private FilterList getColumnValueFilters(Row row) {
  FilterList filterList = new FilterList(Operator.MUST_PASS_ALL);
  Set<String> filterColumnNames = Sets.newHashSet(row.schema().fieldNames());

  for (Map.Entry<String, ColumnDef> column : columns.entrySet()) {
    if (!column.getValue().cf.equals("rowkey")) {
      if (filterColumnNames.contains(column.getKey())) {
        byte[] value = getColumnValueAsBytes(column.getValue().name, column.getValue().type, row);
        if (value != null) {
          SingleColumnValueFilter columnValueFilter = new SingleColumnValueFilter(
              Bytes.toBytes(column.getValue().cf),
              Bytes.toBytes(column.getValue().name),
              CompareFilter.CompareOp.EQUAL,
              value
          );
          filterList.addFilter(columnValueFilter);
        }
      }
    }
  }

  return filterList;
}
项目:Camel    文件:ModelAwareColumnMatchingFilter.java   
/**
 * Applies the message to {@link org.apache.hadoop.hbase.filter.Filter} to context.
 */
@Override
public void apply(CamelContext context, HBaseRow rowModel) {
    fl.getFilters().clear();
    if (rowModel != null) {
        for (HBaseCell cell : rowModel.getCells()) {
            if (cell.getValue() != null) {
                byte[] family = HBaseHelper.getHBaseFieldAsBytes(cell.getFamily());
                byte[] qualifier = HBaseHelper.getHBaseFieldAsBytes(cell.getQualifier());
                byte[] value = context.getTypeConverter().convertTo(byte[].class, cell.getValue());
                SingleColumnValueFilter columnValueFilter = new SingleColumnValueFilter(family, qualifier, CompareFilter.CompareOp.EQUAL, value);
                fl.addFilter(columnValueFilter);
            }
        }
    }
}
项目:LCIndex-HBase-0.94.16    文件:TestFromClientSide.java   
@Test
public void testJira6912() throws Exception {
  byte [] TABLE = Bytes.toBytes("testJira6912");
  HTable foo = TEST_UTIL.createTable(TABLE, new byte[][] {FAMILY}, 10);

  List<Put> puts = new ArrayList<Put>();
  for (int i=0;i !=100; i++){
    Put put = new Put(Bytes.toBytes(i));
    put.add(FAMILY, FAMILY, Bytes.toBytes(i));
    puts.add(put);
  }
  foo.put(puts);
  // If i comment this out it works
  TEST_UTIL.flush();

  Scan scan = new Scan();
  scan.setStartRow(Bytes.toBytes(1));
  scan.setStopRow(Bytes.toBytes(3));
  scan.addColumn(FAMILY, FAMILY);
  scan.setFilter(new RowFilter(CompareFilter.CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes(1))));

  ResultScanner scanner = foo.getScanner(scan);
  Result[] bar = scanner.next(100);
  assertEquals(1, bar.length);
}
项目:knowledge    文件:AbstractQueryStrategy.java   
protected void addTimeConstraints(Scan scan)
{
    List<Filter> filters = new ArrayList<>();

    if(context.getQuery().getAfter() != null)
    {
        filters.add(new SingleColumnValueFilter(Schema.F_INFO, Schema.Q_EPOCH, CompareFilter.CompareOp.GREATER_OR_EQUAL, Bytes.toBytes(context.getQuery().getAfter())));
    }

    if(context.getQuery().getBefore() != null)
    {
        filters.add(new SingleColumnValueFilter(Schema.F_INFO, Schema.Q_EPOCH, CompareFilter.CompareOp.LESS_OR_EQUAL, Bytes.toBytes(context.getQuery().getBefore())));
    }

    if(!filters.isEmpty())
    {
        FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL, filters);
        scan.setFilter(filterList);
    }
}
项目:knowledge    文件:PostfixFilter.java   
public static PostfixFilter parseFrom(final byte[] bytes) throws DeserializationException
{
    CustomFilterProtos.PostfixFilter proto;
    try
    {
        proto = CustomFilterProtos.PostfixFilter.parseFrom(bytes);
    }
    catch (InvalidProtocolBufferException e)
    {
        throw new DeserializationException(e);
    }

    final CompareFilter.CompareOp compareOp = CompareFilter.CompareOp.values()[proto.getCompareOp()];
    final int offset = proto.getOffset();
    final byte[] postfix = proto.getPostfix().toByteArray();

    return new PostfixFilter(compareOp, postfix, offset);
}
项目:cloud-bigtable-client    文件:TestSingleColumnValueFilterAdapter.java   
@Test
public void latestVersionOnlyComparisonsAreDone() throws IOException {
  byte[] filterValue = Bytes.toBytes("foobar");
  byte[] qualifier = Bytes.toBytes("someColumn");
  byte[] family = Bytes.toBytes("f");

  SingleColumnValueFilter filter = new SingleColumnValueFilter(
      family,
      qualifier,
      CompareFilter.CompareOp.EQUAL,
      new BinaryComparator(filterValue));

  filter.setFilterIfMissing(false);
  filter.setLatestVersionOnly(true);

  RowFilter adaptedFilter = adapter.adapt(
      new FilterAdapterContext(new Scan()),
      filter);

  assertFilterIfNotMIssingMatches(
      family,
      qualifier,
      filterValue,
      1 /* latest version only = true */,
      adaptedFilter);
}
项目:cloud-bigtable-client    文件:TestSingleColumnValueFilterAdapter.java   
@Test
public void allVersionComparisonAreDone() throws IOException {
  byte[] filterValue = Bytes.toBytes("foobar");
  byte[] qualifier = Bytes.toBytes("someColumn");
  byte[] family = Bytes.toBytes("f");

  SingleColumnValueFilter filter = new SingleColumnValueFilter(
      family,
      qualifier,
      CompareFilter.CompareOp.EQUAL,
      new BinaryComparator(filterValue));

  filter.setFilterIfMissing(false);
  filter.setLatestVersionOnly(false);

  RowFilter adaptedFilter = adapter.adapt(
      new FilterAdapterContext(new Scan()),
      filter);

  assertFilterIfNotMIssingMatches(
      family,
      qualifier,
      filterValue,
      Integer.MAX_VALUE /* latest version only = false */,
      adaptedFilter);
}
项目:pbase    文件:AccessController.java   
@Override
public boolean preCheckAndPutAfterRowLock(final ObserverContext<RegionCoprocessorEnvironment> c,
    final byte[] row, final byte[] family, final byte[] qualifier,
    final CompareFilter.CompareOp compareOp, final ByteArrayComparable comparator, final Put put,
    final boolean result) throws IOException {
  if (put.getAttribute(CHECK_COVERING_PERM) != null) {
    // We had failure with table, cf and q perm checks and now giving a chance for cell
    // perm check
    TableName table = c.getEnvironment().getRegion().getRegionInfo().getTable();
    Map<byte[], ? extends Collection<byte[]>> families = makeFamilyMap(family, qualifier);
    AuthResult authResult = null;
    if (checkCoveringPermission(OpType.CHECK_AND_PUT, c.getEnvironment(), row, families,
        HConstants.LATEST_TIMESTAMP, Action.READ)) {
      authResult = AuthResult.allow(OpType.CHECK_AND_PUT.toString(), "Covering cell set",
          getActiveUser(), Action.READ, table, families);
    } else {
      authResult = AuthResult.deny(OpType.CHECK_AND_PUT.toString(), "Covering cell set",
          getActiveUser(), Action.READ, table, families);
    }
    logResult(authResult);
    if (!authResult.isAllowed()) {
      throw new AccessDeniedException("Insufficient permissions " + authResult.toContextString());
    }
  }
  return result;
}
项目:pbase    文件:TestFromClientSide.java   
@Test
public void testJira6912() throws Exception {
  TableName TABLE = TableName.valueOf("testJira6912");
  Table foo = TEST_UTIL.createTable(TABLE, new byte[][] {FAMILY}, 10);

  List<Put> puts = new ArrayList<Put>();
  for (int i=0;i !=100; i++){
    Put put = new Put(Bytes.toBytes(i));
    put.add(FAMILY, FAMILY, Bytes.toBytes(i));
    puts.add(put);
  }
  foo.put(puts);
  // If i comment this out it works
  TEST_UTIL.flush();

  Scan scan = new Scan();
  scan.setStartRow(Bytes.toBytes(1));
  scan.setStopRow(Bytes.toBytes(3));
  scan.addColumn(FAMILY, FAMILY);
  scan.setFilter(new RowFilter(CompareFilter.CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes(1))));

  ResultScanner scanner = foo.getScanner(scan);
  Result[] bar = scanner.next(100);
  assertEquals(1, bar.length);
}
项目:pbase    文件:TestJoinedScanners.java   
private void runScanner(Table table, boolean slow) throws Exception {
  long time = System.nanoTime();
  Scan scan = new Scan();
  scan.addColumn(cf_essential, col_name);
  scan.addColumn(cf_joined, col_name);

  SingleColumnValueFilter filter = new SingleColumnValueFilter(
      cf_essential, col_name, CompareFilter.CompareOp.EQUAL, flag_yes);
  filter.setFilterIfMissing(true);
  scan.setFilter(filter);
  scan.setLoadColumnFamiliesOnDemand(!slow);

  ResultScanner result_scanner = table.getScanner(scan);
  Result res;
  long rows_count = 0;
  while ((res = result_scanner.next()) != null) {
    rows_count++;
  }

  double timeSec = (System.nanoTime() - time) / 1000000000.0;
  result_scanner.close();
  LOG.info((slow ? "Slow" : "Joined") + " scanner finished in " + Double.toString(timeSec)
    + " seconds, got " + Long.toString(rows_count/2) + " rows");
}
项目:HIndex    文件:TestFromClientSide.java   
@Test
public void testJira6912() throws Exception {
  byte [] TABLE = Bytes.toBytes("testJira6912");
  HTable foo = TEST_UTIL.createTable(TABLE, new byte[][] {FAMILY}, 10);

  List<Put> puts = new ArrayList<Put>();
  for (int i=0;i !=100; i++){
    Put put = new Put(Bytes.toBytes(i));
    put.add(FAMILY, FAMILY, Bytes.toBytes(i));
    puts.add(put);
  }
  foo.put(puts);
  // If i comment this out it works
  TEST_UTIL.flush();

  Scan scan = new Scan();
  scan.setStartRow(Bytes.toBytes(1));
  scan.setStopRow(Bytes.toBytes(3));
  scan.addColumn(FAMILY, FAMILY);
  scan.setFilter(new RowFilter(CompareFilter.CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes(1))));

  ResultScanner scanner = foo.getScanner(scan);
  Result[] bar = scanner.next(100);
  assertEquals(1, bar.length);
}
项目:HIndex    文件:TestJoinedScanners.java   
private void runScanner(HTable table, boolean slow) throws Exception {
  long time = System.nanoTime();
  Scan scan = new Scan();
  scan.addColumn(cf_essential, col_name);
  scan.addColumn(cf_joined, col_name);

  SingleColumnValueFilter filter = new SingleColumnValueFilter(
      cf_essential, col_name, CompareFilter.CompareOp.EQUAL, flag_yes);
  filter.setFilterIfMissing(true);
  scan.setFilter(filter);
  scan.setLoadColumnFamiliesOnDemand(!slow);

  ResultScanner result_scanner = table.getScanner(scan);
  Result res;
  long rows_count = 0;
  while ((res = result_scanner.next()) != null) {
    rows_count++;
  }

  double timeSec = (System.nanoTime() - time) / 1000000000.0;
  result_scanner.close();
  LOG.info((slow ? "Slow" : "Joined") + " scanner finished in " + Double.toString(timeSec)
    + " seconds, got " + Long.toString(rows_count/2) + " rows");
}
项目:IRIndex    文件:TestFromClientSide.java   
@Test
public void testJira6912() throws Exception {
  byte [] TABLE = Bytes.toBytes("testJira6912");
  HTable foo = TEST_UTIL.createTable(TABLE, new byte[][] {FAMILY}, 10);

  List<Put> puts = new ArrayList<Put>();
  for (int i=0;i !=100; i++){
    Put put = new Put(Bytes.toBytes(i));
    put.add(FAMILY, FAMILY, Bytes.toBytes(i));
    puts.add(put);
  }
  foo.put(puts);
  // If i comment this out it works
  TEST_UTIL.flush();

  Scan scan = new Scan();
  scan.setStartRow(Bytes.toBytes(1));
  scan.setStopRow(Bytes.toBytes(3));
  scan.addColumn(FAMILY, FAMILY);
  scan.setFilter(new RowFilter(CompareFilter.CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes(1))));

  ResultScanner scanner = foo.getScanner(scan);
  Result[] bar = scanner.next(100);
  assertEquals(1, bar.length);
}
项目:hbase    文件:TestJoinedScanners.java   
private void runScanner(Table table, boolean slow) throws Exception {
  long time = System.nanoTime();
  Scan scan = new Scan();
  scan.addColumn(cf_essential, col_name);
  scan.addColumn(cf_joined, col_name);

  SingleColumnValueFilter filter = new SingleColumnValueFilter(
      cf_essential, col_name, CompareFilter.CompareOp.EQUAL, flag_yes);
  filter.setFilterIfMissing(true);
  scan.setFilter(filter);
  scan.setLoadColumnFamiliesOnDemand(!slow);

  ResultScanner result_scanner = table.getScanner(scan);
  Result res;
  long rows_count = 0;
  while ((res = result_scanner.next()) != null) {
    rows_count++;
  }

  double timeSec = (System.nanoTime() - time) / 1000000000.0;
  result_scanner.close();
  LOG.info((slow ? "Slow" : "Joined") + " scanner finished in " + Double.toString(timeSec)
    + " seconds, got " + Long.toString(rows_count/2) + " rows");
}