大数据小问题

作者: kason_zhang | 来源:发表于2018-04-25 23:10 被阅读18次

1 Hadoop Mapreduce 提交YARN jar包冲突问题

最近开发遇到一个jar包冲突的问题, 我们的应用程序里需要操作httpclient-4.5.2.jar和httpcore-4.5.2.jar 这两个jar包,而Hadoop 本身提供的jar包版本是httpclient-4.2.5.jar,httpcore-4.2.5.jar,


image.png

而当我们使用hadoop jar 可执行性Jar Main class时Hadoop 会先加载自己的jar而忽略应用程序的版本,这时候就会出现class not found exception等问题。

解决方案:加入下面这个

-Dmapreduce.task.classpath.user.precedence=true -libjars httpclient-4.5.2.jar httpcore-4.5.2.jar 强制执行用户的jar包

2 Hbase按Region 进行Scan

private static void checkTable(String tabName) throws Exception {
        TableName tn = TableName.valueOf(tabName);
        Configuration config = HBaseConfiguration.create();
        HRegionInfo regionInfo;
        Connection connection = null;
        Admin admin = null;
        Table table = null;
        try  {
            connection = ConnectionFactory.createConnection(config);
            admin = connection.getAdmin();
            table = connection.getTable(tn);

            if (!admin.tableExists(TableName.valueOf(tabName))) {
                return;
            }
            List<HRegionInfo> lr = admin.getTableRegions(tn);
            Result r = null;

            if (lr == null) {
                System.out.print("No region found for table " + tabName);
            }
            // 遍历表的每个region
            Iterator<HRegionInfo> ir = lr.iterator();

            int i = 1;
            while (ir.hasNext()) {
                regionInfo = ir.next();

                ResultScanner scanner = null;
                byte[] startRowkey = regionInfo.getStartKey();
                System.out.println("----start----" + Bytes.toString(startRowkey));
                byte[] endKey = regionInfo.getEndKey();
                System.out.println("----end----" + Bytes.toString(endKey));
                Scan sc = new Scan();
                sc.setBatch(1);
                sc.setStartRow(startRowkey);
                sc.setStopRow(endKey);
                try {
                    scanner = table.getScanner(sc);
                    Iterator<Result> iterator = scanner.iterator();
                    while (iterator.hasNext()) {
                        Result next = iterator.next();
                        byte[] row = next.getRow();
                        System.out.println("第" + i + " 批 " + Arrays.toString(row));
                    }
                } finally {
                    if (null != scanner) {
                        scanner.close();
                    }
                }
                i ++;
            }
        }catch (Exception e) {

        } finally {
            if (null != table) {
                table.close();
            }
            if (null != admin) {
                admin.close();
            }
            if (null != connection) {
                connection.close();
            }
        }
    }

相关文章

  • hadoop 小问题环境设置

    title: hadoop 小问题环境设置tags: 大数据,环境配置, 小问题grammar_cjkRuby: ...

  • 健康大数据如何管理与提取

    小问题大方法(大数据问题) 每个医生都是数据和数据传感器

  • 大数据小问题

    1 Hadoop Mapreduce 提交YARN jar包冲突问题 最近开发遇到一个jar包冲突的问题, 我们的...

  • 2022-04-02 省份发言亮点模型

    大龄到 做大文章,先把小问题做好,然后,大文章就是分割成小问题而已。 大问题也是分割小问题而已。 先弄清基础的,再...

  • 小问题,大奥秘

    今天晚上我正在做奥数题,突然看见了困扰了我两年的一道奥数题,深深地陷入了沉思。我想:今天我一定要把这道题做出来,不...

  • 小问题,大讨论

    最近六年级开始学习一元一次方程,课本要求我们写上结论,数学老师一般都会要求学生养成规范书写的习惯。 但是,六年级的...

  • 第二十七节-递归树

    什么是递归树 递归的思想,就是将大问题分解为小问题,再将小问题分解为小小问题。这样一层一层分解,直到问题的数据规模...

  • 大boss解决小问题

    因为搞活动,立起几个充气门,用绳子和铁钉固定在地上。活动完,铁钉没拔走,留地上了。 一普通员工,发现了,自己试了试...

  • 小问题呈现大困难

    两位数乘两位数的不进位乘法刚刚结束,大部分学生都知道方法,先用第二个乘数的个位乘第一个乘数,乘积的末位与个...

  • 2020-06-30【IO和字节流】

    IO流概述 IO流概述 字节流写数据 写数据的三种方式 字节流写数据的两个小问题 异常处理 字节流读数据 练习

网友评论

    本文标题:大数据小问题

    本文链接:https://www.haomeiwen.com/subject/msuulftx.html