use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project hadoop by apache.
the class TimelineFilterUtils method createHBaseSingleColValueFilter.
/**
* Creates a HBase {@link SingleColumnValueFilter}.
*
* @param columnFamily Column Family represented as bytes.
* @param columnQualifier Column Qualifier represented as bytes.
* @param value Value.
* @param compareOp Compare operator.
* @param filterIfMissing This flag decides if we should filter the row if the
* specified column is missing. This is based on the filter's keyMustExist
* field.
* @return a {@link SingleColumnValueFilter} object
* @throws IOException
*/
private static SingleColumnValueFilter createHBaseSingleColValueFilter(byte[] columnFamily, byte[] columnQualifier, byte[] value, CompareOp compareOp, boolean filterIfMissing) throws IOException {
SingleColumnValueFilter singleColValFilter = new SingleColumnValueFilter(columnFamily, columnQualifier, compareOp, new BinaryComparator(value));
singleColValFilter.setLatestVersionOnly(true);
singleColValFilter.setFilterIfMissing(filterIfMissing);
return singleColValFilter;
}
use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project hbase by apache.
the class ReplicationTableBase method getQueuesBelongingToServer.
/**
* Get the queue id's and meta data (Owner and History) for the queues belonging to the named
* server
*
* @param server name of the server
* @return a ResultScanner over the QueueIds belonging to the server
* @throws IOException
*/
protected ResultScanner getQueuesBelongingToServer(String server) throws IOException {
Scan scan = new Scan();
SingleColumnValueFilter filterMyQueues = new SingleColumnValueFilter(CF_QUEUE, COL_QUEUE_OWNER, CompareFilter.CompareOp.EQUAL, Bytes.toBytes(server));
scan.setFilter(filterMyQueues);
scan.addColumn(CF_QUEUE, COL_QUEUE_OWNER);
scan.addColumn(CF_QUEUE, COL_QUEUE_OWNER_HISTORY);
try (Table replicationTable = getOrBlockOnReplicationTable()) {
ResultScanner results = replicationTable.getScanner(scan);
return results;
}
}
use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project hbase by apache.
the class TableBasedReplicationQueuesImpl method getResultIfOwner.
/**
* Attempts to run a Get on some queue. Will only return a non-null result if we currently own
* the queue.
*
* @param get The Get that we want to query
* @return The result of the Get if this server is the owner of the queue. Else it returns null.
* @throws IOException
*/
private Result getResultIfOwner(Get get) throws IOException {
Scan scan = new Scan(get);
// Check if the Get currently contains all columns or only specific columns
if (scan.getFamilyMap().size() > 0) {
// Add the OWNER column if the scan is already only over specific columns
scan.addColumn(CF_QUEUE, COL_QUEUE_OWNER);
}
scan.setMaxResultSize(1);
SingleColumnValueFilter checkOwner = new SingleColumnValueFilter(CF_QUEUE, COL_QUEUE_OWNER, CompareFilter.CompareOp.EQUAL, serverNameBytes);
scan.setFilter(checkOwner);
ResultScanner scanner = null;
try (Table replicationTable = getOrBlockOnReplicationTable()) {
scanner = replicationTable.getScanner(scan);
Result result = scanner.next();
return (result == null || result.isEmpty()) ? null : result;
} finally {
if (scanner != null) {
scanner.close();
}
}
}
use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project hbase by apache.
the class TestFromClientSide method buildScanner.
private ResultScanner buildScanner(String keyPrefix, String value, Table ht) throws IOException {
// OurFilterList allFilters = new OurFilterList();
FilterList allFilters = new FilterList();
allFilters.addFilter(new PrefixFilter(Bytes.toBytes(keyPrefix)));
SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes("trans-tags"), Bytes.toBytes("qual2"), CompareOp.EQUAL, Bytes.toBytes(value));
filter.setFilterIfMissing(true);
allFilters.addFilter(filter);
// allFilters.addFilter(new
// RowExcludingSingleColumnValueFilter(Bytes.toBytes("trans-tags"),
// Bytes.toBytes("qual2"), CompareOp.EQUAL, Bytes.toBytes(value)));
Scan scan = new Scan();
scan.addFamily(Bytes.toBytes("trans-blob"));
scan.addFamily(Bytes.toBytes("trans-type"));
scan.addFamily(Bytes.toBytes("trans-date"));
scan.addFamily(Bytes.toBytes("trans-tags"));
scan.addFamily(Bytes.toBytes("trans-group"));
scan.setFilter(allFilters);
return ht.getScanner(scan);
}
use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project cxf by apache.
the class HBaseQueryVisitor method buildSimpleQuery.
private Filter buildSimpleQuery(ConditionType ct, String name, Object value) {
name = super.getRealPropertyName(name);
validatePropertyValue(name, value);
Class<?> clazz = getPrimitiveFieldClass(name, value.getClass());
CompareOp compareOp = null;
boolean regexCompRequired = false;
switch(ct) {
case EQUALS:
compareOp = CompareOp.EQUAL;
regexCompRequired = String.class == clazz && value.toString().endsWith("*");
break;
case NOT_EQUALS:
compareOp = CompareOp.NOT_EQUAL;
regexCompRequired = String.class == clazz && value.toString().endsWith("*");
break;
case GREATER_THAN:
compareOp = CompareOp.GREATER;
break;
case GREATER_OR_EQUALS:
compareOp = CompareOp.GREATER_OR_EQUAL;
break;
case LESS_THAN:
compareOp = CompareOp.LESS;
break;
case LESS_OR_EQUALS:
compareOp = CompareOp.LESS_OR_EQUAL;
break;
default:
break;
}
String qualifier = name;
String theFamily = family != null ? family : familyMap.get(qualifier);
ByteArrayComparable byteArrayComparable = regexCompRequired ? new RegexStringComparator(value.toString().replace("*", ".")) : new BinaryComparator(value.toString().getBytes(StandardCharsets.UTF_8));
return new SingleColumnValueFilter(theFamily.getBytes(StandardCharsets.UTF_8), qualifier.getBytes(StandardCharsets.UTF_8), compareOp, byteArrayComparable);
}
Aggregations