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 方法查看数据;
阅读(1681) | 评论(0) | 转发(0) |