设为首页 加入收藏

TOP

大数据——综合案例(二)
2023-07-23 13:34:35 】 浏览:80
Tags:
che.hadoop.hbase.KeyValue;

import org.apache.hadoop.hbase.client.Get;

import org.apache.hadoop.hbase.client.HBaseAdmin;

import org.apache.hadoop.hbase.client.HTable;

import org.apache.hadoop.hbase.client.Put;

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.util.Bytes;

public class HBaseImportTest extends Thread {

    public Configuration config;

    public HTable table;

    public HBaseAdmin admin;

    public HBaseImportTest() {

        config = HBaseConfiguration.create();

//      config.set("hbase.master", "master:60000");

//      config.set("hbase.zookeeper.quorum", "master");

        try {

            table = new HTable(config, Bytes.toBytes("user_action"));

            admin = new HBaseAdmin(config);

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

    public static void main(String[] args) throws Exception {

        if (args.length == 0) {       //第一个参数是该jar所使用的类,第二个参数是数据集所存放的路径

            throw new Exception("You must set input path!");

        }

        String fileName = args[args.length-1];  //输入的文件路径是最后一个参数

        HBaseImportTest test = new HBaseImportTest();

        test.importLocalFileToHBase(fileName);

    }

    public void importLocalFileToHBase(String fileName) {

        long st = System.currentTimeMillis();

        BufferedReader br = null;

        try {

            br = new BufferedReader(new InputStreamReader(new FileInputStream(

                    fileName)));

            String line = null;

            int count = 0;

            while ((line = br.readLine()) != null) {

                count++;

                put(line);

    &

首页 上一页 1 2 3 4 5 下一页 尾页 2/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Linux中CentOS 7的安装及Linux常.. 下一篇Linux中CentOS 7版本安装JDK、Tom..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目