



mysql -h FE_HOST -P9030 -uadmin -p
SET PASSWORD FOR 'admin' = PASSWORD('your_password');
CREATE USER 'test' IDENTIFIED BY 'test_passwd';
mysql -h FE_HOST -P9030 -utest -ptest_passwd
CREATE DATABASE example_db;。HELP CREATE DATABASE;。 CREATE DATABASE, CREATE TABLE,CREATE USER 等命令。 SHOW DATABASES; 查看数据库信息。MySQL> SHOW DATABASES;+--------------------+| Database |+--------------------+| doris_audit_db__ || example_db || information_schema |+--------------------+3 rows in set (0.00 sec)
GRANT ALL ON example_db TO test;
USE example_db;
CREATE TABLE 命令建立一个表。腾讯云数据仓库 TCHouse-D 支持单分区和复合分区两种建表方式,具体参见 数据分区和分桶。下面以聚合模型为例,分别演示两种分区的建表语句。
单分区
建立一个名字为 table1 的逻辑表。分桶列为 siteid,桶数为 10,表的 schema 如下:CREATE TABLE table1(siteid INT DEFAULT '10',citycode SMALLINT,username VARCHAR(32) DEFAULT '',pv BIGINT SUM DEFAULT '0')AGGREGATE KEY(siteid,citycode,username)DISTRIBUTED BY HASH(siteid) BUCKETS 10PROPERTIES("replication_num" = "1");
CREATE TABLE table2(event_day DATE,siteid INT DEFAULT '10',citycode SMALLINT,username VARCHAR(32) DEFAULT '',pv BIGINT SUM DEFAULT '0')AGGREGATE KEY(event_day, siteid, citycode, username)PARTITION BY RANGE(event_day)(PARTITION p201706 VALUES LESS THAN ('2017-07-01'),PARTITION p201707 VALUES LESS THAN ('2017-08-01'),PARTITION p201708 VALUES LESS THAN ('2017-09-01'))DISTRIBUTED BY HASH(siteid) BUCKETS 10PROPERTIES("replication_num" = "1");
MySQL> SHOW TABLES;+----------------------+| Tables_in_example_db |+----------------------+| table1 || table2 |+----------------------+2 rows in set (0.01 sec)MySQL> DESC table1;+----------+-------------+------+-------+---------+-------+| Field | Type | Null | Key | Default | Extra |+----------+-------------+------+-------+---------+-------+| siteid | int(11) | Yes | true | 10 | || citycode | smallint(6) | Yes | true | N/A | || username | varchar(32) | Yes | true | | || pv | bigint(20) | Yes | false | 0 | SUM |+----------+-------------+------+-------+---------+-------+4 rows in set (0.00 sec)MySQL> DESC table2;+-----------+-------------+------+-------+---------+-------+| Field | Type | Null | Key | Default | Extra |+-----------+-------------+------+-------+---------+-------+| event_day | date | Yes | true | N/A | || siteid | int(11) | Yes | true | 10 | || citycode | smallint(6) | Yes | true | N/A | || username | varchar(32) | Yes | true | | || pv | bigint(20) | Yes | false | 0 | SUM |+-----------+-------------+------+-------+---------+-------+5 rows in set (0.00 sec)
HELP STREAM LOAD;。
示例1:以 "table1_20170707" 为 Label,使用本地文件 table1_data 导入 table1 表。curl --location-trusted -u test:test_passwd -H "label:table1_20170707" -H "column_separator:," -T table1_data http://FE_HOST:8030/api/example_db/table1/_stream_load
1,1,jim,22,1,grace,23,2,tom,24,3,bush,35,3,helen,3
curl --location-trusted -u test:test -H "label:table2_20170707" -H "column_separator:|" -T table2_datahttp://127.0.0.1:8030/api/example_db/table2/_stream_load
table2_data 以|作为数据之间的分隔,具体内容如下:2017-07-03|1|1|jim|22017-07-05|2|1|grace|22017-07-12|3|2|tom|22017-07-15|4|3|bush|32017-07-12|5|3|helen|3
HELP BROKER LOAD;。
示例:以 "table1_20170708" 为 Label,将 HDFS 上的文件导入 table1 表。LOAD LABEL table1_20170708(DATA INFILE("hdfs://your.namenode.host:port/dir/table1_data")INTO TABLE table1)WITH BROKER hdfs("username"="hdfs_user","password"="hdfs_password")PROPERTIES("timeout"="3600","max_filter_ratio"="0.1");
SHOW LOAD;查看。如:SHOW LOAD WHERE LABEL = "table1_20170708";
State 字段为 FINISHED 则表示导入成功。关于 SHOW LOAD 的更多说明,可以参阅 HELP SHOW LOAD;。
异步的导入任务在结束前可以取消:CANCEL LOAD WHERE LABEL = "table1_20170708";。MySQL> SELECT * FROM table1 LIMIT 3;+--------+----------+----------+------+| siteid | citycode | username | pv |+--------+----------+----------+------+| 2 | 1 | 'grace' | 2 || 5 | 3 | 'helen' | 3 || 3 | 2 | 'tom' | 2 |+--------+----------+----------+------+3 rows in set (0.01 sec)MySQL> SELECT * FROM table1 ORDER BY citycode;+--------+----------+----------+------+| siteid | citycode | username | pv |+--------+----------+----------+------+| 2 | 1 | 'grace' | 2 || 1 | 1 | 'jim' | 2 || 3 | 2 | 'tom' | 2 || 4 | 3 | 'bush' | 3 || 5 | 3 | 'helen' | 3 |+--------+----------+----------+------+5 rows in set (0.01 sec)
MySQL> SELECT SUM(table1.pv) FROM table1 JOIN table2 WHERE table1.siteid = table2.siteid;+--------------------+| sum(`table1`.`pv`) |+--------------------+| 12 |+--------------------+1 row in set (0.20 sec)
MySQL> SELECT SUM(pv) FROM table2 WHERE siteid IN (SELECT siteid FROM table1 WHERE siteid > 2);+-----------+| sum(`pv`) |+-----------+| 8 |+-----------+1 row in set (0.13 sec)
https:// fe_ip:8030,当看到如下页面时说明启动成功。
Data Import后可从本地上传数据。






文档反馈