@Test public void testFilterWithLongCompartor() throws Exception { byte [] TABLE = Bytes.toBytes("testFilterWithLongCompartor"); Table ht = TEST_UTIL.createTable(TABLE, FAMILY); byte [][] ROWS = makeN(ROW, 10); byte [][] values = new byte[10][]; for (int i = 0; i < 10; i ++) { values[i] = Bytes.toBytes(100L * i); } for(int i = 0; i < 10; i ++) { Put put = new Put(ROWS[i]); put.setDurability(Durability.SKIP_WAL); put.add(FAMILY, QUALIFIER, values[i]); ht.put(put); } Scan scan = new Scan(); scan.addFamily(FAMILY); Filter filter = new SingleColumnValueFilter(FAMILY, QUALIFIER, CompareOp.GREATER, new LongComparator(500)); scan.setFilter(filter); ResultScanner scanner = ht.getScanner(scan); int expectedIndex = 0; for(Result result : ht.getScanner(scan)) { assertEquals(result.size(), 1); assertTrue(Bytes.toLong(result.getValue(FAMILY, QUALIFIER)) > 500); expectedIndex++; } assertEquals(expectedIndex, 4); scanner.close(); }
@Test public void testFilterWithLongCompartor() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); Table ht = TEST_UTIL.createTable(tableName, FAMILY); byte [][] ROWS = makeN(ROW, 10); byte [][] values = new byte[10][]; for (int i = 0; i < 10; i ++) { values[i] = Bytes.toBytes(100L * i); } for(int i = 0; i < 10; i ++) { Put put = new Put(ROWS[i]); put.setDurability(Durability.SKIP_WAL); put.addColumn(FAMILY, QUALIFIER, values[i]); ht.put(put); } Scan scan = new Scan(); scan.addFamily(FAMILY); Filter filter = new SingleColumnValueFilter(FAMILY, QUALIFIER, CompareOperator.GREATER, new LongComparator(500)); scan.setFilter(filter); ResultScanner scanner = ht.getScanner(scan); int expectedIndex = 0; for(Result result : ht.getScanner(scan)) { assertEquals(1, result.size()); assertTrue(Bytes.toLong(result.getValue(FAMILY, QUALIFIER)) > 500); expectedIndex++; } assertEquals(4, expectedIndex); scanner.close(); }