【问题标题】:NullPointerException when working with Coprocessor in HBASE?在 HBASE 中使用协处理器时出现 NullPointerException?
【发布时间】:2013-08-03 15:17:45
【问题描述】:

我将 HBASE 0.94.8 与 HDFS 一起使用。我已经实现了协处理器来汇总值。该表只有两行

hbase(main):043:0> 扫描“演示”

行列+单元格

row1 列=信息:类别, 时间戳=1375438808010,值=网络
第 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', VERSIONS => '3', 压缩 => '无',
MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => '假',块大小 => '65536', IN_MEMORY => '假', ENCODE_ON_DISK => '真', BLOCKCACHE => 'true'} 1 行 0.0670 秒

我的代码如下:

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();
       }
   } }

我的堆栈跟踪如下:

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

请帮忙。

【问题讨论】:

    标签: hadoop nullpointerexception hbase


    【解决方案1】:

    我遇到了同样的错误。经过一番调查,我发现问题是我的列类型是整数,所以 LongColumnInterpreter.getValue 方法返回 null。

    从您的代码和结果来看,我确信您的“info:hits”列是字符串列,但不是长列。

    只需考虑将 hits 更改为真正的长列,从 hbase shell 其值应如下所示

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

    或者您可以自己编写一个 ColumnInterpreter 来处理字符串值总和。

    【讨论】:

    • 你如何确保它被存储为一个真正的 long?
    【解决方案2】:

    问题是关于数据类型的。

    A. put.addColumn(Bytes.toBytes("objects"), Bytes.toBytes("info"), Bytes.toBytes(1.0));
    

    max/min/sum 没问题。 但是

    B. put.addColumn(Bytes.toBytes("objects"), Bytes.toBytes("info"), Bytes.toBytes("1.0"));
    

    不正常。 而从hbase-shell,我们可以看到

    A. column=objects:info, timestamp=1525942759312, value=?\xF0\x00\x00\x00\x00\x00\x00
    B. column=objects:info, timestamp=1525941054901, value=1.0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-07
      • 2013-01-10
      • 2014-11-14
      • 2020-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多