环境:
OS:Centos 7
DB版本:3.2.0
1.准备数据文件
myuser.json文件内容如下:
{"id": 1, "name": "foo", "day_joined": 1408312800, "bio": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.", "address": {"city": "Dornbirn", "country": "Austria"}}
{"id": 2, "name": "bar", "day_joined": 1408312800, "bio": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.", "address": {"city": "Berlin", "country": "Germany"}}
2.登陆数据库创建表
[root@localhost config]# su - crate
-bash-4.2$ crash --host 192.168.1.129 -U devtest
输入密码
cr> CREATE TABLE doc.myusers (
id INT primary key,
name STRING,
day_joined TIMESTAMP primary key,
bio STRING INDEX using fulltext,
address OBJECT (dynamic) AS (
city STRING,
country STRING
)
) CLUSTERED INTO 6 shards
PARTITIONED BY (day_joined)
WITH (number_of_replicas = 0);
3.导入数据
cr> COPY doc.myusers FROM '/home/crate/myuser.json';
COPY OK, 2 rows affected (0.273 sec)
4.查看数据
cr> select * from doc.myusers;
+--------------------------------------------+-----------------------------------------------------------+------------+----+------+
| address | bio | day_joined | id | name |
+--------------------------------------------+-----------------------------------------------------------+------------+----+------+
| {"city": "Dornbirn", "country": "Austria"} | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. | 1408312800 | 1 | foo |
| {"city": "Berlin", "country": "Germany"} | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. | 1408312800 | 2 | bar |
+--------------------------------------------+-----------------------------------------------------------+------------+----+------+
SELECT 2 rows in set (0.003 sec)
cr>
--The End --
阅读(13307) | 评论(0) | 转发(0) |