org.apache.hadoop.hbase.filter.QualifierFilter Java Examples
The following examples show how to use
org.apache.hadoop.hbase.filter.QualifierFilter.
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: TestStoreScanner.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testReadVersionWithRawAndFilter() throws IOException { ScanInfo scanInfo = new ScanInfo(CONF, CF, 0, 1, Long.MAX_VALUE, KeepDeletedCells.FALSE, HConstants.DEFAULT_BLOCKSIZE, 0 , CellComparator.getInstance(), false); KeyValue [] kvs = new KeyValue[] { create("R1", "cf", "a", 3, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "a", 2, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care") }; List<KeyValueScanner> scanners = Arrays.asList( new KeyValueScanner[]{ new KeyValueScanFixture(CellComparator.getInstance(), kvs) }); BinaryComparator comp = new BinaryComparator(Bytes.toBytes("a")); Filter filter = new QualifierFilter(CompareOperator.EQUAL, comp); Scan scanSpec = new Scan().withStartRow(Bytes.toBytes("R1")).readVersions(2).setRaw(true); scanSpec.setFilter(filter); try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, null, scanners)) { List<Cell> results = new ArrayList<>(); assertEquals(true, scan.next(results)); assertEquals(2, results.size()); } }
Example #2
Source File: TestScannersFromClientSide.java From hbase with Apache License 2.0 | 6 votes |
@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 #3
Source File: Filters.java From java-docs-samples with Apache License 2.0 | 5 votes |
public static void filterComposingInterleave( String projectId, String instanceId, String tableId) { // A filter that matches cells with the value true OR with the column qualifier os_build Filter qualifierFilter = new QualifierFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("os_build"))); Filter valueFilter = new ValueFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("true"))); FilterList filter = new FilterList(Operator.MUST_PASS_ONE); filter.addFilter(qualifierFilter); filter.addFilter(valueFilter); Scan scan = new Scan().setFilter(filter).setMaxVersions(); readWithFilter(projectId, instanceId, tableId, scan); }
Example #4
Source File: CommonHBaseConnection.java From pentaho-hadoop-shims with Apache License 2.0 | 5 votes |
void addFilterByMapping( FilterList fl, CompareFilter.CompareOp comp, Class<?> comparatorClass, Object comparator, Mapping.TupleMapping tupleMapping ) throws NoSuchMethodException, InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException { switch ( tupleMapping ) { case KEY: { addFilter( RowFilter.class, fl, comp, comparatorClass, comparator ); return; } case FAMILY: { addFilter( FamilyFilter.class, fl, comp, comparatorClass, comparator ); return; } case COLUMN: { //TODO Check if ColumnPrefixFilter works faster and suit more addFilter( QualifierFilter.class, fl, comp, comparatorClass, comparator ); return; } case VALUE: { addFilter( ValueFilter.class, fl, comp, comparatorClass, comparator ); return; } case TIMESTAMP: { addFilter( TimestampsFilter.class, fl, comp, comparatorClass, comparator ); // Constructor<TimestampsFilter> columnFilterConstructor = // TimestampsFilter.class.getConstructor( CompareFilter.CompareOp.class, comparatorClass ); // TimestampsFilter scf = columnFilterConstructor.newInstance( comp, comparator ); // fl.addFilter( scf ); return; } } }
Example #5
Source File: ViewTTLIT.java From phoenix with Apache License 2.0 | 5 votes |
private void assertViewHeaderRowsHaveViewTTLRelatedCells(String schemaName, long minTimestamp, boolean rawScan, int expectedRows) throws IOException, SQLException { FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL); RowFilter schemaNameFilter = new RowFilter( CompareFilter.CompareOp.EQUAL, new SubstringComparator(schemaName) ); QualifierFilter viewTTLQualifierFilter = new QualifierFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(PhoenixDatabaseMetaData.VIEW_TTL_BYTES)); filterList.addFilter(schemaNameFilter); filterList.addFilter(viewTTLQualifierFilter); try (Table tbl = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES) .getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES)) { Scan allRows = new Scan(); allRows.setRaw(rawScan); allRows.setTimeRange(minTimestamp, HConstants.LATEST_TIMESTAMP); allRows.setFilter(filterList); ResultScanner scanner = tbl.getScanner(allRows); int numMatchingRows = 0; for (Result result = scanner.next(); result != null; result = scanner.next()) { numMatchingRows += result.containsColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.VIEW_TTL_BYTES) ? 1 : 0; } assertEquals(String.format("Expected rows do not match for table = %s at timestamp %d", Bytes.toString(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES), minTimestamp), expectedRows, numMatchingRows); } }
Example #6
Source File: HbaseAgentEventDao.java From pinpoint with Apache License 2.0 | 5 votes |
@Override public List<AgentEventBo> getAgentEvents(String agentId, Range range, Set<AgentEventType> excludeEventTypes) { Objects.requireNonNull(agentId, "agentId"); Objects.requireNonNull(range, "range"); Scan scan = new Scan(); scan.setMaxVersions(1); scan.setCaching(SCANNER_CACHE_SIZE); scan.setStartRow(createRowKey(agentId, range.getTo())); scan.setStopRow(createRowKey(agentId, range.getFrom())); scan.addFamily(descriptor.getColumnFamilyName()); if (!CollectionUtils.isEmpty(excludeEventTypes)) { FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL); for (AgentEventType excludeEventType : excludeEventTypes) { byte[] excludeQualifier = Bytes.toBytes(excludeEventType.getCode()); filterList.addFilter(new QualifierFilter(CompareFilter.CompareOp.NOT_EQUAL, new BinaryComparator(excludeQualifier))); } scan.setFilter(filterList); } TableName agentEventTableName = descriptor.getTableName(); List<AgentEventBo> agentEvents = this.hbaseOperations2.find(agentEventTableName, scan, agentEventResultsExtractor); logger.debug("agentEvents found. {}", agentEvents); return agentEvents; }
Example #7
Source File: TestHBaseStorageFiltering.java From spork with Apache License 2.0 | 5 votes |
private void assertQualifierFilter(Filter filter, CompareFilter.CompareOp compareOp, String value) { assertTrue("Filter is not a QualifierFilter: " + filter.getClass().getSimpleName(), filter instanceof QualifierFilter); QualifierFilter qualifierFilter = (QualifierFilter)filter; assertEquals("Unexpected compareOp", compareOp, qualifierFilter.getOperator()); assertEquals("Unexpected value", value, Bytes.toString(qualifierFilter.getComparator().getValue())); }
Example #8
Source File: TestScannersWithFilters.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testSkipFilter() throws Exception { // Test for qualifier regex: "testQualifierOne-2" // Should only get rows from second group, and all keys Filter f = new SkipFilter(new QualifierFilter(CompareOperator.NOT_EQUAL, new BinaryComparator(Bytes.toBytes("testQualifierOne-2")))); Scan s = new Scan(); s.setFilter(f); KeyValue [] kvs = { // testRowTwo-0 new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), // testRowTwo-2 new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), // testRowTwo-3 new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]), new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]), new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]), new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]), new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]), new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]), }; verifyScanFull(s, kvs); }
Example #9
Source File: TestCheckAndMutate.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testCheckAndMutateWithTimestampFilter() throws Throwable { try (Table table = createTable()) { // Put with specifying the timestamp table.put(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))); // Put with success boolean ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) .ifMatches(new FilterList( new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(100L)))) .build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))); assertTrue(ok); Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"))); assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B")))); // Put with failure ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) .ifMatches(new FilterList( new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(101L)))) .build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")))); assertFalse(ok); assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C")))); } }
Example #10
Source File: TestCheckAndMutate.java From hbase with Apache License 2.0 | 5 votes |
@Test @Deprecated public void testCheckAndMutateWithTimestampFilterForOldApi() throws Throwable { try (Table table = createTable()) { // Put with specifying the timestamp table.put(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))); // Put with success boolean ok = table.checkAndMutate(ROWKEY, new FilterList( new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(100L)) )) .thenPut(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))); assertTrue(ok); Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"))); assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B")))); // Put with failure ok = table.checkAndMutate(ROWKEY, new FilterList( new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(101L)) )) .thenPut(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"))); assertFalse(ok); assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C")))); } }
Example #11
Source File: TestFromClientSide.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testFilters() throws Exception { final TableName tableName = name.getTableName(); try (Table ht = TEST_UTIL.createTable(tableName, FAMILY)) { byte[][] ROWS = makeN(ROW, 10); byte[][] QUALIFIERS = { Bytes.toBytes("col0-<d2v1>-<d3v2>"), Bytes.toBytes("col1-<d2v1>-<d3v2>"), Bytes.toBytes("col2-<d2v1>-<d3v2>"), Bytes.toBytes("col3-<d2v1>-<d3v2>"), Bytes.toBytes("col4-<d2v1>-<d3v2>"), Bytes.toBytes("col5-<d2v1>-<d3v2>"), Bytes.toBytes("col6-<d2v1>-<d3v2>"), Bytes.toBytes("col7-<d2v1>-<d3v2>"), Bytes.toBytes("col8-<d2v1>-<d3v2>"), Bytes.toBytes("col9-<d2v1>-<d3v2>") }; for (int i = 0; i < 10; i++) { Put put = new Put(ROWS[i]); put.setDurability(Durability.SKIP_WAL); put.addColumn(FAMILY, QUALIFIERS[i], VALUE); ht.put(put); } Scan scan = new Scan(); scan.addFamily(FAMILY); Filter filter = new QualifierFilter(CompareOperator.EQUAL, new RegexStringComparator("col[1-5]")); scan.setFilter(filter); try (ResultScanner scanner = ht.getScanner(scan)) { int expectedIndex = 1; for (Result result : scanner) { assertEquals(1, result.size()); assertTrue(Bytes.equals(CellUtil.cloneRow(result.rawCells()[0]), ROWS[expectedIndex])); assertTrue(Bytes.equals(CellUtil.cloneQualifier(result.rawCells()[0]), QUALIFIERS[expectedIndex])); expectedIndex++; } assertEquals(6, expectedIndex); } } }
Example #12
Source File: TestAsyncTable.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testCheckAndMutateWithTimestampFilter() 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(CheckAndMutate.newBuilder(row) .ifMatches(new FilterList( new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(100L)))) .build(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(CheckAndMutate.newBuilder(row) .ifMatches(new FilterList( new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(101L)))) .build(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 #13
Source File: TestAsyncTable.java From hbase with Apache License 2.0 | 5 votes |
@Test @Deprecated public void testCheckAndMutateWithTimestampFilterForOldApi() 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 FilterList( new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(100L)) )) .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 FilterList( new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(101L)) )) .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 #14
Source File: PermissionStorage.java From hbase with Apache License 2.0 | 5 votes |
static private void removeTablePermissions(TableName tableName, byte[] column, Table table, boolean closeTable) throws IOException { Scan scan = new Scan(); scan.addFamily(ACL_LIST_FAMILY); String columnName = Bytes.toString(column); scan.setFilter(new QualifierFilter(CompareOperator.EQUAL, new RegexStringComparator( String.format("(%s%s%s)|(%s%s)$", ACL_KEY_DELIMITER, columnName, ACL_KEY_DELIMITER, ACL_KEY_DELIMITER, columnName)))); Set<byte[]> qualifierSet = new TreeSet<>(Bytes.BYTES_COMPARATOR); ResultScanner scanner = null; try { scanner = table.getScanner(scan); for (Result res : scanner) { for (byte[] q : res.getFamilyMap(ACL_LIST_FAMILY).navigableKeySet()) { qualifierSet.add(q); } } if (qualifierSet.size() > 0) { Delete d = new Delete(tableName.getName()); for (byte[] qualifier : qualifierSet) { d.addColumns(ACL_LIST_FAMILY, qualifier); } table.delete(d); } } finally { if (scanner != null) { scanner.close(); } if (closeTable) { table.close(); } } }
Example #15
Source File: Filters.java From java-docs-samples with Apache License 2.0 | 5 votes |
public static void filterLimitColQualifierRegex( String projectId, String instanceId, String tableId) { // A filter that matches cells whose column qualifier satisfies the given regex Filter filter = new QualifierFilter(CompareOp.EQUAL, new RegexStringComparator("connected_.*$")); Scan scan = new Scan().setFilter(filter); readWithFilter(projectId, instanceId, tableId, scan); }
Example #16
Source File: QuotaTableUtil.java From hbase with Apache License 2.0 | 4 votes |
/** * converts quotafilter to serializeable filterlists. */ public static Filter makeFilter(final QuotaFilter filter) { FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL); if (StringUtils.isNotEmpty(filter.getUserFilter())) { FilterList userFilters = new FilterList(FilterList.Operator.MUST_PASS_ONE); boolean hasFilter = false; if (StringUtils.isNotEmpty(filter.getNamespaceFilter())) { FilterList nsFilters = new FilterList(FilterList.Operator.MUST_PASS_ALL); nsFilters.addFilter(new RowFilter(CompareOperator.EQUAL, new RegexStringComparator(getUserRowKeyRegex(filter.getUserFilter()), 0))); nsFilters.addFilter(new QualifierFilter(CompareOperator.EQUAL, new RegexStringComparator( getSettingsQualifierRegexForUserNamespace(filter.getNamespaceFilter()), 0))); userFilters.addFilter(nsFilters); hasFilter = true; } if (StringUtils.isNotEmpty(filter.getTableFilter())) { FilterList tableFilters = new FilterList(FilterList.Operator.MUST_PASS_ALL); tableFilters.addFilter(new RowFilter(CompareOperator.EQUAL, new RegexStringComparator(getUserRowKeyRegex(filter.getUserFilter()), 0))); tableFilters.addFilter(new QualifierFilter(CompareOperator.EQUAL, new RegexStringComparator( getSettingsQualifierRegexForUserTable(filter.getTableFilter()), 0))); userFilters.addFilter(tableFilters); hasFilter = true; } if (!hasFilter) { userFilters.addFilter(new RowFilter(CompareOperator.EQUAL, new RegexStringComparator(getUserRowKeyRegex(filter.getUserFilter()), 0))); } filterList.addFilter(userFilters); } else if (StringUtils.isNotEmpty(filter.getTableFilter())) { filterList.addFilter(new RowFilter(CompareOperator.EQUAL, new RegexStringComparator(getTableRowKeyRegex(filter.getTableFilter()), 0))); } else if (StringUtils.isNotEmpty(filter.getNamespaceFilter())) { filterList.addFilter(new RowFilter(CompareOperator.EQUAL, new RegexStringComparator(getNamespaceRowKeyRegex(filter.getNamespaceFilter()), 0))); } else if (StringUtils.isNotEmpty(filter.getRegionServerFilter())) { filterList.addFilter(new RowFilter(CompareOperator.EQUAL, new RegexStringComparator( getRegionServerRowKeyRegex(filter.getRegionServerFilter()), 0))); } return filterList; }
Example #17
Source File: TestFromClientSide5.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testFiltersWithReverseScan() throws Exception { final TableName tableName = name.getTableName(); try (Table ht = TEST_UTIL.createTable(tableName, FAMILY)) { byte[][] ROWS = makeN(ROW, 10); byte[][] QUALIFIERS = {Bytes.toBytes("col0-<d2v1>-<d3v2>"), Bytes.toBytes("col1-<d2v1>-<d3v2>"), Bytes.toBytes("col2-<d2v1>-<d3v2>"), Bytes.toBytes("col3-<d2v1>-<d3v2>"), Bytes.toBytes("col4-<d2v1>-<d3v2>"), Bytes.toBytes("col5-<d2v1>-<d3v2>"), Bytes.toBytes("col6-<d2v1>-<d3v2>"), Bytes.toBytes("col7-<d2v1>-<d3v2>"), Bytes.toBytes("col8-<d2v1>-<d3v2>"), Bytes.toBytes("col9-<d2v1>-<d3v2>")}; for (int i = 0; i < 10; i++) { Put put = new Put(ROWS[i]); put.addColumn(FAMILY, QUALIFIERS[i], VALUE); ht.put(put); } Scan scan = new Scan(); scan.setReversed(true); scan.addFamily(FAMILY); Filter filter = new QualifierFilter(CompareOperator.EQUAL, new RegexStringComparator("col[1-5]")); scan.setFilter(filter); try (ResultScanner scanner = ht.getScanner(scan)) { int expectedIndex = 5; for (Result result : scanner) { assertEquals(1, result.size()); Cell c = result.rawCells()[0]; assertTrue(Bytes.equals(c.getRowArray(), c.getRowOffset(), c.getRowLength(), ROWS[expectedIndex], 0, ROWS[expectedIndex].length)); assertTrue(Bytes.equals(c.getQualifierArray(), c.getQualifierOffset(), c.getQualifierLength(), QUALIFIERS[expectedIndex], 0, QUALIFIERS[expectedIndex].length)); expectedIndex--; } assertEquals(0, expectedIndex); } } }
Example #18
Source File: HbaseTraceDaoV2.java From pinpoint with Apache License 2.0 | 4 votes |
public QualifierFilter createSpanQualifierFilter() { byte indexPrefix = SpanEncoder.TYPE_SPAN; BinaryPrefixComparator prefixComparator = new BinaryPrefixComparator(new byte[]{indexPrefix}); QualifierFilter qualifierPrefixFilter = new QualifierFilter(CompareFilter.CompareOp.EQUAL, prefixComparator); return qualifierPrefixFilter; }
Example #19
Source File: JobHistoryService.java From hraven with Apache License 2.0 | 4 votes |
/** * Returns the {@link Flow} runs' stats - summed up per flow If the * {@code version} parameter is non-null, the returned results will be * restricted to those matching this app version. * * <p> * <strong>Note:</strong> this retrieval method will omit the configuration * data from all of the returned jobs. * </p> * * @param cluster the cluster where the jobs were run * @param user the user running the jobs * @param appId the application identifier for the jobs * @param version if non-null, only flows matching this application version * will be returned * @param startTime the start time for the flows to be looked at * @param endTime the end time for the flows to be looked at * @param limit the maximum number of flows to return * @return */ public List<Flow> getFlowTimeSeriesStats(String cluster, String user, String appId, String version, long startTime, long endTime, int limit, byte[] startRow) throws IOException { // app portion of row key byte[] rowPrefix = Bytes.toBytes((cluster + Constants.SEP + user + Constants.SEP + appId + Constants.SEP)); byte[] scanStartRow; if (startRow != null) { scanStartRow = startRow; } else { if (endTime != 0) { // use end time in start row, if present long endRunId = FlowKey.encodeRunId(endTime); scanStartRow = Bytes.add(rowPrefix, Bytes.toBytes(endRunId), Constants.SEP_BYTES); } else { scanStartRow = rowPrefix; } } // TODO: use RunMatchFilter to limit scan on the server side Scan scan = new Scan(); scan.setStartRow(scanStartRow); FilterList filters = new FilterList(FilterList.Operator.MUST_PASS_ALL); if (startTime != 0) { // if limited by start time, early out as soon as we hit it long startRunId = FlowKey.encodeRunId(startTime); // zero byte at the end makes the startRunId inclusive byte[] scanEndRow = Bytes.add(rowPrefix, Bytes.toBytes(startRunId), Constants.ZERO_SINGLE_BYTE); scan.setStopRow(scanEndRow); } else { // require that all rows match the app prefix we're looking for filters.addFilter(new WhileMatchFilter(new PrefixFilter(rowPrefix))); } // if version is passed, restrict the rows returned to that version if (version != null && version.length() > 0) { filters.addFilter(new SingleColumnValueFilter(Constants.INFO_FAM_BYTES, Constants.VERSION_COLUMN_BYTES, CompareFilter.CompareOp.EQUAL, Bytes.toBytes(version))); } // filter out all config columns except the queue name filters.addFilter(new QualifierFilter(CompareFilter.CompareOp.NOT_EQUAL, new RegexStringComparator( "^c\\!((?!" + Constants.HRAVEN_QUEUE + ").)*$"))); scan.setFilter(filters); LOG.info("scan : \n " + scan.toJSON() + " \n"); return createFromResults(scan, false, limit); }