0

HDFS で HBASE 0.94.8 を使用しています。値の合計のためにコプロセッサを実装しました。テーブルには 2 つの行しかありません。

hbase(メイン):043:0> スキャン 'デモ'

行の列 + セル

行 1 列 = 情報: カテゴリ、タイムスタンプ = 1375438808010、値 = Web
行 1 列 = 情報: ヒット、タイムスタンプ = 1375438797824、値 = 123
行 2 列 = 情報: カテゴリ、タイムスタンプ = 1375438834518、値 = メール
行 2 列 = 情報: ヒット、タイムスタンプ=1375438822093、値=1321

hbase(main):043:0> 「デモ」を記述

'demo', {METHOD => 'table_att', coprocessor$1 => '|org.apache.hadoop.hbase.coprocess true
or.AggregateImplementation||'}, {NAME => 'info', DATA_BLOCK_ENCODING => 'NONE' 、BLOO MFILTER => 'NONE'、REPLICATION_SCOPE => '0'、バージョン => '3'、圧縮 => 'NONE'、
MIN_VERSIONS => '0'、TTL => '2147483647'、KEEP_DELETED_CELLS => 'false' , BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOCKCACHE => 'true'} 0.0670 秒で 1 行

私のコードは以下のとおりです。

import org.apache.hadoop.conf.Configuration; 
import org.apache.hadoop.hbase.HBaseConfiguration; 
import org.apache.hadoop.hbase.HColumnDescriptor; 
import org.apache.hadoop.hbase.HTableDescriptor; 
import org.apache.hadoop.hbase.KeyValue; 
import org.apache.hadoop.hbase.client.HBaseAdmin; 
import org.apache.hadoop.hbase.client.HTable; 
import org.apache.hadoop.hbase.client.Result; 
import org.apache.hadoop.hbase.client.ResultScanner; 
import org.apache.hadoop.hbase.client.Scan; 
import org.apache.hadoop.hbase.client.coprocessor.AggregationClient; 
import org.apache.hadoop.hbase.client.coprocessor.LongColumnInterpreter;
import org.apache.hadoop.hbase.util.Bytes; 
import org.apache.hadoop.hbase.coprocessor.ColumnInterpreter; 
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
public class webAggregator {

   // private static final byte[] EDRP_FAMILY = Bytes.toBytes("EDRP");
   // private static final byte[] EDRP_QUALIFIER = Bytes.toBytes("advanceKWh");
   public static void testSumWithValidRange(Configuration conf,
                 String[] otherArgs) throws Throwable {
          byte[] EDRP_TABLE = Bytes.toBytes(otherArgs[0]);
          byte[] EDRP_FAMILY = Bytes.toBytes(otherArgs[1]);
          byte[] EDRP_QUALIFIER = Bytes.toBytes(otherArgs[2]);

          conf.set("hbase.zookeeper.quorum", "master");
          conf.set("hbase.zookeeper.property.clientPort", "2222");

          conf.setLong("hbase.rpc.timeout", 600000);

          conf.setLong("hbase.client.scanner.caching", 1000);
          conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
                       "org.apache.hadoop.hbase.coprocessor.AggregateImplementation");

          // Utility.CreateHBaseTable(conf, otherArgs[1], otherArgs[2], true);
          /*HBaseAdmin admin = new HBaseAdmin(conf);
          HTableDescriptor desc = new HTableDescriptor(EDRP_TABLE);
          desc.addFamily(new HColumnDescriptor(EDRP_FAMILY));
          admin.createTable(desc);*/

          AggregationClient aClient = new AggregationClient(conf);
          Scan scan = new Scan();
          scan.addColumn(EDRP_FAMILY, EDRP_QUALIFIER);


          HTable table = new HTable(conf, "demo");
          Scan s = new Scan();
          ResultScanner ss = table.getScanner(s);
          for(Result r:ss){
              for(KeyValue kv : r.raw()){
                 System.out.print(new String(kv.getRow()) + " ");
                 System.out.print(new String(kv.getFamily()) + ":");
                 System.out.print(new String(kv.getQualifier()) + " ");
                 System.out.print(kv.getTimestamp() + " ");
                 System.out.println(new String(kv.getValue()));
              }
          }

          final ColumnInterpreter<Long, Long> ci = new LongColumnInterpreter();
          long sum = aClient.sum(Bytes.toBytes(otherArgs[0]), ci, scan);
          System.out.println(sum);
   }

   /**
   * Main entry point.
   *
   * @param argsThe
   *            command line parameters.
   * @throws Exception
   *             When running the job fails.
   */
   public static void main(String[] args) throws Exception {
     Configuration conf = HBaseConfiguration.create();
       String[] otherArgs ={"demo","info","hits"};
      try {
         testSumWithValidRange(conf, otherArgs);
       } catch (Throwable e) {
         e.printStackTrace();
       }
   } }

MY スタック トレースを以下に示します。

webAggregator.main(webAggregator.java:79) での webAggregator.testSumWithValidRange(webAggregator.java:62) での java.lang.NullPointerException

これについて助けてください。

4

2 に答える 2

0

あなたと同じエラーが発生しました。調査の結果、列の型が整数であるため、LongColumnInterpreter.getValue メソッドが null を返すことが問題であることがわかりました。

コードと結果から、「info:hits」列は文字列列ですが、長い列ではないと確信しています。

hbase シェルからの値は次のようになります。

11Ak8Z4Mswtk00:MXf1NZ                        column=f1:dp, timestamp=1400144073173, value=\x00\x00\x00\x00\x00\x00\x00b 

または、ColumnInterpreter を自分で記述して、文字列値の合計を処理することもできます。

于 2014-05-15T09:35:26.050 に答える