利用HBase的coprocessor特性实现聚合函数,添加coprocessor方式有两种
1、修改hbase-site.xml,添加如下内容
<property>
<name>hbase.coprocessor.region.classes</name>
<value>org.apache.hadoop.hbase.coprocessor.AggregateImplementation</value>
</property>
2、通过调用API,让Table注册该Coprocessor
String coprocessClassName = "org.apache.hadoop.hbase.coprocessor.AggregateImplementation";
HBaseAdmin admin = new HBaseAdmin(HBaseConfiguration.create());
admin.disableTable(tableName);
HTableDescriptor htd = admin.getTableDescriptor(tableName);
htd.addCoprocessor(coprocessClassName);
admin.modifyTable(tableName, ht