zoukankan      html  css  js  c++  java
  • cratedb导入json文件

    环境:

    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 --

  • 相关阅读:
    scanf和cin的返回值
    C++ STL中Map的按Key排序跟按Value排序
    name lookup of 'res' changed for new ISO 'res' scoping
    string中c_str()、data()、copy(p,n)函数的用法
    C中malloc的使用(转)
    codeforces 653B B. Bear and Compressing(dfs)
    codeforces 653A A. Bear and Three Balls(水题)
    hdu-5646 DZY Loves Partition(贪心)
    hdu-5645 DZY Loves Balls(水题)
    codeforces 655D D. Robot Rapping Results Report(拓扑排序+拓扑序记录)
  • 原文地址:https://www.cnblogs.com/hxlasky/p/11065001.html
Copyright © 2011-2022 走看看