Java Code Examples for org.apache.hadoop.hbase.client.Get#setFilter()
The following examples show how to use
org.apache.hadoop.hbase.client.Get#setFilter() .
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: HBaseManager.java From hbase-secondary-index with GNU General Public License v3.0 | 6 votes |
public void testGet() throws IOException { long st = System.currentTimeMillis(); Get get = new Get( Bytes.toBytes("{1F591795-74DE-EB70-0245-0E4465C72CFA}")); get.addColumn(Bytes.toBytes("bhvr"), Bytes.toBytes("vvmid")); get.setMaxVersions(100); // get.setTimeRange(1354010844711L - 12000L, 1354010844711L); // get.setTimeStamp(1354700700000L); Filter filter = new ColumnPaginationFilter(1, 10); get.setFilter(filter); Result dbResult = table.get(get); System.out.println("result=" + dbResult.toString()); long en2 = System.currentTimeMillis(); System.out.println("Total Time: " + (en2 - st) + " ms"); }
Example 2
Source File: TransactionProcessor.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { Transaction tx = getFromOperation(get); if (tx != null) { projectFamilyDeletes(get); get.setMaxVersions(); get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData), TxUtils.getMaxVisibleTimestamp(tx)); Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter()); get.setFilter(newFilter); } }
Example 3
Source File: TestInvocationRecordFilter.java From hbase with Apache License 2.0 | 5 votes |
public void verifyInvocationResults(Integer[] selectQualifiers, Integer[] expectedQualifiers) throws Exception { Get get = new Get(ROW_BYTES); for (int i = 0; i < selectQualifiers.length; i++) { get.addColumn(FAMILY_NAME_BYTES, Bytes.toBytes(QUALIFIER_PREFIX + selectQualifiers[i])); } get.setFilter(new InvocationRecordFilter()); List<KeyValue> expectedValues = new ArrayList<>(); for (int i = 0; i < expectedQualifiers.length; i++) { expectedValues.add(new KeyValue(ROW_BYTES, FAMILY_NAME_BYTES, Bytes .toBytes(QUALIFIER_PREFIX + expectedQualifiers[i]), expectedQualifiers[i], Bytes.toBytes(VALUE_PREFIX + expectedQualifiers[i]))); } Scan scan = new Scan(get); List<Cell> actualValues = new ArrayList<>(); List<Cell> temp = new ArrayList<>(); InternalScanner scanner = this.region.getScanner(scan); while (scanner.next(temp)) { actualValues.addAll(temp); temp.clear(); } actualValues.addAll(temp); Assert.assertTrue("Actual values " + actualValues + " differ from the expected values:" + expectedValues, expectedValues.equals(actualValues)); }
Example 4
Source File: TestTimestampFilterSeekHint.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testGetDoesntSeekWithNoHint() throws IOException { StoreFileScanner.instrument(); prepareRegion(); Get g = new Get(RK_BYTES); g.setFilter(new TimestampsFilter(ImmutableList.of(5L))); final long initialSeekCount = StoreFileScanner.getSeekCount(); region.get(g); final long finalSeekCount = StoreFileScanner.getSeekCount(); assertTrue(finalSeekCount >= initialSeekCount ); assertTrue(finalSeekCount < initialSeekCount + 3); }
Example 5
Source File: VisibilityController.java From hbase with Apache License 2.0 | 5 votes |
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { if (!initialized) { throw new VisibilityControllerNotReadyException("VisibilityController not yet initialized"); } // Nothing useful to do if authorization is not enabled if (!authorizationEnabled) { return; } Region region = e.getEnvironment().getRegion(); Authorizations authorizations = null; try { authorizations = get.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; } } Filter visibilityLabelFilter = VisibilityUtils.createVisibilityLabelFilter(e.getEnvironment() .getRegion(), authorizations); if (visibilityLabelFilter != null) { Filter filter = get.getFilter(); if (filter != null) { get.setFilter(new FilterList(filter, visibilityLabelFilter)); } else { get.setFilter(visibilityLabelFilter); } } }
Example 6
Source File: HbaseTraceDaoV2.java From pinpoint with Apache License 2.0 | 5 votes |
private Get createGet(TransactionId transactionId, byte[] columnFamily, Filter filter) { byte[] transactionIdRowKey = rowKeyEncoder.encodeRowKey(transactionId); final Get get = new Get(transactionIdRowKey); get.addFamily(columnFamily); if (filter != null) { get.setFilter(filter); } return get; }
Example 7
Source File: DefaultHBaseSerde.java From envelope with Apache License 2.0 | 5 votes |
private Get convertToGet(Row row) { Get get = new Get(buildRowKey(row)); for (String family : getColumnFamilies(row)) { get.addFamily(Bytes.toBytes(family)); } FilterList filters = getColumnValueFilters(row); if (!filters.getFilters().isEmpty()) { get.setFilter(filters); } return get; }
Example 8
Source File: TransactionProcessor.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { Transaction tx = getFromOperation(get); if (tx != null) { projectFamilyDeletes(get); get.setMaxVersions(); get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData), TxUtils.getMaxVisibleTimestamp(tx)); Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter()); get.setFilter(newFilter); } }
Example 9
Source File: OmidSnapshotFilter.java From phoenix-omid with Apache License 2.0 | 5 votes |
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { if (get.getAttribute(CellUtils.CLIENT_GET_ATTRIBUTE) == null) return; boolean isLowLatency = Bytes.toBoolean(get.getAttribute(CellUtils.LL_ATTRIBUTE)); HBaseTransaction hbaseTransaction = getHBaseTransaction(get.getAttribute(CellUtils.TRANSACTION_ATTRIBUTE), isLowLatency); SnapshotFilterImpl snapshotFilter = getSnapshotFilter(e); snapshotFilterMap.put(get, snapshotFilter); get.setMaxVersions(); Filter newFilter = TransactionFilters.getVisibilityFilter(get.getFilter(), snapshotFilter, hbaseTransaction); get.setFilter(newFilter); }
Example 10
Source File: TransactionProcessor.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { Transaction tx = getFromOperation(get); if (tx != null) { projectFamilyDeletes(get); get.setMaxVersions(); get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData), TxUtils.getMaxVisibleTimestamp(tx)); Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter()); get.setFilter(newFilter); } }
Example 11
Source File: TransactionProcessor.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { Transaction tx = getFromOperation(get); if (tx != null) { projectFamilyDeletes(get); get.setMaxVersions(); get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData), TxUtils.getMaxVisibleTimestamp(tx)); Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter()); get.setFilter(newFilter); } }
Example 12
Source File: TransactionProcessor.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { Transaction tx = getFromOperation(get); if (tx != null) { projectFamilyDeletes(get); get.setMaxVersions(); get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData), TxUtils.getMaxVisibleTimestamp(tx)); Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter()); get.setFilter(newFilter); } }
Example 13
Source File: TransactionProcessor.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { Transaction tx = getFromOperation(get); if (tx != null) { projectFamilyDeletes(get); get.setMaxVersions(); get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData), TxUtils.getMaxVisibleTimestamp(tx)); Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter()); get.setFilter(newFilter); } }
Example 14
Source File: TransactionProcessor.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { Transaction tx = getFromOperation(get); if (tx != null) { projectFamilyDeletes(get); get.setMaxVersions(); get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData), TxUtils.getMaxVisibleTimestamp(tx)); Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter()); get.setFilter(newFilter); } }
Example 15
Source File: TransactionProcessor.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { Transaction tx = getFromOperation(get); if (tx != null) { projectFamilyDeletes(get); get.setMaxVersions(); get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData), TxUtils.getMaxVisibleTimestamp(tx)); Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter()); get.setFilter(newFilter); } }
Example 16
Source File: PerformanceEvaluation.java From hbase with Apache License 2.0 | 5 votes |
@Override boolean testRow(final int i) throws IOException, InterruptedException { if (opts.randomSleep > 0) { Thread.sleep(rd.nextInt(opts.randomSleep)); } Get get = new Get(getRandomRow(this.rand, opts.totalRows)); for (int family = 0; family < opts.families; family++) { byte[] familyName = Bytes.toBytes(FAMILY_NAME_BASE + family); if (opts.addColumns) { for (int column = 0; column < opts.columns; column++) { byte [] qualifier = column == 0? COLUMN_ZERO: Bytes.toBytes("" + column); get.addColumn(familyName, qualifier); } } else { get.addFamily(familyName); } } if (opts.filterAll) { get.setFilter(new FilterAllFilter()); } get.setConsistency(consistency); if (LOG.isTraceEnabled()) LOG.trace(get.toString()); if (opts.multiGet > 0) { this.gets.add(get); if (this.gets.size() == opts.multiGet) { Result [] rs = this.table.get(this.gets); updateValueSize(rs); this.gets.clear(); } else { return false; } } else { updateValueSize(this.table.get(get)); } return true; }
Example 17
Source File: ThriftUtilities.java From hbase with Apache License 2.0 | 4 votes |
/** * Creates a {@link Get} (HBase) from a {@link TGet} (Thrift). * * This ignores any timestamps set on {@link TColumn} objects. * * @param in the <code>TGet</code> to convert * * @return <code>Get</code> object * * @throws IOException if an invalid time range or max version parameter is given */ public static Get getFromThrift(TGet in) throws IOException { Get out = new Get(in.getRow()); // Timestamp overwrites time range if both are set if (in.isSetTimestamp()) { out.setTimestamp(in.getTimestamp()); } else if (in.isSetTimeRange()) { out.setTimeRange(in.getTimeRange().getMinStamp(), in.getTimeRange().getMaxStamp()); } if (in.isSetMaxVersions()) { out.readVersions(in.getMaxVersions()); } if (in.isSetFilterString()) { ParseFilter parseFilter = new ParseFilter(); out.setFilter(parseFilter.parseFilterString(in.getFilterString())); } if (in.isSetAttributes()) { addAttributes(out,in.getAttributes()); } if (in.isSetAuthorizations()) { out.setAuthorizations(new Authorizations(in.getAuthorizations().getLabels())); } if (in.isSetConsistency()) { out.setConsistency(consistencyFromThrift(in.getConsistency())); } if (in.isSetTargetReplicaId()) { out.setReplicaId(in.getTargetReplicaId()); } if (in.isSetCacheBlocks()) { out.setCacheBlocks(in.isCacheBlocks()); } if (in.isSetStoreLimit()) { out.setMaxResultsPerColumnFamily(in.getStoreLimit()); } if (in.isSetStoreOffset()) { out.setRowOffsetPerColumnFamily(in.getStoreOffset()); } if (in.isSetExistence_only()) { out.setCheckExistenceOnly(in.isExistence_only()); } if (in.isSetColumns()) { for (TColumn column : in.getColumns()) { if (column.isSetQualifier()) { out.addColumn(column.getFamily(), column.getQualifier()); } else { out.addFamily(column.getFamily()); } } } if (in.isSetFilterBytes()) { out.setFilter(filterFromThrift(in.getFilterBytes())); } return out; }
Example 18
Source File: RowResultGenerator.java From hbase with Apache License 2.0 | 4 votes |
public RowResultGenerator(final String tableName, final RowSpec rowspec, final Filter filter, final boolean cacheBlocks) throws IllegalArgumentException, IOException { try (Table table = RESTServlet.getInstance().getTable(tableName)) { Get get = new Get(rowspec.getRow()); if (rowspec.hasColumns()) { for (byte[] col : rowspec.getColumns()) { byte[][] split = CellUtil.parseColumn(col); if (split.length == 1) { get.addFamily(split[0]); } else if (split.length == 2) { get.addColumn(split[0], split[1]); } else { throw new IllegalArgumentException("Invalid column specifier."); } } } get.setTimeRange(rowspec.getStartTime(), rowspec.getEndTime()); get.readVersions(rowspec.getMaxVersions()); if (filter != null) { get.setFilter(filter); } get.setCacheBlocks(cacheBlocks); Result result = table.get(get); if (result != null && !result.isEmpty()) { valuesI = result.listCells().iterator(); } } catch (DoNotRetryIOException e) { // Warn here because Stargate will return 404 in the case if multiple // column families were specified but one did not exist -- currently // HBase will fail the whole Get. // Specifying multiple columns in a URI should be uncommon usage but // help to avoid confusion by leaving a record of what happened here in // the log. LOG.warn(StringUtils.stringifyException(e)); // Lets get the exception rethrown to get a more meaningful error message than 404 if (e instanceof AccessDeniedException) { throw e; } } }
Example 19
Source File: TestSnapshotFilter.java From phoenix-omid with Apache License 2.0 | 4 votes |
@Test(timeOut = 60_000) public void testGetWithFilter() throws Throwable { byte[] rowName1 = Bytes.toBytes("row1"); byte[] famName1 = Bytes.toBytes(TEST_FAMILY); byte[] famName2 = Bytes.toBytes("test-fam2"); byte[] colName1 = Bytes.toBytes("col1"); byte[] colName2 = Bytes.toBytes("col2"); byte[] dataValue1 = Bytes.toBytes("testWrite-1"); String TEST_TABLE = "testGetWithFilter"; createTableIfNotExists(TEST_TABLE, Bytes.toBytes(TEST_FAMILY), famName2); TTable tt = new TTable(connection, TEST_TABLE); Transaction tx1 = tm.begin(); Put put1 = new Put(rowName1); put1.addColumn(famName1, colName1, dataValue1); tt.put(tx1, put1); tm.commit(tx1); Transaction tx2 = tm.begin(); Put put2 = new Put(rowName1); put2.addColumn(famName2, colName2, dataValue1); tt.put(tx2, put2); tm.commit(tx2); Transaction tx3 = tm.begin(); Get get = new Get(rowName1); Filter filter1 = new FilterList(FilterList.Operator.MUST_PASS_ONE, new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes(TEST_FAMILY))), new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(famName2))); get.setFilter(filter1); Result result = tt.get(tx3, get); assertTrue(result.size() == 2, "Result should be 2"); Filter filter2 = new FilterList(FilterList.Operator.MUST_PASS_ONE, new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes(TEST_FAMILY)))); get.setFilter(filter2); result = tt.get(tx3, get); assertTrue(result.size() == 1, "Result should be 2"); tm.commit(tx3); tt.close(); }
Example 20
Source File: TestSnapshotFilter.java From phoenix-omid with Apache License 2.0 | 4 votes |
@Test(timeOut = 60_000) public void testGetWithFamilyDelete() throws Throwable { byte[] rowName1 = Bytes.toBytes("row1"); byte[] famName1 = Bytes.toBytes(TEST_FAMILY); byte[] famName2 = Bytes.toBytes("test-fam2"); byte[] colName1 = Bytes.toBytes("col1"); byte[] colName2 = Bytes.toBytes("col2"); byte[] dataValue1 = Bytes.toBytes("testWrite-1"); String TEST_TABLE = "testGetWithFamilyDelete"; createTableIfNotExists(TEST_TABLE, Bytes.toBytes(TEST_FAMILY), famName2); TTable tt = new TTable(connection, TEST_TABLE); Transaction tx1 = tm.begin(); Put put1 = new Put(rowName1); put1.addColumn(famName1, colName1, dataValue1); tt.put(tx1, put1); tm.commit(tx1); Transaction tx2 = tm.begin(); Put put2 = new Put(rowName1); put2.addColumn(famName2, colName2, dataValue1); tt.put(tx2, put2); tm.commit(tx2); Transaction tx3 = tm.begin(); Delete d = new Delete(rowName1); d.addFamily(famName2); tt.delete(tx3, d); Transaction tx4 = tm.begin(); Get get = new Get(rowName1); Filter filter1 = new FilterList(FilterList.Operator.MUST_PASS_ONE, new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes(TEST_FAMILY))), new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(famName2))); get.setFilter(filter1); Result result = tt.get(tx4, get); assertTrue(result.size() == 2, "Result should be 2"); try { tm.commit(tx3); } catch (RollbackException e) { if (!tm.isLowLatency()) fail(); } Transaction tx5 = tm.begin(); result = tt.get(tx5, get); if (!tm.isLowLatency()) assertTrue(result.size() == 1, "Result should be 1"); tt.close(); }