org.apache.hadoop.hbase.filter.BinaryComparator Java Examples
The following examples show how to use
org.apache.hadoop.hbase.filter.BinaryComparator.
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: 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 #2
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 #3
Source File: PerformanceEvaluation.java From hbase with Apache License 2.0 | 6 votes |
protected Scan constructScan(byte[] valuePrefix) throws IOException { FilterList list = new FilterList(); Filter filter = new SingleColumnValueFilter(FAMILY_ZERO, COLUMN_ZERO, CompareOperator.EQUAL, new BinaryComparator(valuePrefix)); list.addFilter(filter); if (opts.filterAll) { list.addFilter(new FilterAllFilter()); } Scan scan = new Scan().setCaching(opts.caching).setCacheBlocks(opts.cacheBlocks) .setAsyncPrefetch(opts.asyncPrefetch).setReadType(opts.scanReadType) .setScanMetricsEnabled(true); if (opts.addColumns) { for (int column = 0; column < opts.columns; column++) { byte [] qualifier = column == 0? COLUMN_ZERO: Bytes.toBytes("" + column); scan.addColumn(FAMILY_ZERO, qualifier); } } else { scan.addFamily(FAMILY_ZERO); } scan.setFilter(list); return scan; }
Example #4
Source File: RequestConverter.java From hbase with Apache License 2.0 | 6 votes |
/** * Create a protocol buffer Condition * * @return a Condition * @throws IOException */ public static Condition buildCondition(final byte[] row, final byte[] family, final byte[] qualifier, final CompareOperator op, final byte[] value, final Filter filter, final TimeRange timeRange) throws IOException { Condition.Builder builder = Condition.newBuilder().setRow(UnsafeByteOperations.unsafeWrap(row)); if (filter != null) { builder.setFilter(ProtobufUtil.toFilter(filter)); } else { builder.setFamily(UnsafeByteOperations.unsafeWrap(family)) .setQualifier(UnsafeByteOperations.unsafeWrap( qualifier == null ? HConstants.EMPTY_BYTE_ARRAY : qualifier)) .setComparator(ProtobufUtil.toComparator(new BinaryComparator(value))) .setCompareType(CompareType.valueOf(op.name())); } return builder.setTimeRange(ProtobufUtil.toTimeRange(timeRange)).build(); }
Example #5
Source File: TestDoubleSerDeser.java From Eagle with Apache License 2.0 | 6 votes |
/** * @link http://en.wikipedia.org/wiki/Double-precision_floating-point_format */ @Test public void testIEEE754_Binary64_DoublePrecisionFloatingPointFormat(){ for(Double last = null,i=Math.pow(-2.0,33);i< Math.pow(2.0,33);i+=Math.pow(2.0,10)){ if(last != null){ Assert.assertTrue(i > last); if(last < 0 && i <0){ Assert.assertTrue("Negative double value and its serialization Binary array have negative correlation", new BinaryComparator(ByteUtil.doubleToBytes(i)).compareTo(ByteUtil.doubleToBytes(last)) < 0); }else if(last < 0 && i >=0){ Assert.assertTrue("Binary array for negative double is always greater than any positive doubles' ",new BinaryComparator(ByteUtil.doubleToBytes(i)).compareTo(ByteUtil.doubleToBytes(last)) < 0); }else if(last >= 0){ Assert.assertTrue("Positive double value and its serialization Binary array have positive correlation",new BinaryComparator(ByteUtil.doubleToBytes(i)).compareTo(ByteUtil.doubleToBytes(last)) > 0); } } last = i; } Assert.assertTrue("Binary array for negative double is always greater than any positive doubles'",new BinaryComparator(ByteUtil.doubleToBytes(-1.0)).compareTo(ByteUtil.doubleToBytes(Math.pow(2.0,32)))>0) ; }
Example #6
Source File: ScannerModel.java From hbase with Apache License 2.0 | 6 votes |
public ByteArrayComparableModel( ByteArrayComparable comparator) { String typeName = comparator.getClass().getSimpleName(); ComparatorType type = ComparatorType.valueOf(typeName); this.type = typeName; switch (type) { case BinaryComparator: case BinaryPrefixComparator: this.value = Bytes.toString(Base64.getEncoder().encode(comparator.getValue())); break; case BitComparator: this.value = Bytes.toString(Base64.getEncoder().encode(comparator.getValue())); this.op = ((BitComparator)comparator).getOperator().toString(); break; case NullComparator: break; case RegexStringComparator: case SubstringComparator: this.value = Bytes.toString(comparator.getValue()); break; default: throw new RuntimeException("unhandled filter type: " + type); } }
Example #7
Source File: Filters.java From java-docs-samples with Apache License 2.0 | 6 votes |
public static void filterLimitValueRange(String projectId, String instanceId, String tableId) { // A filter that matches cells whose values are between the given values ValueFilter valueGreaterFilter = new ValueFilter( CompareFilter.CompareOp.GREATER_OR_EQUAL, new BinaryComparator(Bytes.toBytes("PQ2A.190405"))); ValueFilter valueLesserFilter = new ValueFilter( CompareFilter.CompareOp.LESS_OR_EQUAL, new BinaryComparator(Bytes.toBytes("PQ2A.190406"))); FilterList filter = new FilterList(FilterList.Operator.MUST_PASS_ALL); filter.addFilter(valueGreaterFilter); filter.addFilter(valueLesserFilter); Scan scan = new Scan().setFilter(filter); readWithFilter(projectId, instanceId, tableId, scan); }
Example #8
Source File: PerformanceEvaluation.java From hbase with Apache License 2.0 | 5 votes |
protected Scan constructScan(byte[] valuePrefix) { Filter filter = new SingleColumnValueFilter( FAMILY_NAME, QUALIFIER_NAME, CompareOperator.EQUAL, new BinaryComparator(valuePrefix) ); Scan scan = new Scan(); scan.addColumn(FAMILY_NAME, QUALIFIER_NAME); scan.setFilter(filter); return scan; }
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: TestAtomicOperation.java From hbase with Apache License 2.0 | 5 votes |
@Override public void doWork() throws Exception { Put[] puts = new Put[1]; Put put = new Put(Bytes.toBytes("r1")); put.addColumn(Bytes.toBytes(family), Bytes.toBytes("q1"), Bytes.toBytes("11")); puts[0] = put; while (testStep != TestStep.PUT_COMPLETED) { Thread.sleep(100); } testStep = TestStep.CHECKANDPUT_STARTED; region.checkAndMutate(Bytes.toBytes("r1"), Bytes.toBytes(family), Bytes.toBytes("q1"), CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("10")), put); testStep = TestStep.CHECKANDPUT_COMPLETED; }
Example #11
Source File: TestSerialization.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testCompareFilter() throws Exception { Filter f = new RowFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("testRowOne-2"))); byte[] bytes = f.toByteArray(); Filter ff = RowFilter.parseFrom(bytes); assertNotNull(ff); }
Example #12
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 #13
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 #14
Source File: HBaseStorage.java From spork with Apache License 2.0 | 5 votes |
private void addRowFilter(CompareOp op, byte[] val) { if (LOG.isDebugEnabled()) { LOG.debug("Adding filter " + op.toString() + " with value " + Bytes.toStringBinary(val)); } addFilter(new RowFilter(op, new BinaryComparator(val))); }
Example #15
Source File: HBaseTableInputFormat.java From spork with Apache License 2.0 | 5 votes |
private boolean skipRegion(CompareOp op, byte[] key, byte[] option ) { if (key.length == 0 || option == null) return false; BinaryComparator comp = new BinaryComparator(option); RowFilter rowFilter = new RowFilter(op, comp); return rowFilter.filterRowKey(key, 0, key.length); }
Example #16
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 #17
Source File: FirstLastValueServerAggregator.java From phoenix with Apache License 2.0 | 5 votes |
@Override public void reset() { topOrder = new BinaryComparator(ByteUtil.EMPTY_BYTE_ARRAY); topValue = null; topValues.clear(); topValuesCount = 0; }
Example #18
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 #19
Source File: MetaDataEndpointImpl.java From phoenix with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param tableName parent table's name * @return true if there exist a table that use this table as their base table. * TODO: should we pass a timestamp here? */ private boolean hasViews(HRegion region, byte[] tenantId, PTable table) throws IOException { byte[] schemaName = table.getSchemaName().getBytes(); byte[] tableName = table.getTableName().getBytes(); Scan scan = new Scan(); // If the table is multi-tenant, we need to check across all tenant_ids, // so we can't constrain the row key. Otherwise, any views would have // the same tenantId. if (!table.isMultiTenant()) { byte[] startRow = ByteUtil.concat(tenantId, QueryConstants.SEPARATOR_BYTE_ARRAY); byte[] stopRow = ByteUtil.nextKey(startRow); scan.setStartRow(startRow); scan.setStopRow(stopRow); } SingleColumnValueFilter filter1 = new SingleColumnValueFilter(TABLE_FAMILY_BYTES, BASE_SCHEMA_NAME_BYTES, EQUAL, schemaName); filter1.setFilterIfMissing(schemaName.length > 0); SingleColumnValueFilter filter2 = new SingleColumnValueFilter(TABLE_FAMILY_BYTES, BASE_TABLE_NAME_BYTES, EQUAL, tableName); filter2.setFilterIfMissing(true); BinaryComparator comparator = new BinaryComparator(ByteUtil.concat(tenantId, QueryConstants.SEPARATOR_BYTE_ARRAY, schemaName, QueryConstants.SEPARATOR_BYTE_ARRAY, tableName)); RowFilter filter3 = new RowFilter(CompareOp.NOT_EQUAL,comparator); Filter filter = new FilterList(filter1,filter2,filter3); scan.setFilter(filter); RegionScanner scanner = region.getScanner(scan); try { List<KeyValue> results = newArrayList(); scanner.next(results); return results.size() > 0; } finally { scanner.close(); } }
Example #20
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 #21
Source File: ElementModel.java From hgraphdb with Apache License 2.0 | 5 votes |
protected Scan getPropertyScan(String label) { Scan scan = new Scan(); SingleColumnValueFilter valueFilter = new SingleColumnValueFilter(Constants.DEFAULT_FAMILY_BYTES, Constants.LABEL_BYTES, CompareFilter.CompareOp.EQUAL, new BinaryComparator(ValueUtils.serialize(label))); valueFilter.setFilterIfMissing(true); scan.setFilter(valueFilter); return scan; }
Example #22
Source File: ElementModel.java From hgraphdb with Apache License 2.0 | 5 votes |
protected Scan getPropertyScan(String label, byte[] key, byte[] val) { Scan scan = new Scan(); SingleColumnValueFilter labelFilter = new SingleColumnValueFilter(Constants.DEFAULT_FAMILY_BYTES, Constants.LABEL_BYTES, CompareFilter.CompareOp.EQUAL, new BinaryComparator(ValueUtils.serialize(label))); labelFilter.setFilterIfMissing(true); SingleColumnValueFilter valueFilter = new SingleColumnValueFilter(Constants.DEFAULT_FAMILY_BYTES, key, CompareFilter.CompareOp.EQUAL, new BinaryComparator(val)); valueFilter.setFilterIfMissing(true); FilterList filterList = new FilterList(labelFilter, valueFilter); scan.setFilter(filterList); return scan; }
Example #23
Source File: ElementModel.java From hgraphdb with Apache License 2.0 | 5 votes |
protected Scan getPropertyScan(String label, byte[] key, byte[] inclusiveFromValue, byte[] exclusiveToValue) { Scan scan = new Scan(); SingleColumnValueFilter labelFilter = new SingleColumnValueFilter(Constants.DEFAULT_FAMILY_BYTES, Constants.LABEL_BYTES, CompareFilter.CompareOp.EQUAL, new BinaryComparator(ValueUtils.serialize(label))); labelFilter.setFilterIfMissing(true); SingleColumnValueFilter fromValueFilter = new SingleColumnValueFilter(Constants.DEFAULT_FAMILY_BYTES, key, CompareFilter.CompareOp.GREATER_OR_EQUAL, new BinaryComparator(inclusiveFromValue)); fromValueFilter.setFilterIfMissing(true); SingleColumnValueFilter toValueFilter = new SingleColumnValueFilter(Constants.DEFAULT_FAMILY_BYTES, key, CompareFilter.CompareOp.LESS, new BinaryComparator(exclusiveToValue)); toValueFilter.setFilterIfMissing(true); FilterList filterList = new FilterList(labelFilter, fromValueFilter, toValueFilter); scan.setFilter(filterList); return scan; }
Example #24
Source File: TestDoubleSerDeser.java From eagle with Apache License 2.0 | 5 votes |
/** * @link http://en.wikipedia.org/wiki/Double-precision_floating-point_format */ @Test public void testIEEE754_Binary64_DoublePrecisionFloatingPointFormat() { for (Double last = null, i = Math.pow(-2.0, 33); i < Math.pow(2.0, 33); i += Math.pow(2.0, 10)) { if (last != null) { Assert.assertTrue(i > last); if (last < 0 && i < 0) { Assert .assertTrue("Negative double value and its serialization Binary array have negative correlation", new BinaryComparator(ByteUtil.doubleToBytes(i)) .compareTo(ByteUtil.doubleToBytes(last)) < 0); } else if (last < 0 && i >= 0) { Assert .assertTrue("Binary array for negative double is always greater than any positive doubles' ", new BinaryComparator(ByteUtil.doubleToBytes(i)) .compareTo(ByteUtil.doubleToBytes(last)) < 0); } else if (last >= 0) { Assert .assertTrue("Positive double value and its serialization Binary array have positive correlation", new BinaryComparator(ByteUtil.doubleToBytes(i)) .compareTo(ByteUtil.doubleToBytes(last)) > 0); } } last = i; } Assert.assertTrue("Binary array for negative double is always greater than any positive doubles'", new BinaryComparator(ByteUtil.doubleToBytes(-1.0)) .compareTo(ByteUtil.doubleToBytes(Math.pow(2.0, 32))) > 0); }
Example #25
Source File: Filters.java From java-docs-samples with Apache License 2.0 | 5 votes |
public static void filterComposingChain(String projectId, String instanceId, String tableId) { // A filter that selects one cell per row AND within the column family cell_plan Filter familyFilter = new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("cell_plan"))); Filter columnCountGetFilter = new ColumnCountGetFilter(3); FilterList filter = new FilterList(FilterList.Operator.MUST_PASS_ALL); filter.addFilter(columnCountGetFilter); filter.addFilter(familyFilter); Scan scan = new Scan().setFilter(filter); readWithFilter(projectId, instanceId, tableId, scan); }
Example #26
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 #27
Source File: FirstLastValueServerAggregator.java From phoenix with Apache License 2.0 | 5 votes |
@Override public void reset() { topOrder = new BinaryComparator(ByteUtil.EMPTY_BYTE_ARRAY); topValue = null; topValues.clear(); topValuesCount = 0; offset = -1; useOffset = false; }
Example #28
Source File: TestFromClientSide5.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testJira6912() throws Exception { final TableName tableName = name.getTableName(); try (Table foo = TEST_UTIL.createTable(tableName, new byte[][] {FAMILY}, 10)) { List<Put> puts = new ArrayList<>(); for (int i = 0; i != 100; i++) { Put put = new Put(Bytes.toBytes(i)); put.addColumn(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.withStartRow(Bytes.toBytes(1)); scan.withStopRow(Bytes.toBytes(3)); scan.addColumn(FAMILY, FAMILY); scan.setFilter(new RowFilter(CompareOperator.NOT_EQUAL, new BinaryComparator(Bytes.toBytes(1)))); try (ResultScanner scanner = foo.getScanner(scan)) { Result[] bar = scanner.next(100); assertEquals(1, bar.length); } } }
Example #29
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 #30
Source File: FirstLastValueBaseClientAggregator.java From phoenix with Apache License 2.0 | 4 votes |
@Override public void reset() { topOrder = new BinaryComparator(ByteUtil.EMPTY_BYTE_ARRAY); topValue = null; topValues.clear(); }