Topik ini menjelaskan cara menggunakan kluster StarRocks di E-MapReduce untuk membuat dan menanyakan tabel.
Prasyarat
Anda telah membuat kluster StarRocks. Untuk informasi lebih lanjut, lihat Buat kluster StarRocks.
Contoh
Masuk ke Node master dari kluster StarRocks menggunakan SSH. Untuk informasi lebih lanjut, lihat Masuk ke kluster.
Jalankan perintah berikut untuk terhubung ke kluster StarRocks:
mysql -h127.0.0.1 -P 9030 -urootJalankan perintah berikut untuk membuat database dan memilihnya:
CREATE DATABASE IF NOT EXISTS load_test; USE load_test;Jalankan perintah berikut untuk membuat tabel:
CREATE TABLE insert_wiki_edit ( event_time DATETIME, channel VARCHAR(32) DEFAULT '', user VARCHAR(128) DEFAULT '', is_anonymous TINYINT DEFAULT '0', is_minor TINYINT DEFAULT '0', is_new TINYINT DEFAULT '0', is_robot TINYINT DEFAULT '0', is_unpatrolled TINYINT DEFAULT '0', delta INT SUM DEFAULT '0', added INT SUM DEFAULT '0', deleted INT SUM DEFAULT '0' ) AGGREGATE KEY(event_time, channel, user, is_anonymous, is_minor, is_new, is_robot, is_unpatrolled) PARTITION BY RANGE(event_time) ( PARTITION p06 VALUES LESS THAN ('2015-09-12 06:00:00'), PARTITION p12 VALUES LESS THAN ('2015-09-12 12:00:00'), PARTITION p18 VALUES LESS THAN ('2015-09-12 18:00:00'), PARTITION p24 VALUES LESS THAN ('2015-09-13 00:00:00') ) DISTRIBUTED BY HASH(user) BUCKETS 10 PROPERTIES("replication_num" = "1");Jalankan perintah berikut untuk mengimpor data uji:
INSERT INTO insert_wiki_edit VALUES("2015-09-12 00:00:00","#en.wikipedia","GELongstreet",0,0,0,0,0,36,36,0),("2015-09-12 00:00:00","#ca.wikipedia","PereBot",0,1,0,1,0,17,17,0);Jalankan perintah berikut untuk menanyakan data:
select * from insert_wiki_edit;Keluaran berikut dikembalikan:
+---------------------+---------------+--------------+--------------+----------+--------+----------+----------------+-------+-------+---------+ | event_time | channel | user | is_anonymous | is_minor | is_new | is_robot | is_unpatrolled | delta | added | deleted | +---------------------+---------------+--------------+--------------+----------+--------+----------+----------------+-------+-------+---------+ | 2015-09-12 00:00:00 | #en.wikipedia | GELongstreet | 0 | 0 | 0 | 0 | 0 | 36 | 36 | 0 | | 2015-09-12 00:00:00 | #ca.wikipedia | PereBot | 0 | 1 | 0 | 1 | 0 | 17 | 17 | 0 | +---------------------+---------------+--------------+--------------+----------+--------+----------+----------------+-------+-------+---------+ 2 baris dalam set (0,16 detik)