Changes between Initial Version and Version 1 of waue/2011/0425_Itri5ShowReport


Ignore:
Timestamp:
Apr 25, 2011, 4:21:47 PM (13 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2011/0425_Itri5ShowReport

    v1 v1  
     1{{{
     2#!java
     3
     4package itri;
     5
     6
     7
     8// ITRI serial program number 5
     9
     10// 0. after Itri4SortTurnover
     11
     12// run it
     13
     14
     15
     16import java.io.IOException;
     17
     18
     19
     20import org.apache.hadoop.conf.Configuration;
     21
     22import org.apache.hadoop.fs.Path;
     23
     24import org.apache.hadoop.hbase.HBaseConfiguration;
     25
     26import org.apache.hadoop.hbase.HConstants;
     27
     28import org.apache.hadoop.hbase.client.Result;
     29
     30import org.apache.hadoop.hbase.client.ResultScanner;
     31
     32import org.apache.hadoop.hbase.client.tableindexed.IndexedTable;
     33
     34import org.apache.hadoop.hbase.filter.CompareFilter;
     35
     36import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
     37
     38import org.apache.hadoop.hbase.util.Bytes;
     39
     40import org.apache.hadoop.util.GenericOptionsParser;
     41
     42
     43
     44public 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}}}