From 130592442373ec8cd03004b21d1c094d3deee6ce Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Tue, 10 Jan 2023 15:12:20 +0800 Subject: [PATCH] ci: add sqlness job (#835) * ci: add sqlness job Signed-off-by: Ruihang Xia * update sqlness to official release Signed-off-by: Ruihang Xia * filter out backtrace Signed-off-by: Ruihang Xia * fix error display Signed-off-by: Ruihang Xia * close once_cell feature gate Signed-off-by: Ruihang Xia Signed-off-by: Ruihang Xia --- .github/workflows/develop.yml | 18 ++++++++ Cargo.lock | 5 +- src/sql/src/error.rs | 4 +- tests/cases/standalone/basic.result | 53 ++++++++++++---------- tests/cases/standalone/select/dummy.result | 36 +++++++-------- tests/runner/Cargo.toml | 2 +- tests/runner/src/env.rs | 9 ++-- 7 files changed, 77 insertions(+), 50 deletions(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 696508a1be..e5ad89ba6a 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -110,6 +110,24 @@ jobs: # GT_S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }} # UNITTEST_LOG_DIR: "__unittest_logs" + sqlness: + name: Sqlness Test + if: github.event.pull_request.draft == false + runs-on: ubuntu-latest-8-cores + timeout-minutes: 60 + steps: + - uses: actions/checkout@v3 + - uses: arduino/setup-protoc@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_TOOLCHAIN }} + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + - name: Run sqlness + run: cargo run --bin sqlness-runner + fmt: name: Rustfmt if: github.event.pull_request.draft == false diff --git a/Cargo.lock b/Cargo.lock index b68e5bd510..dcd1024cfb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6875,8 +6875,9 @@ dependencies = [ [[package]] name = "sqlness" -version = "0.1.0" -source = "git+https://github.com/ceresdb/sqlness.git#94ad8235b52d8a8d8211844a0880e0a845f6dcc7" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ffa69a2ae10018ec72a3cb7574e3a33a3fc322ed03740f6e435fd7f0c1db4a7" dependencies = [ "async-trait", "derive_builder", diff --git a/src/sql/src/error.rs b/src/sql/src/error.rs index 2e2508eade..04168d343b 100644 --- a/src/sql/src/error.rs +++ b/src/sql/src/error.rs @@ -79,14 +79,14 @@ pub enum Error { backtrace: Backtrace, }, - #[snafu(display("Failed to parse value: {}, {}", msg, backtrace))] + #[snafu(display("Failed to parse value: {}", msg))] ParseSqlValue { msg: String, backtrace: Backtrace }, #[snafu(display( "Column {} expect type: {:?}, actual: {:?}", column_name, expect, - actual + actual, ))] ColumnTypeMismatch { column_name: String, diff --git a/tests/cases/standalone/basic.result b/tests/cases/standalone/basic.result index f62bdf242d..c296f4d4e7 100644 --- a/tests/cases/standalone/basic.result +++ b/tests/cases/standalone/basic.result @@ -9,45 +9,52 @@ CREATE TABLE system_metrics ( TIME INDEX(ts) ); +Affected Rows: 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); +Affected Rows: 3 + 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 | -+-----------------------+----------------------+----------------------------+-------------------------------+-----------------------------+----------------------------+ ++-------+-------+----------+-------------+-----------+-------------------------+ +| host | idc | cpu_util | memory_util | disk_util | ts | ++-------+-------+----------+-------------+-----------+-------------------------+ +| host1 | idc_a | 11.8 | 10.3 | 10.3 | 2022-11-03T03:39:57.450 | +| host1 | idc_b | 50 | 66.7 | 40.6 | 2022-11-03T03:39:57.450 | +| host2 | idc_a | 80.1 | 70.3 | 90 | 2022-11-03T03:39:57.450 | ++-------+-------+----------+-------------+-----------+-------------------------+ SELECT count(*) FROM system_metrics; -+----------------------------------+ -| COUNT(UInt8(1)), #Field, #Uint64 | -+----------------------------------+ -| 3 | -+----------------------------------+ ++-----------------+ +| COUNT(UInt8(1)) | ++-----------------+ +| 3 | ++-----------------+ SELECT avg(cpu_util) FROM system_metrics; -+------------------------------------------------+ -| AVG(system_metrics.cpu_util), #Field, #Float64 | -+------------------------------------------------+ -| 47.29999999999999 | -+------------------------------------------------+ ++------------------------------+ +| AVG(system_metrics.cpu_util) | ++------------------------------+ +| 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 | -+----------------------+---------------------------------------------------+ ++-------+---------------------------------+ +| idc | AVG(system_metrics.memory_util) | ++-------+---------------------------------+ +| idc_a | 40.3 | +| idc_b | 66.7 | ++-------+---------------------------------+ DROP TABLE system_metrics; + +Affected Rows: 1 + diff --git a/tests/cases/standalone/select/dummy.result b/tests/cases/standalone/select/dummy.result index 24132d6b4f..eb53626454 100644 --- a/tests/cases/standalone/select/dummy.result +++ b/tests/cases/standalone/select/dummy.result @@ -1,36 +1,36 @@ select 1; -+--------------------------+ -| Int64(1), #Field, #Int64 | -+--------------------------+ -| 1 | -+--------------------------+ ++----------+ +| Int64(1) | ++----------+ +| 1 | ++----------+ select 2 + 3; -+----------------------------------------+ -| Int64(2) Plus Int64(3), #Field, #Int64 | -+----------------------------------------+ -| 5 | -+----------------------------------------+ ++---------------------+ +| Int64(2) + Int64(3) | ++---------------------+ +| 5 | ++---------------------+ select 4 + 0.5; -+----------------------------------------------+ -| Int64(4) Plus Float64(0.5), #Field, #Float64 | -+----------------------------------------------+ -| 4.5 | -+----------------------------------------------+ ++-------------------------+ +| Int64(4) + Float64(0.5) | ++-------------------------+ +| 4.5 | ++-------------------------+ select "a"; -Failed to execute, error: Datanode { code: 1003, msg: "Failed to execute query: select \"a\";, source: Failed to select from table, source: Error occurred on the data node, code: 3000, msg: Failed to execute sql, source: Cannot plan SQL: SELECT \"a\", source: Error during planning: Invalid identifier '#a' for schema fields:[], metadata:{}" } +Failed to do Flight get, addr: 127.0.0.1:4001, code: 3000, err_msg: Failed to execute sql statement, source: Failed to execute sql, source: Failure during query planning, source: Cannot plan SQL: SELECT "a", source: Schema error: No field named 'a'. Valid fields are . select "A"; -Failed to execute, error: Datanode { code: 1003, msg: "Failed to execute query: select \"A\";, source: Failed to select from table, source: Error occurred on the data node, code: 3000, msg: Failed to execute sql, source: Cannot plan SQL: SELECT \"A\", source: Error during planning: Invalid identifier '#A' for schema fields:[], metadata:{}" } +Failed to do Flight get, addr: 127.0.0.1:4001, code: 3000, err_msg: Failed to execute sql statement, source: Failed to execute sql, source: Failure during query planning, source: Cannot plan SQL: SELECT "A", source: Schema error: No field named 'A'. Valid fields are . select * where "a" = "A"; -Failed to execute, error: Datanode { code: 1003, msg: "Failed to execute query: select * where \"a\" = \"A\";, source: Failed to select from table, source: Error occurred on the data node, code: 3000, msg: Failed to execute sql, source: Cannot plan SQL: SELECT * WHERE \"a\" = \"A\", source: Error during planning: Invalid identifier '#a' for schema fields:[], metadata:{}" } +Failed to do Flight get, addr: 127.0.0.1:4001, code: 3000, err_msg: Failed to execute sql statement, source: Failed to execute sql, source: Failure during query planning, source: Cannot plan SQL: SELECT * WHERE "a" = "A", source: Schema error: No field named 'a'. Valid fields are . diff --git a/tests/runner/Cargo.toml b/tests/runner/Cargo.toml index 5a50dc3a68..a38a72e27c 100644 --- a/tests/runner/Cargo.toml +++ b/tests/runner/Cargo.toml @@ -10,5 +10,5 @@ client = { path = "../../src/client" } common-base = { path = "../../src/common/base" } common-grpc = { path = "../../src/common/grpc" } common-query = { path = "../../src/common/query" } -sqlness = { git = "https://github.com/ceresdb/sqlness.git" } +sqlness = "0.1" tokio.workspace = true diff --git a/tests/runner/src/env.rs b/tests/runner/src/env.rs index a61c1c434d..7d0efbf00e 100644 --- a/tests/runner/src/env.rs +++ b/tests/runner/src/env.rs @@ -14,13 +14,14 @@ use std::fmt::Display; use std::fs::OpenOptions; +use std::path::Path; use std::process::Stdio; use std::time::Duration; use async_trait::async_trait; use client::{Client, Database as DB, Error as ClientError}; use common_query::Output; -use sqlness::{Database, Environment}; +use sqlness::{Database, EnvController}; use tokio::process::{Child, Command}; use crate::util; @@ -31,10 +32,10 @@ const SERVER_LOG_FILE: &str = "/tmp/greptime-sqlness.log"; pub struct Env {} #[async_trait] -impl Environment for Env { +impl EnvController for Env { type DB = GreptimeDB; - async fn start(&self, mode: &str, _config: Option) -> Self::DB { + async fn start(&self, mode: &str, _config: Option<&Path>) -> Self::DB { match mode { "standalone" => Self::start_standalone().await, "distributed" => Self::start_distributed().await, @@ -139,7 +140,7 @@ impl Display for ResultDisplayer { } Output::Stream(_) => unreachable!(), }, - Err(e) => write!(f, "Failed to execute, error: {e:?}"), + Err(e) => write!(f, "{e}"), } } }