第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

offset (0) + length (8) exceed the capacity of the array: 1

offset (0) + length (8) exceed the capacity of the array: 1

qq_易永勝_0 2018-02-21 15:05:16
package com.yys.spark.yys_web.utils;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.client.*;import org.apache.hadoop.hbase.filter.Filter;import org.apache.hadoop.hbase.filter.PrefixFilter;import org.apache.hadoop.hbase.util.Bytes;import java.io.IOException;import java.util.HashMap;import java.util.Map;/** * HBase操作工具類 */public class HBaseUtils { ? ?HBaseAdmin admin = null; ? ?Configuration conf = null; ? ?/** ? ? * 私有構(gòu)造方法:加載一些必要的參數(shù) ? ? */ ? ?private HBaseUtils() { ? ? ? ?conf = new Configuration(); ? ? ? ?conf.set("hbase.zookeeper.quorum", "spark:2181"); ? ? ? ?conf.set("hbase.rootdir", "hdfs://spark:9000/hbase"); ? ? ? ?try { ? ? ? ? ? ?admin = new HBaseAdmin(conf); ? ? ? ?} catch (IOException e) { ? ? ? ? ? ?e.printStackTrace(); ? ? ? ?} ? ?} ? ?private static HBaseUtils instance = null; ? ?public static synchronized HBaseUtils getInstance() { ? ? ? ?if (null == instance) { ? ? ? ? ? ?instance = new HBaseUtils(); ? ? ? ?} ? ? ? ?return instance; ? ?} ? ?/** ? ? * 根據(jù)表名獲取到HTable實(shí)例 ? ? */ ? ?public HTable getTable(String tableName) { ? ? ? ?HTable table = null; ? ? ? ?try { ? ? ? ? ? ?table = new HTable(conf, tableName); ? ? ? ?} catch (IOException e) { ? ? ? ? ? ?e.printStackTrace(); ? ? ? ?} ? ? ? ?return table; ? ?} ? ?/** ? ? * 根據(jù)表名和輸入條件獲取HBase的記錄數(shù) ? ? */ ? ?public Map<String, Long> query(String tableName, String condition) throws Exception { ? ? ? ?Map<String, Long> map = new HashMap<>(); ? ? ? ?HTable table = getTable(tableName); ? ? ? ?String cf = "info"; ? ? ? ?String qualifier = "click_count"; ? ? ? ?Scan scan = new Scan(); ? ? ? ?Filter filter = new PrefixFilter(Bytes.toBytes(condition)); ? ? ? ?scan.setFilter(filter); ? ? ? ?ResultScanner rs = table.getScanner(scan); ? ? ? ?for(Result result : rs) { ? ? ? ? ? ?String row = Bytes.toString(result.getRow()); ? ? ? ? ? ?long clickCount = Bytes.toLong(result.getValue(cf.getBytes(), qualifier.getBytes())); ? ? ? ? ? ?map.put(row, clickCount); ? ? ? ?} ? ? ? ?return ?map; ? ?} ? ?public static void main(String[] args) throws Exception { ? ? ? ?Map<String, Long> map = HBaseUtils.getInstance().query("yys_course_clickcount" , "20180220"); ? ? ? ?for(Map.Entry<String, Long> entry: map.entrySet()) { ? ? ? ? ? ?System.out.println(entry.getKey()+ " : " + entry.getValue()); ? ? ? ?} ? ?}}
查看完整描述

1 回答

?
wangsha0

TA貢獻(xiàn)1條經(jīng)驗(yàn) 獲得超0個(gè)贊

cf.getBytes()--->Bytes.toBytes(cf)

or?

long clickCount--->String?clickCount

or?

文件中含有有null值??

查看完整回答
反對(duì) 回復(fù) 2018-02-21
  • 1 回答
  • 0 關(guān)注
  • 2358 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)