Java 类org.apache.hadoop.hbase.filter.Filter 实例源码
项目:SparkDemo
文件:MyClass.java
public static void QueryByCondition2(String tableName) {
try {
HTablePool pool = new HTablePool(configuration, 1000);
HTable table = (HTable) pool.getTable(tableName);
Filter filter = new SingleColumnValueFilter(Bytes
.toBytes("column1"), null, CompareOp.EQUAL, Bytes
.toBytes("aaa")); // 当列column1的值为aaa时进行查询
Scan s = new Scan();
s.setFilter(filter);
ResultScanner rs = table.getScanner(s);
for (Result r : rs) {
System.out.println("获得到rowkey:" + new String(r.getRow()));
for (KeyValue keyValue : r.raw()) {
System.out.println("列:" + new String(keyValue.getFamily())
+ "====值:" + new String(keyValue.getValue()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
项目:QDrill
文件:HBaseFilterBuilder.java
private HBaseScanSpec mergeScanSpecs(String functionName, HBaseScanSpec leftScanSpec, HBaseScanSpec rightScanSpec) {
Filter newFilter = null;
byte[] startRow = HConstants.EMPTY_START_ROW;
byte[] stopRow = HConstants.EMPTY_END_ROW;
switch (functionName) {
case "booleanAnd":
newFilter = HBaseUtils.andFilterAtIndex(leftScanSpec.filter, HBaseUtils.LAST_FILTER, rightScanSpec.filter);
startRow = HBaseUtils.maxOfStartRows(leftScanSpec.startRow, rightScanSpec.startRow);
stopRow = HBaseUtils.minOfStopRows(leftScanSpec.stopRow, rightScanSpec.stopRow);
break;
case "booleanOr":
newFilter = HBaseUtils.orFilterAtIndex(leftScanSpec.filter, HBaseUtils.LAST_FILTER, rightScanSpec.filter);
startRow = HBaseUtils.minOfStartRows(leftScanSpec.startRow, rightScanSpec.startRow);
stopRow = HBaseUtils.maxOfStopRows(leftScanSpec.stopRow, rightScanSpec.stopRow);
}
return new HBaseScanSpec(groupScan.getTableName(), startRow, stopRow, newFilter);
}
项目:QDrill
文件:HBaseUtils.java
public static Filter andFilterAtIndex(Filter currentFilter, int index, Filter newFilter) {
if (currentFilter == null) {
return newFilter;
} else if (newFilter == null) {
return currentFilter;
}
List<Filter> allFilters = Lists.newArrayList();
if (currentFilter instanceof FilterList && ((FilterList)currentFilter).getOperator() == FilterList.Operator.MUST_PASS_ALL) {
allFilters.addAll(((FilterList)currentFilter).getFilters());
} else {
allFilters.add(currentFilter);
}
allFilters.add((index == LAST_FILTER ? allFilters.size() : index), newFilter);
return new FilterList(FilterList.Operator.MUST_PASS_ALL, allFilters);
}
项目:QDrill
文件:HBaseUtils.java
public static Filter orFilterAtIndex(Filter currentFilter, int index, Filter newFilter) {
if (currentFilter == null) {
return newFilter;
} else if (newFilter == null) {
return currentFilter;
}
List<Filter> allFilters = Lists.newArrayList();
if (currentFilter instanceof FilterList && ((FilterList)currentFilter).getOperator() == FilterList.Operator.MUST_PASS_ONE) {
allFilters.addAll(((FilterList)currentFilter).getFilters());
} else {
allFilters.add(currentFilter);
}
allFilters.add((index == LAST_FILTER ? allFilters.size() : index), newFilter);
return new FilterList(FilterList.Operator.MUST_PASS_ONE, allFilters);
}
项目:dremio-oss
文件:HBaseFilterBuilder.java
public HBaseScanSpec parseTree() {
HBaseScanSpec parsedSpec = le.accept(this, null);
if (parsedSpec != null) {
parsedSpec = mergeScanSpecs("booleanAnd", this.groupScan.getHBaseScanSpec(), parsedSpec);
/*
* If RowFilter is THE filter attached to the scan specification,
* remove it since its effect is also achieved through startRow and stopRow.
*/
Filter parsedFilter = HBaseUtils.deserializeFilter(parsedSpec.filter);
if (parsedFilter instanceof RowFilter &&
((RowFilter)parsedFilter).getComparator() instanceof BinaryComparator) {
parsedSpec.filter = null;
}
}
return parsedSpec;
}
项目:dremio-oss
文件:HBaseFilterBuilder.java
private HBaseScanSpec mergeScanSpecs(String functionName, HBaseScanSpec leftScanSpec, HBaseScanSpec rightScanSpec) {
Filter newFilter = null;
byte[] startRow = HConstants.EMPTY_START_ROW;
byte[] stopRow = HConstants.EMPTY_END_ROW;
switch (functionName) {
case "booleanAnd":
newFilter = HBaseUtils.andFilterAtIndex(
HBaseUtils.deserializeFilter(leftScanSpec.filter),
HBaseUtils.LAST_FILTER,
HBaseUtils.deserializeFilter(rightScanSpec.filter));
startRow = HBaseUtils.maxOfStartRows(leftScanSpec.startRow, rightScanSpec.startRow);
stopRow = HBaseUtils.minOfStopRows(leftScanSpec.stopRow, rightScanSpec.stopRow);
break;
case "booleanOr":
newFilter = HBaseUtils.orFilterAtIndex(
HBaseUtils.deserializeFilter(leftScanSpec.filter),
HBaseUtils.LAST_FILTER,
HBaseUtils.deserializeFilter(rightScanSpec.filter));
startRow = HBaseUtils.minOfStartRows(leftScanSpec.startRow, rightScanSpec.startRow);
stopRow = HBaseUtils.maxOfStopRows(leftScanSpec.stopRow, rightScanSpec.stopRow);
}
return new HBaseScanSpec(groupScan.getTableName(), startRow, stopRow, newFilter);
}
项目: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);
}
}
项目:ditb
文件:CellCounter.java
private static Scan getConfiguredScanForJob(Configuration conf, String[] args) throws IOException {
Scan s = new Scan();
// Set Scan Versions
s.setMaxVersions(Integer.MAX_VALUE);
s.setCacheBlocks(false);
// Set Scan Column Family
if (conf.get(TableInputFormat.SCAN_COLUMN_FAMILY) != null) {
s.addFamily(Bytes.toBytes(conf.get(TableInputFormat.SCAN_COLUMN_FAMILY)));
}
// Set RowFilter or Prefix Filter if applicable.
Filter rowFilter = getRowFilter(args);
if (rowFilter!= null) {
LOG.info("Setting Row Filter for counter.");
s.setFilter(rowFilter);
}
// Set TimeRange if defined
long timeRange[] = getTimeRange(args);
if (timeRange != null) {
LOG.info("Setting TimeRange for counter.");
s.setTimeRange(timeRange[0], timeRange[1]);
}
return s;
}
项目:ditb
文件:ScanPreprocess.java
public static ConditionTree preprocess(HRegion region, Filter filter, float maxScale) {
if (filter == null) return null;
ConditionTree tree = null;
if (isIndexFilter(region, filter)) {
System.out.println("preprocess A");
tree = new ConditionTreeNoneLeafNode(region, (SingleColumnValueFilter) filter, maxScale);
} else if (filter instanceof FilterList) {
System.out.println("preprocess B");
tree = new ConditionTreeNoneLeafNode(region, (FilterList) filter, maxScale);
}
if (tree.isPrune()) {
System.out.println("return null for prune");
return null;
} else {
return tree;
}
}
项目: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
文件:TestTableInputFormat.java
@Override
public void configure(JobConf job) {
try {
HTable exampleTable = new HTable(HBaseConfiguration.create(job),
Bytes.toBytes("exampleDeprecatedTable"));
// mandatory
setHTable(exampleTable);
byte[][] inputColumns = new byte [][] { Bytes.toBytes("columnA"),
Bytes.toBytes("columnB") };
// mandatory
setInputColumns(inputColumns);
Filter exampleFilter = new RowFilter(CompareOp.EQUAL, new RegexStringComparator("aa.*"));
// optional
setRowFilter(exampleFilter);
} catch (IOException exception) {
throw new RuntimeException("Failed to configure for job.", exception);
}
}
项目:ditb
文件:TestTableInputFormat.java
@Override
public void configure(JobConf job) {
try {
HTable exampleTable = new HTable(HBaseConfiguration.create(job),
Bytes.toBytes("exampleDeprecatedTable"));
// mandatory
setHTable(exampleTable);
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(CompareOp.EQUAL, new RegexStringComparator("aa.*"));
scan.setFilter(exampleFilter);
setScan(scan);
} catch (IOException exception) {
throw new RuntimeException("Failed to configure for job.", exception);
}
}
项目:ditb
文件:TestTableInputFormat.java
@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(CompareOp.EQUAL, new RegexStringComparator("aa.*"));
scan.setFilter(exampleFilter);
setScan(scan);
} catch (IOException exception) {
throw new RuntimeException("Failed to initialize.", exception);
}
}
项目:ditb
文件:TestTableInputFormat.java
@Override
protected void initialize(JobContext job) throws IOException {
Connection connection = ConnectionFactory.createConnection(HBaseConfiguration.create(
job.getConfiguration()));
TableName tableName = TableName.valueOf("exampleTable");
// 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(CompareOp.EQUAL, new RegexStringComparator("aa.*"));
scan.setFilter(exampleFilter);
setScan(scan);
}
项目:ditb
文件:ProtobufUtil.java
/**
* Convert a protocol buffer Filter to a client Filter
*
* @param proto the protocol buffer Filter to convert
* @return the converted Filter
*/
@SuppressWarnings("unchecked")
public static Filter toFilter(FilterProtos.Filter proto) throws IOException {
String type = proto.getName();
final byte [] value = proto.getSerializedFilter().toByteArray();
String funcName = "parseFrom";
try {
Class<? extends Filter> c =
(Class<? extends Filter>)Class.forName(type, true, CLASS_LOADER);
Method parseFrom = c.getMethod(funcName, byte[].class);
if (parseFrom == null) {
throw new IOException("Unable to locate function: " + funcName + " in type: " + type);
}
return (Filter)parseFrom.invoke(c, value);
} catch (Exception e) {
// Either we couldn't instantiate the method object, or "parseFrom" failed.
// In either case, let's not retry.
throw new DoNotRetryIOException(e);
}
}
项目:ditb
文件:ScannerModel.java
/**
* @param filter the filter
* @return the JSON representation of the filter
* @throws Exception
*/
public static String stringifyFilter(final Filter filter) throws Exception {
JSONJAXBContext context =
new JSONJAXBContext(JSONConfiguration.natural().build(),
FilterModel.class);
JSONMarshaller marshaller = context.createJSONMarshaller();
StringWriter writer = new StringWriter();
marshaller.marshallToJSON(new FilterModel(filter), writer);
return writer.toString();
}
项目:big_data
文件:ActiveUserRunner.java
/**
* 获取这个列名过滤的column
*
* @param columns
* @return
*/
private Filter getColumnFilter(String[] columns) {
int length = columns.length;
byte[][] filter = new byte[length][];
for (int i = 0; i < length; i++) {
filter[i] = Bytes.toBytes(columns[i]);
}
return new MultipleColumnPrefixFilter(filter);
}
项目:QDrill
文件:HBaseFilterBuilder.java
private HBaseScanSpec createRowKeyPrefixScanSpec(FunctionCall call,
CompareFunctionsProcessor processor) {
byte[] startRow = processor.getRowKeyPrefixStartRow();
byte[] stopRow = processor.getRowKeyPrefixStopRow();
Filter filter = processor.getRowKeyPrefixFilter();
if (startRow != HConstants.EMPTY_START_ROW ||
stopRow != HConstants.EMPTY_END_ROW ||
filter != null) {
return new HBaseScanSpec(groupScan.getTableName(), startRow, stopRow, filter);
}
// else
return null;
}
项目:QDrill
文件:HBaseUtils.java
static Filter parseFilterString(String filterString) {
if (filterString == null) {
return null;
}
try {
return FILTER_PARSEER.parseFilterString(filterString);
} catch (CharacterCodingException e) {
throw new DrillRuntimeException("Error parsing filter string: " + filterString, e);
}
}
项目:QDrill
文件:HBaseUtils.java
public static byte[] serializeFilter(Filter filter) {
if (filter == null) {
return null;
}
try {
FilterProtos.Filter pbFilter = ProtobufUtil.toFilter(filter);
return pbFilter.toByteArray();
} catch (IOException e) {
throw new DrillRuntimeException("Error serializing filter: " + filter, e);
}
}
项目:QDrill
文件:HBaseUtils.java
public static Filter deserializeFilter(byte[] filterBytes) {
if (filterBytes == null) {
return null;
}
try {
FilterProtos.Filter pbFilter = FilterProtos.Filter.parseFrom(filterBytes);
return ProtobufUtil.toFilter(pbFilter);
} catch (Exception e) {
throw new DrillRuntimeException("Error deserializing filter: " + filterBytes, e);
}
}
项目:ignite-hbase
文件:HBaseCacheStore.java
private Scan createScan(Object[] args) {
Scan scan = new Scan();
scan.addColumn(family(), QUALIFIER);
Optional<Filter> filter = FilterParser.createFilter(args);
filter.ifPresent(scan::setFilter);
return scan;
}
项目:hadoop-ecosystem-examples
文件:HBaseService.java
/**
* 多条件查询
* @param tableName
* @param familyNames
* @param qualifiers
* @param values
* @throws IOException
*/
public static void queryByConditions(String tableName, String[] familyNames, String[] qualifiers,String[] values) throws IOException {
Connection conn = ConnectionFactory.createConnection(conf);
Table table = conn.getTable(TableName.valueOf(tableName));
try {
List<Filter> filters = new ArrayList<Filter>();
if (familyNames != null && familyNames.length > 0) {
int i = 0;
for (String familyName : familyNames) {
Filter filter = new SingleColumnValueFilter(Bytes.toBytes(familyName), Bytes.toBytes(qualifiers[i]), CompareFilter.CompareOp.EQUAL, Bytes.toBytes(values[i]));
filters.add(filter);
i++;
}
}
FilterList filterList = new FilterList(filters);
Scan scan = new Scan();
scan.setFilter(filterList);
ResultScanner rs = table.getScanner(scan);
for (Result r : rs) {
System.out.println("获得到rowkey:" + new String(r.getRow()));
for (Cell keyValue : r.rawCells()) {
System.out.println("列:" + new String(CellUtil.cloneFamily(keyValue))+":"+new String(CellUtil.cloneQualifier(keyValue)) + "====值:" + new String(CellUtil.cloneValue(keyValue)));
}
}
rs.close();
} catch (Exception e) {
table.close();
conn.close();
}
}
项目:dremio-oss
文件:HBaseFilterBuilder.java
private HBaseScanSpec createRowKeyPrefixScanSpec(FunctionCall call, CompareFunctionsProcessor processor) {
byte[] startRow = processor.getRowKeyPrefixStartRow();
byte[] stopRow = processor.getRowKeyPrefixStopRow();
Filter filter = processor.getRowKeyPrefixFilter();
if (startRow != HConstants.EMPTY_START_ROW ||
stopRow != HConstants.EMPTY_END_ROW ||
filter != null) {
return new HBaseScanSpec(groupScan.getTableName(), startRow, stopRow, filter);
}
// else
return null;
}
项目:dremio-oss
文件:HBaseScanSpec.java
public HBaseScanSpec(String tableName, byte[] startRow, byte[] stopRow, Filter filter) {
this.tableName = tableName;
this.startRow = startRow;
this.stopRow = stopRow;
if (filter != null) {
this.filter = HBaseUtils.serializeFilter(filter);
} else {
this.filter = null;
}
}
项目:dremio-oss
文件:HBaseScanSpec.java
@JsonIgnore
public Filter getFilter() {
if (filterParsed == null) {
synchronized(this) {
if (filterParsed == null) {
filterParsed = HBaseUtils.deserializeFilter(this.filter);
}
}
}
return filterParsed;
}
项目:dremio-oss
文件:HBaseScanSpec.java
@Override
public String toString() {
Filter filterToString = getFilter();
return "HBaseScanSpec [tableName=" + tableName
+ ", startRow=" + (startRow == null ? null : Bytes.toStringBinary(startRow))
+ ", stopRow=" + (stopRow == null ? null : Bytes.toStringBinary(stopRow))
+ ", filter=" + (filter == null ? null : filterToString.toString())
+ "]";
}
项目:dremio-oss
文件:HBaseUtils.java
static Filter parseFilterString(String filterString) {
if (filterString == null) {
return null;
}
try {
return FILTER_PARSEER.parseFilterString(filterString);
} catch (CharacterCodingException e) {
throw new RuntimeException("Error parsing filter string: " + filterString, e);
}
}
项目:dremio-oss
文件:HBaseUtils.java
public static byte[] serializeFilter(Filter filter) {
if (filter == null) {
return null;
}
try {
FilterProtos.Filter pbFilter = ProtobufUtil.toFilter(filter);
return pbFilter.toByteArray();
} catch (IOException e) {
throw new RuntimeException("Error serializing filter: " + filter, e);
}
}
项目:dremio-oss
文件:HBaseUtils.java
public static Filter deserializeFilter(byte[] filterBytes) {
if (filterBytes == null) {
return null;
}
try {
FilterProtos.Filter pbFilter = FilterProtos.Filter.parseFrom(filterBytes);
return ProtobufUtil.toFilter(pbFilter);
} catch (Exception e) {
throw new RuntimeException("Error deserializing filter: " + filterBytes, e);
}
}
项目:aliyun-tablestore-hbase-client
文件:TestColumnPaginationFilter.java
@Test
public void testResultLessThanLimit() 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"));
put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_3"), Bytes.toBytes("col_3_var"));
put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_4"), Bytes.toBytes("col_4_var"));
table.put(put);
}
{
Get get = new Get(Bytes.toBytes(rowPrefix));
Filter filter = new ColumnPaginationFilter(5, 3);
get.setFilter(filter);
Result result = table.get(get);
List<Cell> cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_1"));
assertEquals(0, cells.size());
cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_2"));
assertEquals(0, cells.size());
cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_3"));
assertEquals(0, cells.size());
cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_4"));
assertEquals(1, cells.size());
assertEquals("col_4_var", Bytes.toString(cells.get(0).getValueArray(), cells.get(0).getValueOffset(), cells.get(0).getValueLength()));
}
}
项目:aliyun-tablestore-hbase-client
文件:TestColumnPaginationFilter.java
@Test
public void testStartRow() 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"));
put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_3"), Bytes.toBytes("col_3_var"));
put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_4"), Bytes.toBytes("col_4_var"));
table.put(put);
}
{
Get get = new Get(Bytes.toBytes(rowPrefix));
Filter filter = new ColumnPaginationFilter(1, Bytes.toBytes("col_2"));
get.setFilter(filter);
Result result = table.get(get);
List<Cell> cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_1"));
assertEquals(0, cells.size());
cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_2"));
assertEquals(1, cells.size());
assertEquals("col_2_var", Bytes.toString(cells.get(0).getValueArray(), cells.get(0).getValueOffset(), cells.get(0).getValueLength()));
cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_3"));
assertEquals(0, cells.size());
cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_4"));
assertEquals(0, cells.size());
}
}
项目:aliyun-tablestore-hbase-client
文件:TestColumnPaginationFilter.java
@Test
public void testStartRowByScan() 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"));
put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_3"), Bytes.toBytes("col_3_var"));
put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_4"), Bytes.toBytes("col_4_var"));
table.put(put);
}
{
Scan scan = new Scan();
Filter filter = new ColumnPaginationFilter(1, Bytes.toBytes("col_2"));
scan.setFilter(filter);
scan.setStartRow(Bytes.toBytes(rowPrefix));
scan.setStopRow(Bytes.toBytes(rowPrefix + 5));
ResultScanner scanResult = table.getScanner(scan);
Result result = scanResult.next();
List<Cell> cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_1"));
assertEquals(0, cells.size());
cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_2"));
assertEquals(1, cells.size());
assertEquals("col_2_var", Bytes.toString(cells.get(0).getValueArray(), cells.get(0).getValueOffset(), cells.get(0).getValueLength()));
cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_3"));
assertEquals(0, cells.size());
cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_4"));
assertEquals(0, cells.size());
}
}
项目:aliyun-tablestore-hbase-client
文件:TestColumnPaginationFilter.java
@Test
public void testStartRowIsNotExist() 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"));
put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_3"), Bytes.toBytes("col_3_var"));
put.addColumn(Bytes.toBytes(familyName), Bytes.toBytes("col_4"), Bytes.toBytes("col_4_var"));
table.put(put);
}
{
Get get = new Get(Bytes.toBytes(rowPrefix));
Filter filter = new ColumnPaginationFilter(1, Bytes.toBytes("col_3_not_exist"));
get.setFilter(filter);
Result result = table.get(get);
List<Cell> cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_1"));
assertEquals(0, cells.size());
cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_2"));
assertEquals(0, cells.size());
cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_3"));
assertEquals(0, cells.size());
cells = result.getColumnCells(Bytes.toBytes(familyName), Bytes.toBytes("col_4"));
assertEquals(1, cells.size());
assertEquals("col_4_var", Bytes.toString(cells.get(0).getValueArray(), cells.get(0).getValueOffset(), cells.get(0).getValueLength()));
}
}
项目:aliyun-tablestore-hbase-client
文件:TestFilterList.java
@Test
public void testTwoFilterWithDefaultOperator() 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.EQUAL, Bytes.toBytes("col_2_var"));
FilterList filterList = new FilterList();
filterList.addFilter(filter1);
filterList.addFilter(filter2);
get.setFilter(filterList);
Result result = table.get(get);
String value = Bytes.toString(result.getValue(Bytes.toBytes(familyName), Bytes.toBytes("col_1")));
assertEquals("col_1_var", value);
value = Bytes.toString(result.getValue(Bytes.toBytes(familyName), Bytes.toBytes("col_2")));
assertEquals("col_2_var", value);
}
}
项目:aliyun-tablestore-hbase-client
文件:TestFilterList.java
@Test
public void testTwoFilterWithMustAllPassSucceeded() 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.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);
String value = Bytes.toString(result.getValue(Bytes.toBytes(familyName), Bytes.toBytes("col_1")));
assertEquals("col_1_var", value);
value = Bytes.toString(result.getValue(Bytes.toBytes(familyName), Bytes.toBytes("col_2")));
assertEquals("col_2_var", value);
}
}
项目:aliyun-tablestore-hbase-client
文件:TestFilterList.java
@Test
public void testTwoFilterWithMustOnePassSucceeded() 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_ONE);
filterList.addFilter(filter1);
filterList.addFilter(filter2);
get.setFilter(filterList);
Result result = table.get(get);
String value = Bytes.toString(result.getValue(Bytes.toBytes(familyName), Bytes.toBytes("col_1")));
assertEquals("col_1_var", value);
value = Bytes.toString(result.getValue(Bytes.toBytes(familyName), Bytes.toBytes("col_2")));
assertEquals("col_2_var", value);
}
}
项目:ditb
文件:ThriftServerRunner.java
@Override
public int scannerOpenWithPrefix(ByteBuffer tableName,
ByteBuffer startAndPrefix,
List<ByteBuffer> columns,
Map<ByteBuffer, ByteBuffer> attributes)
throws IOError, TException {
Table table = null;
try {
table = getTable(tableName);
Scan scan = new Scan(getBytes(startAndPrefix));
addAttributes(scan, attributes);
Filter f = new WhileMatchFilter(
new PrefixFilter(getBytes(startAndPrefix)));
scan.setFilter(f);
if (columns != null && columns.size() != 0) {
for(ByteBuffer column : columns) {
byte [][] famQf = KeyValue.parseColumn(getBytes(column));
if(famQf.length == 1) {
scan.addFamily(famQf[0]);
} else {
scan.addColumn(famQf[0], famQf[1]);
}
}
}
return addScanner(table.getScanner(scan), false);
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw new IOError(Throwables.getStackTraceAsString(e));
} finally{
closeTable(table);
}
}
项目:ditb
文件:VisibilityController.java
@Override
public RegionScanner preScannerOpen(ObserverContext<RegionCoprocessorEnvironment> e, Scan scan,
RegionScanner s) throws IOException {
if (!initialized) {
throw new VisibilityControllerNotReadyException("VisibilityController not yet initialized!");
}
// Nothing to do if authorization is not enabled
if (!authorizationEnabled) {
return s;
}
Region region = e.getEnvironment().getRegion();
Authorizations authorizations = null;
try {
authorizations = scan.getAuthorizations();
} catch (DeserializationException de) {
throw new IOException(de);
}
if (authorizations == null) {
// No Authorizations present for this scan/Get!
// In case of system tables other than "labels" just scan with out visibility check and
// filtering. Checking visibility labels for META and NAMESPACE table is not needed.
TableName table = region.getRegionInfo().getTable();
if (table.isSystemTable() && !table.equals(LABELS_TABLE_NAME)) {
return s;
}
}
Filter visibilityLabelFilter = VisibilityUtils.createVisibilityLabelFilter(region,
authorizations);
if (visibilityLabelFilter != null) {
Filter filter = scan.getFilter();
if (filter != null) {
scan.setFilter(new FilterList(filter, visibilityLabelFilter));
} else {
scan.setFilter(visibilityLabelFilter);
}
}
return s;
}