| 1 | {{{ |
| 2 | #!java |
| 3 | |
| 4 | package itri; |
| 5 | |
| 6 | |
| 7 | |
| 8 | // ITRI serial program number 5 |
| 9 | |
| 10 | // 0. after Itri4SortTurnover |
| 11 | |
| 12 | // run it |
| 13 | |
| 14 | |
| 15 | |
| 16 | import java.io.IOException; |
| 17 | |
| 18 | |
| 19 | |
| 20 | import org.apache.hadoop.conf.Configuration; |
| 21 | |
| 22 | import org.apache.hadoop.fs.Path; |
| 23 | |
| 24 | import org.apache.hadoop.hbase.HBaseConfiguration; |
| 25 | |
| 26 | import org.apache.hadoop.hbase.HConstants; |
| 27 | |
| 28 | import org.apache.hadoop.hbase.client.Result; |
| 29 | |
| 30 | import org.apache.hadoop.hbase.client.ResultScanner; |
| 31 | |
| 32 | import org.apache.hadoop.hbase.client.tableindexed.IndexedTable; |
| 33 | |
| 34 | import org.apache.hadoop.hbase.filter.CompareFilter; |
| 35 | |
| 36 | import org.apache.hadoop.hbase.filter.SingleColumnValueFilter; |
| 37 | |
| 38 | import org.apache.hadoop.hbase.util.Bytes; |
| 39 | |
| 40 | import org.apache.hadoop.util.GenericOptionsParser; |
| 41 | |
| 42 | |
| 43 | |
| 44 | public class Itri5ShowReport { |
| 45 | |
| 46 | |
| 47 | |
| 48 | static public void readSortedValGreater(String filter_val) |
| 49 | |
| 50 | throws IOException { |
| 51 | |
| 52 | HBaseConfiguration conf = new HBaseConfiguration(); |
| 53 | |
| 54 | conf.addResource(new Path("/opt/hbase/conf/hbase-site.xml")); |
| 55 | |
| 56 | // the id of the index to use |
| 57 | |
| 58 | String tablename = "itri"; |
| 59 | |
| 60 | String indexId = "Sum"; |
| 61 | |
| 62 | byte[] column_1 = Bytes.toBytes("Turnover:Sum"); |
| 63 | |
| 64 | byte[] column_2 = Bytes.toBytes("Detail:Name"); |
| 65 | |
| 66 | |
| 67 | |
| 68 | byte[] indexStartRow = HConstants.EMPTY_START_ROW; |
| 69 | |
| 70 | byte[] indexStopRow = null; |
| 71 | |
| 72 | byte[][] indexColumns = null; |
| 73 | |
| 74 | |
| 75 | |
| 76 | SingleColumnValueFilter indexFilter = new SingleColumnValueFilter(Bytes |
| 77 | |
| 78 | .toBytes("Turnover"), Bytes.toBytes("Sum"), |
| 79 | |
| 80 | CompareFilter.CompareOp.GREATER_OR_EQUAL, Bytes |
| 81 | |
| 82 | .toBytes(filter_val)); |
| 83 | |
| 84 | |
| 85 | |
| 86 | byte[][] baseColumns = new byte[][] { column_1, column_2 }; |
| 87 | |
| 88 | |
| 89 | |
| 90 | IndexedTable table = new IndexedTable(conf, Bytes.toBytes(tablename)); |
| 91 | |
| 92 | |
| 93 | |
| 94 | ResultScanner scanner = table.getIndexedScanner(indexId, indexStartRow, |
| 95 | |
| 96 | indexStopRow, indexColumns, indexFilter, baseColumns); |
| 97 | |
| 98 | |
| 99 | |
| 100 | for (Result rowResult : scanner) { |
| 101 | |
| 102 | String sum = Bytes.toString(rowResult.getValue(column_1)); |
| 103 | |
| 104 | String name = Bytes.toString(rowResult.getValue(column_2)); |
| 105 | |
| 106 | System.out.println(name + " 's turnover is " + sum + " $."); |
| 107 | |
| 108 | } |
| 109 | |
| 110 | table.close(); |
| 111 | |
| 112 | } |
| 113 | |
| 114 | |
| 115 | |
| 116 | public static void main(String[] argv) throws IOException { |
| 117 | |
| 118 | |
| 119 | |
| 120 | String[] args = new GenericOptionsParser(new Configuration(), argv) |
| 121 | |
| 122 | .getRemainingArgs(); |
| 123 | |
| 124 | if (args.length < 1) { |
| 125 | |
| 126 | System.out.println("Input the MIN number:"); |
| 127 | |
| 128 | return; |
| 129 | |
| 130 | } |
| 131 | |
| 132 | readSortedValGreater(args[0]); |
| 133 | |
| 134 | } |
| 135 | |
| 136 | } |
| 137 | |
| 138 | }}} |