hbase shell(1) 的在Hbase中,创建商品信息表goods.go0ds表中有两个列族,infor列表示商品的基 本信息,param列族表示此商品的参数← (2) 向goods表插入2条数据:
时间: 2024-03-23 15:39:01 浏览: 15
1. 使用hbase shell创建goods表,包括两个列族infor和param:
```
create 'goods', 'infor', 'param'
```
2. 向goods表插入2条数据,每条数据包括商品的基本信息和参数,可以使用如下命令:
```
put 'goods', 'row1', 'infor:name', 'product1'
put 'goods', 'row1', 'infor:price', '10'
put 'goods', 'row1', 'infor:color', 'red'
put 'goods', 'row1', 'param:weight', '1kg'
put 'goods', 'row1', 'param:size', 'medium'
put 'goods', 'row2', 'infor:name', 'product2'
put 'goods', 'row2', 'infor:price', '20'
put 'goods', 'row2', 'infor:color', 'blue'
put 'goods', 'row2', 'param:weight', '2kg'
put 'goods', 'row2', 'param:size', 'large'
```
这样,我们就向goods表中成功插入了两条数据。
相关问题
在hbase中,创建商品信息表goods,goos表中有两个列族,infor列族表示商品的基本信息,param列族表示此商品的参数
好的,您的问题是关于 HBase 中创建商品信息表的。那我来回答一下,您可以使用 HBase Shell 或 Java API 来创建表。以下是使用 HBase Shell 创建商品信息表 goods 并添加 infor 和 param 两个列族的命令:
```shell
create 'goods', {NAME => 'infor'}, {NAME => 'param'}
```
这个命令将创建一个名为 goods 的表,并为其添加 infor 和 param 两个列族。您可以根据需要添加更多的列族或列。
当然,如果您使用 Java API,您可以使用 HBaseAdmin 类的 createTable() 方法来创建表。以下是一个简单的示例:
```java
Configuration config = HBaseConfiguration.create();
HBaseAdmin admin = new HBaseAdmin(config);
HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf("goods"));
tableDesc.addFamily(new HColumnDescriptor("infor"));
tableDesc.addFamily(new HColumnDescriptor("param"));
admin.createTable(tableDesc);
```
这个示例使用 HBaseAdmin 类的 createTable() 方法来创建一个名为 goods 的表,并为其添加 infor 和 param 两个列族。
希望这些信息能对您有所帮助。
使用HBASE shell创建学生表(Student)并输入内容,要求学生表有两个列族
以下是使用 HBase shell 创建学生表 Student 并输入内容,表中包含两个列族的示例:
1. 打开 HBase shell:在命令行中输入 `hbase shell` 并回车。
2. 创建表:输入 `create 'Student', {NAME=>'info'}, {NAME=>'score'}` 并回车。此命令创建了名为 Student 的表和两个列族,分别为 info 和 score。
3. 输入数据:输入以下命令并回车,将数据插入到表中。
```
put 'Student', '1001', 'info:name', 'Alice'
put 'Student', '1001', 'info:age', '20'
put 'Student', '1001', 'score:chinese', '90'
put 'Student', '1001', 'score:math', '95'
put 'Student', '1002', 'info:name', 'Bob'
put 'Student', '1002', 'info:age', '21'
put 'Student', '1002', 'score:chinese', '80'
put 'Student', '1002', 'score:math', '85'
put 'Student', '1003', 'info:name', 'Cathy'
put 'Student', '1003', 'info:age', '22'
put 'Student', '1003', 'score:chinese', '95'
put 'Student', '1003', 'score:math', '90'
```
以上命令向表 Student 中插入了 3 条记录,每个记录包含 4 个列,分别是 info 列族中的 name 和 age,以及 score 列族中的 chinese 和 math。
4. 验证数据:输入 `scan 'Student'` 并回车,可以查看表中的所有数据。
5. 退出 HBase shell:输入 `exit` 并回车,退出 HBase shell。
这样就完成了使用 HBase shell 创建学生表并输入内容,表中包含两个列族的操作。