ToB企服应用市场:ToB评测及商务社交产业平台

标题: 云计算复习索引 [打印本页]

作者: 万有斥力    时间: 2022-6-21 11:05
标题: 云计算复习索引
每晚睡前复习一个题,云计算必高分过系列
为了提高学习效率,这里搬个友链

这里写目录标题



以下所有内容可能有误,请自行甄别

一. HBase && Spark

1. HBase

启动集群后:

① Shell

其中apple为表名,0001为行键,base_info为列族(必须是已经创建了的),weight为列名,89为具体的值

其余可参考

在上图中,在创建表的时候,可以用命令:
create "Student","Stuinfo","Grades"
列族是可以后续添加的,比如:
alter "apple","extra_info"
再插入数据:
put "apple","0001","extra_info:grade","good"
然后继续插入信息可以查看到更新后的表信息:


scan "apple"用来获取所有的信息
apple为表名

在结果中我们可以看到两部分
第一部分是:ROW为0001
第二部分是:COLUMN(包含列的名字列族:列名的形式)+CELL(时间戳和值)
指定获取某个值:
get "apple","0001","base_info:weight"
其中,apple为表名,0001为行键,base_info为列族,weight为列名

   插入的区别(个人总结,可能不对):
      删除的区别(来自网络 && 个人总结):
    ② IDE 下 CRUD

给定JSON or XML数据
比如:

或者是:

或者是xml格式:

转换为二维表就是:

  1. public static void getConnect() throws IOException
  2. {
  3.                 conf.set("hbase.zookeeper.quorum", "master315");
  4.                 conf.set("hbase.zookeeper.property.clientPort", "2181");
  5.                 //conf.set("zookeeper.znode.parent", "/hbase");
  6.                 try{ connection=ConnectionFactory.createConnection(conf);  }
  7.                 catch(IOException e){     }
  8. }
复制代码
其中master315为主机名
2. 创建表
  1. //创建一张表,通过HBaseAdmin HTableDescriptor来创建  
  2. public static void createTable(String tablename) throws Exception {
  3.     TableName tableName = TableName.valueOf(tablename);
  4.     Admin admin = connection.getAdmin();
  5.     if (admin.tableExists(tableName)) {
  6.         admin.disableTable(tableName);
  7.         admin.deleteTable(tableName);
  8.         System.out.println(tablename + " table Exists, delete ......");
  9.     }
  10.     @SuppressWarnings("deprecation")
  11.     HTableDescriptor desc = new HTableDescriptor(tableName);
  12.     @SuppressWarnings("deprecation")
  13.     HColumnDescriptor colDesc = new HColumnDescriptor("base_info");
  14.     colDesc.setBloomFilterType(BloomType.ROWCOL);
  15.     desc.addFamily(colDesc);
  16.     desc.addFamily(new HColumnDescriptor("extra_info"));
  17.     admin.createTable(desc);
  18.     admin.close();
  19.     System.out.println("create table success!");
  20. }
复制代码
  1. public static void addData(String tablename) throws Exception {
  2.                 HTable table = (HTable) connection.getTable(TableName.valueOf(tablename));
  3.                 Put p1 = new Put(Bytes.toBytes("0001"));
  4.                 p1.addColumn(Bytes.toBytes("base_info"), Bytes.toBytes("weight"), Bytes.toBytes(String.valueOf(89)));
  5.                 p1.addColumn(Bytes.toBytes("base_info"), Bytes.toBytes("caption"), Bytes.toBytes("GuoGuang"));
  6.                 p1.addColumn(Bytes.toBytes("base_info"), Bytes.toBytes("production"), Bytes.toBytes("LongKou"));
  7.                 p1.addColumn(Bytes.toBytes("extra_info"), Bytes.toBytes("grade"), Bytes.toBytes("good"));
  8.                 table.put(p1);
  9.                 Put p2 = new Put(Bytes.toBytes("0002"));
  10.                 p2.addColumn(Bytes.toBytes("base_info"), Bytes.toBytes("weight"), Bytes.toBytes(String.valueOf(50)));
  11.                 p2.addColumn(Bytes.toBytes("base_info"), Bytes.toBytes("caption"), Bytes.toBytes("HongFuShi"));
  12.                 table.put(p2);
  13.                 
  14.                 table.close();
  15.                 System.out.print("insert successed");
  16.                 }
复制代码
shell可查:

[code]public static void getData(String tablename) throws IOException {        HTable table = (HTable) connection.getTable(TableName.valueOf(tablename));        for (int i = 1; i




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4