| | 1 | {{{ |
| | 2 | #!java |
| | 3 | |
| | 4 | package itri; |
| | 5 | |
| | 6 | |
| | 7 | |
| | 8 | // ITRI serial program number 4 |
| | 9 | |
| | 10 | // 0. after Itri3CalculateMR |
| | 11 | |
| | 12 | // 1. run addIndexToTurnover() would add index table to itri. |
| | 13 | |
| | 14 | // if you have indexed the table before, don't do it again. |
| | 15 | |
| | 16 | // 2. tune the filter_value in main() and run readSortedValGreater() would show report |
| | 17 | |
| | 18 | |
| | 19 | |
| | 20 | import java.io.IOException; |
| | 21 | |
| | 22 | |
| | 23 | |
| | 24 | import org.apache.hadoop.fs.Path; |
| | 25 | |
| | 26 | import org.apache.hadoop.hbase.HBaseConfiguration; |
| | 27 | |
| | 28 | import org.apache.hadoop.hbase.client.tableindexed.IndexSpecification; |
| | 29 | |
| | 30 | import org.apache.hadoop.hbase.client.tableindexed.IndexedTableAdmin; |
| | 31 | |
| | 32 | import org.apache.hadoop.hbase.util.Bytes; |
| | 33 | |
| | 34 | |
| | 35 | |
| | 36 | public class Itri4SortTurnover { |
| | 37 | |
| | 38 | |
| | 39 | |
| | 40 | public void addIndexToTurnover(String OriTable, String IndexID, |
| | 41 | |
| | 42 | String OriColumn) throws IOException { |
| | 43 | |
| | 44 | HBaseConfiguration conf = new HBaseConfiguration(); |
| | 45 | |
| | 46 | conf.addResource(new Path("/opt/hbase/conf/hbase-site.xml")); |
| | 47 | |
| | 48 | IndexedTableAdmin admin = new IndexedTableAdmin(conf); |
| | 49 | |
| | 50 | admin.tableExists(OriTable); |
| | 51 | |
| | 52 | admin.addIndex(Bytes.toBytes(OriTable), new IndexSpecification(IndexID, |
| | 53 | |
| | 54 | Bytes.toBytes(OriColumn))); |
| | 55 | |
| | 56 | |
| | 57 | |
| | 58 | } |
| | 59 | |
| | 60 | |
| | 61 | |
| | 62 | public static void main(String[] argv) throws IOException { |
| | 63 | |
| | 64 | |
| | 65 | |
| | 66 | Itri4SortTurnover tt = new Itri4SortTurnover(); |
| | 67 | |
| | 68 | tt.addIndexToTurnover("itri", "Sum", "Turnover:Sum"); |
| | 69 | |
| | 70 | } |
| | 71 | |
| | 72 | } |
| | 73 | |
| | 74 | }}} |