name English Math Computer
zhangsan 60 86 77
lisi 55 100 88
根据上面给出的学生表 Student 的信息,执行如下操作:

(1)用 Hbase Shell 命令创建学生表 Student
在这里插入图片描述(2)用 scan 指令浏览 Student 表的相关信息
在这里插入图片描述
(3)查询 zhangsan 的 Computer 成绩

在这里插入图片描述
(4)修改 lisi 的 Math 成绩,改为 95
在这里插入图片描述

根据上面已经设计出的 Student 表,用 HBase API 编程实现以下操作:

(1)添加数据

scofield 45 89 100
package Main;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;

public class main {

    public static Configuration configuration;
    public static Connection connection;
    public static Admin admin;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        configuration  = HBaseConfiguration.create();
        configuration.set("hbase.rootdir","hdfs://127.0.0.1:8020/hbase");
        try{
            connection = ConnectionFactory.createConnection(configuration);
            admin = connection.getAdmin();
        }catch (IOException e){
            e.printStackTrace();
        }
        try {
            insertRow("student","scofield","score","English","45");
            insertRow("student","scofield","score","Math","89");
            insertRow("student","scofield","score","Computer","100");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        close();
    }
    public static void insertRow(String tableName,String rowKey,String colFamily,
                                 String col,String val) throws IOException {
        Table table = connection.getTable(TableName.valueOf(tableName));
        Put put = new Put(rowKey.getBytes());
        put.addColumn(colFamily.getBytes(), col.getBytes(), val.getBytes());
        table.put(put);
        table.close();
    }
    public static void close(){
        try{
            if(admin != null){
                admin.close();
            }
            if(null != connection){
                connection.close();
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}


运行结果
在这里插入图片描述

(2)获取 scofield 的 English 成绩信息

package Main;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;

public class main {

    public static Configuration configuration;
    public static Connection connection;
    public static Admin admin;

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        configuration = HBaseConfiguration.create();

        configuration.set("hbase.rootdir", "hdfs://127.0.0.1:8020/hbase");

        try {
            connection = ConnectionFactory.createConnection(configuration);
            admin = connection.getAdmin();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            getData("student", "scofield", "score", "English");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        close();
    }

    public static void getData(String tableName, String rowKey, String colFamily,
                               String col) throws IOException {
        Table table = connection.getTable(TableName.valueOf(tableName));
        Get get = new Get(rowKey.getBytes());
        get.addColumn(colFamily.getBytes(), col.getBytes());
        Result result = table.get(get);
        showCell(result);
        table.close();
    }

    public static void showCell(Result result) {
        Cell[] cells = result.rawCells();
        for (Cell cell : cells) {
            System.out.println("RowName:" + new String(CellUtil.cloneRow(cell)) + " ");
            System.out.println("Timetamp:" + cell.getTimestamp() + " ");
            System.out.println("column Family:" + new String(CellUtil.cloneFamily(cell)) + " ");
            System.out.println("row Name:" + new String(CellUtil.cloneQualifier(cell)) + " ");
            System.out.println("value:" + new String(CellUtil.cloneValue(cell)) + " ");
        }
    }

    public static void close() {
        try {
            if (admin != null) {
                admin.close();
            }
            if (null != connection) {
                connection.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


运行结果

在这里插入图片描述

Redis 数据库操作

Student 键值对如下:

zhangsan:{
English: 69
Math: 86
Computer: 77

lisi:{
English: 55
Math: 100
Computer: 88
}

根据上面给出的键值对,完成如下操作:

(1)用 Redis 的哈希结构设计出学生表 Student(键值可以用 student.zhangsan 和student.lisi 来表示两个键值属于同一个表);
在这里插入图片描述
(2)用 hgetall 命令分别输出 zhangsan 和 lisi 的成绩信息;

在这里插入图片描述
(3)用 hget 命令查询 zhangsan 的 Computer 成绩;
在这里插入图片描述
(4)修改 lisi 的 Math 成绩,改为 95
在这里插入图片描述

根据上面已经设计出的学生表 Student,用 Redis 的 JAVA 客户端编程(jedis),实现如下操作:

(1)添加数据:English:69 Math:86 Computer:77
scofield:{
English: 69
Math: 86
Computer: 77

package Main;

import java.util.Map;
import redis.clients.jedis.Jedis;

public class main {

    /\*\*
 \* @param args
 \*/
    public static void main(String[] args) {
        Jedis jedis = new Jedis("127.0.0.1:6379");
        jedis.hset("student.scofield", "English","45");
        jedis.hset("student.scofield", "Math","89");
        jedis.hset("student.scofield", "Computer","100");
        Map<String,String>  value = jedis.hgetAll("student.scofield");
        for(Map.Entry<String, String> entry:value.entrySet())
        {
            System.out.println(entry.getKey()+":"+entry.getValue());
        }
    }
}

(2)获取 scofield 的 English 成绩信息
package Main;

import java.util.Map;
import redis.clients.jedis.Jedis;

public class main {

    /\*\*
 \* @param args
 \*/
    public static void main(String[] args) {
        Jedis jedis = new Jedis("localhost");
        jedis.hset("student.scofield", "English","45");
        jedis.hset("student.scofield", "Math","89");
        jedis.hset("student.scofield", "Computer","100");
        Map<String,String>  value = jedis.hgetAll("student.scofield");
        for(Map.Entry<String, String> entry:value.entrySet())
        {
            System.out.println(entry.getKey()+":"+entry.getValue());
        }
    }
}


(四)MongoDB 数据库操作

Student 文档如下:
{
“name”: “zhangsan”, “score”: {“English”: 69, “Math”: 86, “Computer”: 77}
}

{
“name”: “lisi”, “score”: {“English”: 55, “Math”: 100,“Computer”: 88}
}

根据上面给出的文档,完成如下操作:

(1)用 MongoDB Shell 设计出 student 集合;
在这里插入图片描述

(2)用 find()方法输出两个学生的信息;

在这里插入图片描述

(3)用 find 函数查询 zhangsan 的所有成绩(只显示 score 列)
在这里插入图片描述
(4)修改 lisi 的 Math 成绩,改为 95。
在这里插入图片描述

根据上面已经设计出的 Student 集合,用 MongoDB 的 Java 客户端编程,实现如下操作:

(1)添加数据:English:45 Math:89 Computer:100

与上述数据对应的文档形式如下:
“name”: “scofield”,
“score”: {“English”: 45,“Math”: 89, “Computer”: 100}

package Main;

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

import org.bson.Document;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;

public class main {

    public static void main(String[] args) {

        MongoClient mongoClient = new MongoClient("localhost", 27017);

        MongoDatabase mongoDatabase = mongoClient.getDatabase("student");

        MongoCollection<Document> collection = mongoDatabase.getCollection("student");

        Document document = new Document("name", "scofield").
                append("score", new Document("English", 45).
                        append("Math", 89).
                        append("Computer", 100));
        List<Document> documents = new ArrayList<Document>();
        documents.add(document);
        collection.insertMany(documents);
        System.out.println("文档插入成功");
    }
}




**自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。**

**深知大多数大数据工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**

**因此收集整理了一份《2024年大数据全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。**
![img](https://img-blog.csdnimg.cn/img_convert/5196582d50a39781102f32db6f9a4f04.png)
![img](https://img-blog.csdnimg.cn/img_convert/0082eb5ac8347eebc42f18dcc36a7681.png)
![img](https://img-blog.csdnimg.cn/img_convert/179f928c4fb422d43a87b95e02cc6585.png)
![img](https://img-blog.csdnimg.cn/img_convert/6fbfa790d992ebfd08530264589677b0.png)
![img](https://img-blog.csdnimg.cn/img_convert/814afe56f54ebfac3126f43b385cd547.png)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上大数据开发知识点,真正体系化!**

**由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**

**如果你觉得这些内容对你有帮助,可以添加VX:vip204888 (备注大数据获取)**
![img](https://img-blog.csdnimg.cn/img_convert/99c969246df40002594b880ce4d65ba8.png)

**一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

)]
[外链图片转存中...(img-4LrMqElk-1713021612913)]

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上大数据开发知识点,真正体系化!**

**由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**

**如果你觉得这些内容对你有帮助,可以添加VX:vip204888 (备注大数据获取)**
[外链图片转存中...(img-Q7pDpa38-1713021612913)]

**一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐