Skip to content

Commit

Permalink
feat: add basic case
Browse files Browse the repository at this point in the history
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
  • Loading branch information
waynexia committed Nov 14, 2022
1 parent e3ab335 commit e3564a2
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions tests/cases/local/basic.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
CREATE TABLE system_metrics (
host STRING,
idc STRING,
cpu_util DOUBLE,
memory_util DOUBLE,
disk_util DOUBLE,
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(host, idc),
TIME INDEX(ts)
);

Failed to execute, error: Datanode { code: 1004, msg: "Failed to create table: system_metrics, source: Table already exists: greptime.public.system_metrics" }

INSERT INTO system_metrics
VALUES
("host1", "idc_a", 11.8, 10.3, 10.3, 1667446797450),
("host2", "idc_a", 80.1, 70.3, 90.0, 1667446797450),
("host1", "idc_b", 50.0, 66.7, 40.6, 1667446797450);

MutateResult { success: 3, failure: 0 }

SELECT * FROM system_metrics;

+-----------------------+----------------------+----------------------------+-------------------------------+-----------------------------+----------------------------+
| host, #Field, #String | idc, #Field, #String | cpu_util, #Field, #Float64 | memory_util, #Field, #Float64 | disk_util, #Field, #Float64 | ts, #Timestamp, #Timestamp |
+-----------------------+----------------------+----------------------------+-------------------------------+-----------------------------+----------------------------+
| host1 | idc_a | 11.8 | 10.3 | 10.3 | 1667446797450 |
| host1 | idc_b | 50 | 66.7 | 40.6 | 1667446797450 |
| host2 | idc_a | 80.1 | 70.3 | 90 | 1667446797450 |
+-----------------------+----------------------+----------------------------+-------------------------------+-----------------------------+----------------------------+

SELECT count(*) FROM system_metrics;

+----------------------------------+
| COUNT(UInt8(1)), #Field, #Uint64 |
+----------------------------------+
| 3 |
+----------------------------------+

SELECT avg(cpu_util) FROM system_metrics;

+------------------------------------------------+
| AVG(system_metrics.cpu_util), #Field, #Float64 |
+------------------------------------------------+
| 47.29999999999999 |
+------------------------------------------------+

SELECT idc, avg(memory_util) FROM system_metrics GROUP BY idc ORDER BY idc;

+----------------------+---------------------------------------------------+
| idc, #Field, #String | AVG(system_metrics.memory_util), #Field, #Float64 |
+----------------------+---------------------------------------------------+
| idc_a | 40.3 |
| idc_b | 66.7 |
+----------------------+---------------------------------------------------+

DROP TABLE system_metrics;

Failed to execute, error: Datanode { code: 1001, msg: "Failed to execute sql, source: Cannot parse SQL, source: SQL statement is not supported: DROP TABLE system_metrics;, keyword: DROP" }

26 changes: 26 additions & 0 deletions tests/cases/local/basic.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CREATE TABLE system_metrics (
host STRING,
idc STRING,
cpu_util DOUBLE,
memory_util DOUBLE,
disk_util DOUBLE,
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(host, idc),
TIME INDEX(ts)
);

INSERT INTO system_metrics
VALUES
("host1", "idc_a", 11.8, 10.3, 10.3, 1667446797450),
("host2", "idc_a", 80.1, 70.3, 90.0, 1667446797450),
("host1", "idc_b", 50.0, 66.7, 40.6, 1667446797450);

SELECT * FROM system_metrics;

SELECT count(*) FROM system_metrics;

SELECT avg(cpu_util) FROM system_metrics;

SELECT idc, avg(memory_util) FROM system_metrics GROUP BY idc ORDER BY idc;

DROP TABLE system_metrics;
3 changes: 1 addition & 2 deletions tests/runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ edition = "2021"
async-trait = "0.1"
client = { path = "../../src/client" }
comfy-table = "6.1"
# sqlness = { git = "https://github.com/waynexia/sqlness.git" }
sqlness = { path = "../../../sqlness" }
sqlness = { git = "https://github.com/waynexia/sqlness.git" }
tokio = { version = "1.21", features = ["full"] }
4 changes: 4 additions & 0 deletions tests/runner/src/env.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt::Display;
use std::time::Duration;

use async_trait::async_trait;
use client::api::v1::codec::SelectResult;
Expand All @@ -8,6 +9,7 @@ use client::{Client, Database as DB, Error as ClientError, ObjectResult, Select}
use comfy_table::{Cell, Table};
use sqlness::{Database, Environment};
use tokio::process::{Child, Command};
use tokio::time;

use crate::util;

Expand Down Expand Up @@ -41,6 +43,8 @@ impl Env {
.spawn()
.unwrap_or_else(|_| panic!("Failed to start datanode"));

time::sleep(Duration::from_secs(3)).await;

let client = Client::with_urls(vec!["127.0.0.1:3001"]);
let db = DB::new("greptime", client.clone());

Expand Down

0 comments on commit e3564a2

Please sign in to comment.