首页 > 其他分享 >补实验

补实验

时间:2024-12-03 23:10:28浏览次数:3  
标签:hadoop client 实验 org apache import hbase

import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;

public class RowCountMapper extends TableMapper<Text, LongWritable> {
    private static final LongWritable ONE = new LongWritable(1);
    private Text rowKey = new Text();

    @Override
    protected void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException {
        rowKey.set(key.get());
        context.write(new Text("rowCount"), ONE);
    }
}
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
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.Table;

public class CountRows {
    public static void main(String[] args) throws Exception {
        org.apache.hadoop.conf.Configuration config = HBaseConfiguration.create();
        Connection connection = ConnectionFactory.createConnection(config);
        Table table = connection.getTable(TableName.valueOf("shujuku"));
        
        Scan scan = new Scan();
        ResultScanner scanner = table.getScanner(scan);
        
        int rowCount = 0;
        for (Result result : scanner) {
            rowCount++;
        }
        
        scanner.close();
        connection.close();
        
        System.out.println("Row count: " + rowCount);
    }
}
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;

import java.util.ArrayList;
import java.util.List;

public class ClearTableData {
    public static void main(String[] args) throws Exception {
        org.apache.hadoop.conf.Configuration config = HBaseConfiguration.create();
        Connection connection = ConnectionFactory.createConnection(config);
        Table table = connection.getTable(TableName.valueOf("shujuku"));
        
        Scan scan = new Scan();
        List<Delete> deletes = new ArrayList<>();
        
        table.getScanner(scan).forEach(result -> {
            Delete delete = new Delete(result.getRow());
            deletes.add(delete);
        });
        
        table.delete(deletes);
        
        System.out.println("All records deleted successfully.");
        connection.close();
    }
}

 

标签:hadoop,client,实验,org,apache,import,hbase
From: https://www.cnblogs.com/muzhaodi/p/18585245

相关文章

  • 程序设计实验五
    任务1task1.cpp1#include"publisher.hpp"2#include<vector>3#include<typeinfo>45usingstd::vector;67voidtest(){8vector<Publisher*>v;910v.push_back(newBook("HarryPotter","......
  • 实验5
    #pragmaonce#include<iostream>#include<string>usingstd::cout;usingstd::endl;usingstd::string;//发行/出版物类:Publisher(抽象类)classPublisher{public:Publisher(conststring&s="");//构造函数public:virtualvoi......
  • 20222305 2024-2025-1 《网络与系统攻防技术》实验八实验报告
    网络攻防实验报告姓名:田青学号:20222305实验日期:2024/11/30—2024/12/07实验名称:Web安全指导教师:王志强1.学习内容1.Web前端:负责开发用户所看到的内容。前端语言:HTML、JavaScript(JS):与Java没有关系,与JSP两回事,CSS。Web前端框架:Vue.js(中国人尤雨溪)、Bootstrap(Twitter)、La......
  • 实验五
    实验任务1:task1_1.c源代码:1#include<stdio.h>2#defineN53voidinput(intx[],intn);4voidoutput(intx[],intn);5voidfind_min_max(intx[],intn,int*pmin,int*pmax);6intmain()7{8inta[N];9intmin,max;1011p......
  • 实验五
    实验任务三:#include<iostream>usingnamespacestd;#include<string>#include<vector>classMachinePets{private:stringnickname;public:MachinePets(conststrings);virtualstringtalk()=0;stringget_nickname()const;......
  • 实验5 继承和多态
    实验任务3程序源码:pets.hpp:点击查看代码#pragmaonce#include<iostream>#include<string>usingstd::cout;usingstd::endl;usingstd::string;classMachinePets{public: MachinePets(conststrings); virtualstringtalk()const=0; virtualstring......
  • C语言实验 循环结构2
    时间:2024.12.3一、实验7-1求符合给定条件的整数集#include<stdio.h>intmain(){inta,b,s,g;scanf("%d",&a);inth=0;for(inti=a;i<=a+3;i++){for(intj=a;j<=a+3;j++){for(intk=a;k<=a+3;k++){if((i!=j)&&(i!......
  • C语言实验 一维数组
    时间:2024.12.3一、实验7-1交换最小值和最大值#include<stdio.h>intmain(){intn,a[10],i,min=0,max=0;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&a[i]);}for(i=0;i<n;i......
  • 20222303 2021-2022-1 《网络与系统攻防技术》实验八实验报告
    1.实验内容及要求1.1实验内容本周,通过学习HTML,我对Web安全有了更深入的理解。我掌握了如何创建和使用表单,并学习了GET和POST方法的区别与应用。此外,我了解了MySQL的基本操作,如创建数据库、管理用户和操作表格。在此过程中,我学会了如何利用恶意SQL语句绕过认证并获取敏感信息,同时......
  • Springboot实验室管理系统i0o0a
    Springboot实验室管理系统i0o0a本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表项目功能:用户,实验室信息,实验器材,实验耗材,实验室预约开题报告内容一、项目背景随着教育信息化的快速发展,传统实验室管理......