1)切换到 sdbadmin 用户;
2)在 sequoiadb 数据库上创建集合空间 company,集合 employee,写入如下数据:
( empno: 10001, ename: 'georgi', age: 48 );
( empno: 10002, ename: 'bezalel', age: 21 );
( empno: 10003, ename: 'parto', age: 33 );
note:
sdb
var db = new sdb("localhost", 11810);
db.createdomain("company_domain", [ "group1" ]);
db.createcs("company", { domain: "company_domain" } );
db.company.createcl("employee", { "shardingkey": { "_id": 1 }, "shardingtype": "hash", "replsize": -1, "compressed": true, "compressiontype": "lzw", "autosplit": true, "ensureshardingindex": false } );
db.company.employee.insert({"empno":10001,"ename":"georgi","age":48});
db.company.employee.insert({"empno":10002,"ename":"bezalel","age":21});
db.company.employee.insert({"empno":10003,"ename":"parto","age":33});
该考试环境为单分区三副本,仅创建了数据组 group1
3)在 mysql 实例创建数据库 company 和 数据表 employee 与 sequoiadb 巨杉数据库存储引擎的 employee 集合映射;
/opt/sequoiasql/mysql/bin/mysql -h 127.0.0.1 -p 3306 -u root
create database company;
use company;
create table employee(
empno int,
ename varchar(128),
age int
);
select * from employee;
4)查看当前 mysql 实例连接 sequoiadb 巨杉数据库引擎的协调节点端口是否为11810;
/opt/sequoiasql/mysql/bin/mysql -h 127.0.0.1 -p 3306 -u root -e "show variables like 'sequoiadb_conn%';"
5)使用 beeline 客户端连接 sparksql 的 thriftserver 服务,创建对应集合空间的数据库 company,对应集合的表 employee;建表要求:
设置连接 sequoiadb 的协调节点为 21810;
设置 sparksql 读取数据时优先选择备节点;
/opt/spark/bin/beeline -u 'jdbc:hive2://localhost:10000'
create database company;
use company;
create table employee
(
empno int,
ename string,
age int
)
using com.sequoiadb.spark options
(
host 'localhost:21810',
collectionspace 'company',
collection 'employee',
preferredinstance 's',
preferredinstancemode 'random',
preferredinstancestrict true
);
6)查找年龄最小的员工信息并写入 company.result 表中(使用 spark 结果集创建表的方式把结果存储到巨杉数据库,包含 empno,ename, age 三个字段);
/opt/sequoiasql/mysql/bin/mysql -h 127.0.0.1 -p 3306 -u root
create table result(
empno int,
ename varchar(128),
age int
);
insert into result select * from employee where age=(select min(age) from employee);
/opt/spark/bin/beeline -u 'jdbc:hive2://localhost:10000'
create table result
(
empno int,
ename string,
age int
)
using com.sequoiadb.spark options
(
host 'localhost:21810',
collectionspace 'company',
collection 'result'
);
7)使用 select 方法查看数据;
阅读(1568) | 评论(0) | 转发(0) |