Java Code Examples for org.apache.hadoop.hbase.client.ResultScanner#forEach()
The following examples show how to use
org.apache.hadoop.hbase.client.ResultScanner#forEach() .
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: HBaseFilterTest.java From BigData-In-Practice with Apache License 2.0 | 6 votes |
@Test public void rowFilterTest() { Filter filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("rowkey1"))); FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE, Arrays.asList(filter)); ResultScanner scanner = HBaseUtil .getScanner("FileTable", "rowkey1", "rowkey3", filterList); if (scanner != null) { scanner.forEach(result -> { System.out.println("rowkey=" + Bytes.toString(result.getRow())); System.out.println("fileName=" + Bytes .toString(result.getValue(Bytes.toBytes("fileInfo"), Bytes.toBytes("name")))); }); scanner.close(); } }
Example 2
Source File: HBaseFilterTest.java From BigData-In-Practice with Apache License 2.0 | 6 votes |
@Test public void prefixFilterTest() { Filter filter = new PrefixFilter(Bytes.toBytes("rowkey2")); FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL, Arrays.asList(filter)); ResultScanner scanner = HBaseUtil .getScanner("FileTable", "rowkey1", "rowkey3", filterList); if (scanner != null) { scanner.forEach(result -> { System.out.println("rowkey=" + Bytes.toString(result.getRow())); System.out.println("fileName=" + Bytes .toString(result.getValue(Bytes.toBytes("fileInfo"), Bytes.toBytes("name")))); }); scanner.close(); } }
Example 3
Source File: HBaseFilterTest.java From BigData-In-Practice with Apache License 2.0 | 6 votes |
@Test public void keyOnlyFilterTest() { Filter filter = new KeyOnlyFilter(true); FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL, Arrays.asList(filter)); ResultScanner scanner = HBaseUtil .getScanner("FileTable", "rowkey1", "rowkey3", filterList); if (scanner != null) { scanner.forEach(result -> { System.out.println("rowkey=" + Bytes.toString(result.getRow())); System.out.println("fileName=" + Bytes .toString(result.getValue(Bytes.toBytes("fileInfo"), Bytes.toBytes("name")))); }); scanner.close(); } }
Example 4
Source File: HBaseFilterTest.java From BigData-In-Practice with Apache License 2.0 | 6 votes |
@Test public void columnPrefixFilterTest() { Filter filter = new ColumnPrefixFilter(Bytes.toBytes("nam")); FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL, Arrays.asList(filter)); ResultScanner scanner = HBaseUtil .getScanner("FileTable", "rowkey1", "rowkey3", filterList); if (scanner != null) { scanner.forEach(result -> { System.out.println("rowkey=" + Bytes.toString(result.getRow())); System.out.println("fileName=" + Bytes .toString(result.getValue(Bytes.toBytes("fileInfo"), Bytes.toBytes("name")))); System.out.println("fileType=" + Bytes .toString(result.getValue(Bytes.toBytes("fileInfo"), Bytes.toBytes("type")))); }); scanner.close(); } }
Example 5
Source File: HBaseUtilTest.java From BigData-In-Practice with Apache License 2.0 | 5 votes |
@Test public void scanFileDetails() { ResultScanner scanner = HBaseUtil.getScanner("FileTable", "rowkey2", "rowkey2"); if (scanner != null) { scanner.forEach(result -> { System.out.println("rowkey=" + Bytes.toString(result.getRow())); System.out.println("fileName=" + Bytes .toString(result.getValue(Bytes.toBytes("fileInfo"), Bytes.toBytes("name")))); }); scanner.close(); } }
Example 6
Source File: HbaseImpl.java From tephra with MIT License | 5 votes |
@Override public JSONArray queryAsJson(HbaseQuery query) { JSONArray array = new JSONArray(); if (isDisabled() || query == null) return array; if (validator.isEmpty(query.tableName)) { logger.warn(null, "表名称为空,检索失败!"); return array; } try { Table table = getTable(query.getTableName()); ResultScanner scanner = query(table, query.getFilter()); scanner.forEach(result -> { JSONObject object = new JSONObject(); setToJson(object, Bytes.toString(result.getRow()), result); array.add(object); }); scanner.close(); table.close(); } catch (IOException e) { logger.warn(e, "检索HBase数据[{}]时发生异常!", query.getTableName()); } return array; }