mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2025-12-22 22:20:02 +00:00
feat: integration test suite (#487)
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
250
Cargo.lock
generated
250
Cargo.lock
generated
@@ -35,7 +35,7 @@ version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"getrandom 0.2.7",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
]
|
||||
@@ -161,6 +161,12 @@ version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.7.2"
|
||||
@@ -498,7 +504,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"getrandom",
|
||||
"getrandom 0.2.7",
|
||||
"instant",
|
||||
"pin-project-lite",
|
||||
"rand 0.8.5",
|
||||
@@ -645,6 +651,17 @@ dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blake2b_simd"
|
||||
version = "0.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"arrayvec 0.5.2",
|
||||
"constant_time_eq",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blake3"
|
||||
version = "1.3.1"
|
||||
@@ -652,7 +669,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a08e53fc5a564bb15bfe6fae56bd71522205f1f91893f9c0116edad6496c183f"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"arrayvec",
|
||||
"arrayvec 0.7.2",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"constant_time_eq",
|
||||
@@ -1116,6 +1133,18 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "comfy-table"
|
||||
version = "6.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1090f39f45786ec6dc6286f8ea9c75d0a7ef0a0d3cda674cef0c3af7b307fbc2"
|
||||
dependencies = [
|
||||
"crossterm",
|
||||
"strum 0.24.1",
|
||||
"strum_macros 0.24.3",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "common-base"
|
||||
version = "0.1.0"
|
||||
@@ -1564,6 +1593,31 @@ dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossterm"
|
||||
version = "0.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"crossterm_winapi",
|
||||
"libc",
|
||||
"mio",
|
||||
"parking_lot",
|
||||
"signal-hook",
|
||||
"signal-hook-mio",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossterm_winapi"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
version = "0.2.2"
|
||||
@@ -1659,7 +1713,7 @@ dependencies = [
|
||||
"arrow2",
|
||||
"async-trait",
|
||||
"chrono",
|
||||
"comfy-table",
|
||||
"comfy-table 5.0.1",
|
||||
"datafusion-common",
|
||||
"datafusion-expr",
|
||||
"datafusion-physical-expr",
|
||||
@@ -1850,6 +1904,17 @@ dependencies = [
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users 0.3.5",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "4.0.0"
|
||||
@@ -1876,7 +1941,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"redox_users 0.4.3",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
@@ -1887,7 +1952,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"redox_users 0.4.3",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
@@ -2354,6 +2419,17 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi 0.9.0+wasi-snapshot-preview1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.7"
|
||||
@@ -3756,7 +3832,7 @@ dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"petgraph",
|
||||
"redox_syscall",
|
||||
"redox_syscall 0.2.16",
|
||||
"smallvec",
|
||||
"thread-id",
|
||||
"windows-sys",
|
||||
@@ -4153,6 +4229,17 @@ version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
||||
|
||||
[[package]]
|
||||
name = "prettydiff"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b6176190f1637d46034820b82fbe758727ccb40da9c9fc2255d695eb05ea29c"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"prettytable-rs",
|
||||
"structopt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.1.19"
|
||||
@@ -4163,6 +4250,20 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prettytable-rs"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fd04b170004fa2daccf418a7f8253aaf033c27760b5f225889024cf66d7ac2e"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"csv",
|
||||
"encode_unicode",
|
||||
"lazy_static",
|
||||
"term",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.2.1"
|
||||
@@ -4477,7 +4578,7 @@ version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"getrandom 0.2.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4538,6 +4639,12 @@ dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.1.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.2.16"
|
||||
@@ -4547,14 +4654,25 @@ dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d"
|
||||
dependencies = [
|
||||
"getrandom 0.1.16",
|
||||
"redox_syscall 0.1.57",
|
||||
"rust-argon2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"redox_syscall",
|
||||
"getrandom 0.2.7",
|
||||
"redox_syscall 0.2.16",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
@@ -4603,7 +4721,7 @@ dependencies = [
|
||||
"backon",
|
||||
"base64",
|
||||
"bytes",
|
||||
"dirs",
|
||||
"dirs 4.0.0",
|
||||
"form_urlencoded",
|
||||
"hex",
|
||||
"hmac",
|
||||
@@ -4711,6 +4829,18 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-argon2"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"blake2b_simd",
|
||||
"constant_time_eq",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-ini"
|
||||
version = "0.18.0"
|
||||
@@ -4727,7 +4857,7 @@ version = "1.26.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee9164faf726e4f3ece4978b25ca877ddc6802fa77f38cdccb32c7f805ecd70c"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"arrayvec 0.7.2",
|
||||
"num-traits",
|
||||
"serde",
|
||||
]
|
||||
@@ -4955,7 +5085,7 @@ dependencies = [
|
||||
"crossbeam-utils",
|
||||
"exitcode",
|
||||
"flate2",
|
||||
"getrandom",
|
||||
"getrandom 0.2.7",
|
||||
"half",
|
||||
"hex",
|
||||
"hexf-parse",
|
||||
@@ -5364,6 +5494,27 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook"
|
||||
version = "0.3.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"signal-hook-registry",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-mio"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"mio",
|
||||
"signal-hook",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.0"
|
||||
@@ -5518,6 +5669,32 @@ dependencies = [
|
||||
"sqlparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlness"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/ceresdb/sqlness.git#c077b17d73ab25460c152dc34e8f80f904522a57"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"derive_builder",
|
||||
"prettydiff",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"toml",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlness-runner"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"client",
|
||||
"comfy-table 6.1.2",
|
||||
"sqlness",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlparser"
|
||||
version = "0.15.0"
|
||||
@@ -5685,6 +5862,30 @@ version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "structopt"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10"
|
||||
dependencies = [
|
||||
"clap 2.34.0",
|
||||
"lazy_static",
|
||||
"structopt-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "structopt-derive"
|
||||
version = "0.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
|
||||
dependencies = [
|
||||
"heck 0.3.3",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.23.0"
|
||||
@@ -5852,11 +6053,22 @@ dependencies = [
|
||||
"cfg-if",
|
||||
"fastrand",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"redox_syscall 0.2.16",
|
||||
"remove_dir_all",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "term"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"dirs 1.0.5",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.3"
|
||||
@@ -5918,7 +6130,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fdfe0627923f7411a43ec9ec9c39c3a9b4151be313e0922042581fb6c9b717f"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"redox_syscall 0.2.16",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
@@ -6629,7 +6841,7 @@ version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"getrandom 0.2.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6695,6 +6907,12 @@ dependencies = [
|
||||
"try-lock",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.9.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
|
||||
@@ -33,6 +33,7 @@ members = [
|
||||
"src/store-api",
|
||||
"src/table",
|
||||
"src/mito",
|
||||
"tests/runner",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
|
||||
@@ -7,3 +7,4 @@ coverage:
|
||||
patch: off
|
||||
ignore:
|
||||
- "**/error*.rs" # ignore all error.rs files
|
||||
- "tests/runner/*.rs" # ignore integration test runner
|
||||
|
||||
60
tests/cases/standalone/basic.result
Normal file
60
tests/cases/standalone/basic.result
Normal file
@@ -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)
|
||||
);
|
||||
|
||||
MutateResult { success: 1, failure: 0 }
|
||||
|
||||
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
tests/cases/standalone/basic.sql
Normal file
26
tests/cases/standalone/basic.sql
Normal file
@@ -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;
|
||||
11
tests/runner/Cargo.toml
Normal file
11
tests/runner/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "sqlness-runner"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
async-trait = "0.1"
|
||||
client = { path = "../../src/client" }
|
||||
comfy-table = "6.1"
|
||||
sqlness = { git = "https://github.com/ceresdb/sqlness.git" }
|
||||
tokio = { version = "1.21", features = ["full"] }
|
||||
166
tests/runner/src/env.rs
Normal file
166
tests/runner/src/env.rs
Normal file
@@ -0,0 +1,166 @@
|
||||
// Copyright 2022 Greptime Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::fmt::Display;
|
||||
use std::time::Duration;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use client::api::v1::codec::SelectResult;
|
||||
use client::api::v1::column::SemanticType;
|
||||
use client::api::v1::ColumnDataType;
|
||||
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;
|
||||
|
||||
pub struct Env {}
|
||||
|
||||
#[async_trait]
|
||||
impl Environment for Env {
|
||||
type DB = GreptimeDB;
|
||||
|
||||
async fn start(&self, mode: &str, _config: Option<String>) -> Self::DB {
|
||||
match mode {
|
||||
"local" => Self::start_local().await,
|
||||
"remote" => Self::start_remote().await,
|
||||
_ => panic!("Unexpected mode: {}", mode),
|
||||
}
|
||||
}
|
||||
|
||||
/// Stop one [`Database`].
|
||||
async fn stop(&self, _mode: &str, mut database: Self::DB) {
|
||||
database.server_process.kill().await.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Env {
|
||||
pub async fn start_local() -> GreptimeDB {
|
||||
let server_process = Command::new("cargo")
|
||||
.current_dir("../")
|
||||
.args(["run", "--", "standalone", "start"])
|
||||
.spawn()
|
||||
.unwrap_or_else(|_| panic!("Failed to start GreptimeDB"));
|
||||
|
||||
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());
|
||||
|
||||
GreptimeDB {
|
||||
server_process,
|
||||
client,
|
||||
db,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn start_remote() -> GreptimeDB {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GreptimeDB {
|
||||
server_process: Child,
|
||||
#[allow(dead_code)]
|
||||
client: Client,
|
||||
db: DB,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Database for GreptimeDB {
|
||||
async fn query(&self, query: String) -> Box<dyn Display> {
|
||||
let sql = Select::Sql(query);
|
||||
let result = self.db.select(sql).await;
|
||||
Box::new(ResultDisplayer { result }) as _
|
||||
}
|
||||
}
|
||||
|
||||
struct ResultDisplayer {
|
||||
result: Result<ObjectResult, ClientError>,
|
||||
}
|
||||
|
||||
impl Display for ResultDisplayer {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match &self.result {
|
||||
Ok(result) => match result {
|
||||
ObjectResult::Select(select_result) => {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
SelectResultDisplayer {
|
||||
result: select_result
|
||||
}
|
||||
.display()
|
||||
)
|
||||
}
|
||||
ObjectResult::Mutate(mutate_result) => {
|
||||
write!(f, "{:?}", mutate_result)
|
||||
}
|
||||
},
|
||||
Err(e) => write!(f, "Failed to execute, error: {:?}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SelectResultDisplayer<'a> {
|
||||
result: &'a SelectResult,
|
||||
}
|
||||
|
||||
impl SelectResultDisplayer<'_> {
|
||||
fn display(&self) -> impl Display {
|
||||
let mut table = Table::new();
|
||||
table.load_preset("||--+-++| ++++++");
|
||||
|
||||
if self.result.row_count == 0 {
|
||||
return table;
|
||||
}
|
||||
|
||||
let mut headers = vec![];
|
||||
for column in &self.result.columns {
|
||||
headers.push(Cell::new(format!(
|
||||
"{}, #{:?}, #{:?}",
|
||||
column.column_name,
|
||||
SemanticType::from_i32(column.semantic_type).unwrap(),
|
||||
ColumnDataType::from_i32(column.datatype).unwrap()
|
||||
)));
|
||||
}
|
||||
table.set_header(headers);
|
||||
|
||||
let col_count = self.result.columns.len();
|
||||
let row_count = self.result.row_count as usize;
|
||||
let columns = self
|
||||
.result
|
||||
.columns
|
||||
.iter()
|
||||
.map(|col| {
|
||||
util::values_to_string(
|
||||
ColumnDataType::from_i32(col.datatype).unwrap(),
|
||||
col.values.clone().unwrap(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for row_index in 0..row_count {
|
||||
let mut row = Vec::with_capacity(col_count);
|
||||
for col in columns.iter() {
|
||||
row.push(col[row_index].clone());
|
||||
}
|
||||
table.add_row(row);
|
||||
}
|
||||
|
||||
table
|
||||
}
|
||||
}
|
||||
29
tests/runner/src/main.rs
Normal file
29
tests/runner/src/main.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2022 Greptime Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use env::Env;
|
||||
use sqlness::{ConfigBuilder, Runner};
|
||||
|
||||
mod env;
|
||||
mod util;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let config = ConfigBuilder::default()
|
||||
.case_dir("../cases".to_string())
|
||||
.build()
|
||||
.unwrap();
|
||||
let runner = Runner::new_with_config(config, Env {}).await.unwrap();
|
||||
runner.run().await.unwrap();
|
||||
}
|
||||
97
tests/runner/src/util.rs
Normal file
97
tests/runner/src/util.rs
Normal file
@@ -0,0 +1,97 @@
|
||||
// Copyright 2022 Greptime Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use client::api::v1::column::Values;
|
||||
use client::api::v1::ColumnDataType;
|
||||
|
||||
pub fn values_to_string(data_type: ColumnDataType, values: Values) -> Vec<String> {
|
||||
match data_type {
|
||||
ColumnDataType::Int64 => values
|
||||
.i64_values
|
||||
.into_iter()
|
||||
.map(|val| val.to_string())
|
||||
.collect(),
|
||||
ColumnDataType::Float64 => values
|
||||
.f64_values
|
||||
.into_iter()
|
||||
.map(|val| val.to_string())
|
||||
.collect(),
|
||||
ColumnDataType::String => values.string_values,
|
||||
ColumnDataType::Boolean => values
|
||||
.bool_values
|
||||
.into_iter()
|
||||
.map(|val| val.to_string())
|
||||
.collect(),
|
||||
ColumnDataType::Int8 => values
|
||||
.i8_values
|
||||
.into_iter()
|
||||
.map(|val| val.to_string())
|
||||
.collect(),
|
||||
ColumnDataType::Int16 => values
|
||||
.i16_values
|
||||
.into_iter()
|
||||
.map(|val| val.to_string())
|
||||
.collect(),
|
||||
ColumnDataType::Int32 => values
|
||||
.i32_values
|
||||
.into_iter()
|
||||
.map(|val| val.to_string())
|
||||
.collect(),
|
||||
ColumnDataType::Uint8 => values
|
||||
.u8_values
|
||||
.into_iter()
|
||||
.map(|val| val.to_string())
|
||||
.collect(),
|
||||
ColumnDataType::Uint16 => values
|
||||
.u16_values
|
||||
.into_iter()
|
||||
.map(|val| val.to_string())
|
||||
.collect(),
|
||||
ColumnDataType::Uint32 => values
|
||||
.u32_values
|
||||
.into_iter()
|
||||
.map(|val| val.to_string())
|
||||
.collect(),
|
||||
ColumnDataType::Uint64 => values
|
||||
.u64_values
|
||||
.into_iter()
|
||||
.map(|val| val.to_string())
|
||||
.collect(),
|
||||
ColumnDataType::Float32 => values
|
||||
.f32_values
|
||||
.into_iter()
|
||||
.map(|val| val.to_string())
|
||||
.collect(),
|
||||
ColumnDataType::Binary => values
|
||||
.binary_values
|
||||
.into_iter()
|
||||
.map(|val| format!("{:?}", val))
|
||||
.collect(),
|
||||
ColumnDataType::Datetime => values
|
||||
.i64_values
|
||||
.into_iter()
|
||||
.map(|v| v.to_string())
|
||||
.collect(),
|
||||
ColumnDataType::Date => values
|
||||
.i32_values
|
||||
.into_iter()
|
||||
.map(|v| v.to_string())
|
||||
.collect(),
|
||||
ColumnDataType::Timestamp => values
|
||||
.ts_millis_values
|
||||
.into_iter()
|
||||
.map(|v| v.to_string())
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user