Clover Coverage Report - hbase-handler
Coverage timestamp: Fri Apr 27 2012 21:39:41 UTC
../../../../../img/srcFileCovDistChart0.png 15% of files have more coverage
19   135   11   2.38
6   53   0.58   8
8     1.38  
1    
 
  HBaseStatsUtils       Line # 32 19 11 0% 0.0
 
No Tests
 
1    /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    package org.apache.hadoop.hive.hbase;
20   
21    import java.util.ArrayList;
22    import java.util.Collection;
23    import java.util.HashMap;
24    import java.util.List;
25    import java.util.Map;
26   
27    import org.apache.hadoop.hbase.util.Bytes;
28    import org.apache.hadoop.hive.ql.stats.StatsSetupConst;
29   
30   
31   
 
32    public class HBaseStatsUtils {
33   
34    private static final List<String> supportedStats = new ArrayList<String>();
35    private static final Map<String, String> columnNameMapping = new HashMap<String, String>();
36   
 
37  0 toggle static {
38    // supported statistics
39  0 supportedStats.add(StatsSetupConst.ROW_COUNT);
40  0 supportedStats.add(StatsSetupConst.RAW_DATA_SIZE);
41   
42    // row count statistics
43  0 columnNameMapping.put(StatsSetupConst.ROW_COUNT,
44    HBaseStatsSetupConstants.PART_STAT_ROW_COUNT_COLUMN_NAME);
45   
46    // raw data size
47  0 columnNameMapping.put(StatsSetupConst.RAW_DATA_SIZE,
48    HBaseStatsSetupConstants.PART_STAT_RAW_DATA_SIZE_COLUMN_NAME);
49   
50    }
51   
52    /**
53    * Returns the set of supported statistics
54    */
 
55  0 toggle public static List<String> getSupportedStatistics() {
56  0 return supportedStats;
57    }
58   
59    /**
60    * Retrieves the value for a particular stat from the published map.
61    *
62    * @param statType
63    * - statistic type to be retrieved from the map
64    * @param stats
65    * - stats map
66    * @return value for the given statistic as string, "0" if the statistic is not present
67    */
 
68  0 toggle public static String getStatFromMap(String statType, Map<String, String> stats) {
69  0 String value = stats.get(statType);
70  0 if (value == null) {
71  0 return "0";
72    }
73  0 return value;
74    }
75   
76    /**
77    * Check if the set to be published is within the supported statistics.
78    * It must also contain at least the basic statistics (used for comparison).
79    *
80    * @param stats
81    * - stats to be published
82    * @return true if is a valid statistic set, false otherwise
83    */
84   
 
85  0 toggle public static boolean isValidStatisticSet(Collection<String> stats) {
86  0 if(!stats.contains(getBasicStat())) {
87  0 return false;
88    }
89  0 for (String stat : stats) {
90  0 if (!supportedStats.contains(stat)) {
91  0 return false;
92    }
93    }
94  0 return true;
95    }
96   
97    /**
98    * Check if a particular statistic type is supported
99    *
100    * @param statType
101    * - statistic to be published
102    * @return true if statType is supported, false otherwise
103    */
 
104  0 toggle public static boolean isValidStatistic(String statType) {
105  0 return supportedStats.contains(statType);
106    }
107   
108    /**
109    * Returns the HBase column where the statistics for the given type are stored.
110    *
111    * @param statType
112    * - supported statistic.
113    * @return column name for the given statistic.
114    */
 
115  0 toggle public static byte[] getColumnName(String statType) {
116  0 return Bytes.toBytes(columnNameMapping.get(statType));
117    }
118   
119    /**
120    * Returns the family name for stored statistics.
121    */
 
122  0 toggle public static byte[] getFamilyName() {
123  0 return Bytes.toBytes(HBaseStatsSetupConstants.PART_STAT_COLUMN_FAMILY);
124    }
125   
126    /**
127    * Returns the basic type of the supported statistics.
128    * It is used to determine which statistics are fresher.
129    */
130   
 
131  0 toggle public static String getBasicStat() {
132  0 return supportedStats.get(0);
133    }
134   
135    }