Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: drop table after test #87

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- uses: ./.github/actions/setup
with:
cache-key: integration
- run: make -C tests
- run: make -C tests test-flight-sql
- run: make -C tests test-core
- run: make -C tests test-driver
- run: make -C tests test-bendsql
- run: sudo chown -R runner ~/.cargo/registry
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ build:
test:
cargo test --all --all-features --lib -- --nocapture

integration:
make -C tests

integration-down:
make -C tests down

integration-tests:
make -C tests
integration-core:
make -C tests test-core

integration-tests-flight-sql:
make -C tests test-flight-sql
integration-driver:
make -C tests test-driver

integration-bendsql:
make -C tests test-bendsql
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Databend Client
# BendSQL

Databend Native Client in Rust

Expand All @@ -13,17 +13,17 @@ Databend Native Client in Rust

## Installation for BendSQL

* With Cargo:
* Cargo:
```bash
cargo install bendsql
```

* With Homebrew:
* Homebrew:
```bash
brew install databendcloud/homebrew-tap/bendsql
```

* With Binary: check for latest release [here](https://github.com/datafuselabs/databend-client/releases)
* Binary: check for latest release [here](https://github.com/datafuselabs/databend-client/releases)


## Development
Expand All @@ -45,6 +45,5 @@ make test
*Note: Docker and Docker Compose needed*

```bash
make integration-tests
make integration-tests-flight-sql
make integration
```
2 changes: 1 addition & 1 deletion cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Default for Settings {
Settings {
display_pretty_sql: true,
progress_color: "cyan".to_string(),
prompt: "bendsql> ".to_string(),
prompt: "{user}@{host}> ".to_string(),
output_format: OutputFormat::Table,
show_progress: false,
}
Expand Down
3 changes: 2 additions & 1 deletion cli/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl Session {
{
prompt = prompt.replace("{host}", &info.host);
prompt = prompt.replace("{user}", &info.user);
prompt = prompt.replace("{port}", &info.port.to_string());
}

Ok(Self {
Expand Down Expand Up @@ -96,7 +97,7 @@ impl Session {
let prompt = if self.query.is_none() {
&self.prompt
} else {
" -> "
""
};
match rl.readline(prompt) {
Ok(line) => {
Expand Down
4 changes: 4 additions & 0 deletions cli/tests/http/01-load_stdin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ SQL
${BENDSQL} --query='INSERT INTO test_books VALUES;' --format=csv --data=@- <cli/tests/data/books.csv

${BENDSQL} --query='SELECT * FROM test_books LIMIT 10;' --output=tsv

cat <<SQL | ${BENDSQL}
DROP TABLE test_books;
SQL
4 changes: 4 additions & 0 deletions cli/tests/http/02-load_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ SQL
${BENDSQL} --query='INSERT INTO test_books VALUES;' --format=csv --data=@cli/tests/data/books.csv

${BENDSQL} --query='SELECT * FROM test_books LIMIT 10;' --output=tsv

cat <<SQL | ${BENDSQL}
DROP TABLE test_books;
SQL
4 changes: 4 additions & 0 deletions cli/tests/http/03-load_file_gzip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ ${BENDSQL} \

echo "SELECT COUNT(*) FROM test_ontime;" | ${BENDSQL} --output=tsv
echo 'SELECT * FROM test_ontime LIMIT 1;' | ${BENDSQL} --output=csv

cat <<SQL | ${BENDSQL}
DROP TABLE test_ontime;
SQL
11 changes: 9 additions & 2 deletions core/tests/core/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ async fn insert_with_stage(presigned: bool) {
let file = File::open("tests/core/data/sample.csv").await.unwrap();
let metadata = file.metadata().await.unwrap();

let path = chrono::Utc::now().format("%Y%m%d%H%M%S%.9f").to_string();
let path = chrono::Utc::now().format("%Y%m%d%H%M%S%9f").to_string();
let stage_location = format!("@~/{}/sample.csv", path);
let table = format!("sample_{}", path);
let table = if presigned {
format!("sample_insert_presigned_{}", path)
} else {
format!("sample_insert_stream_{}", path)
};

client
.upload_to_stage(&stage_location, file, metadata.len())
Expand Down Expand Up @@ -72,6 +76,9 @@ async fn insert_with_stage(presigned: bool) {
["6", "Beijing", "99"],
];
assert_eq!(resp.data, expect);

let sql = format!("DROP TABLE `{}` ALL;", table);
client.query_wait(&sql).await.unwrap();
}

#[tokio::test]
Expand Down
4 changes: 4 additions & 0 deletions driver/tests/driver/select_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ async fn select_iter() {
assert_eq!(v, expected[row_count]);
row_count += 1;
}
assert_eq!(row_count, 3);

let sql_drop = format!("DROP TABLE `{}`", table);
conn.exec(&sql_drop).await.unwrap();
}

#[tokio::test]
Expand Down
11 changes: 9 additions & 2 deletions driver/tests/driver/stream_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ async fn stream_load(presigned: bool, file_type: &str) {
.unwrap();
let metadata = file.metadata().await.unwrap();

let path = Utc::now().format("%Y%m%d%H%M%S%.9f").to_string();
let table = format!("books_{}", path);
let path = Utc::now().format("%Y%m%d%H%M%S%9f").to_string();
let table = if presigned {
format!("books_stream_load_{}_presigned_{}", file_type, path)
} else {
format!("books_stream_load_{}_{}", file_type, path)
};

let sql = format!(
"CREATE TABLE `{}` (
Expand Down Expand Up @@ -99,6 +103,9 @@ async fn stream_load(presigned: bool, file_type: &str) {
),
];
assert_eq!(result, expected);

let sql = format!("DROP TABLE `{}` ALL;", table);
client.exec(&sql).await.unwrap();
}

#[tokio::test]
Expand Down
15 changes: 7 additions & 8 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
PHONY: test

default: test
default: run

prepare:
mkdir -p data/databend
Expand All @@ -10,18 +8,19 @@ up: prepare

start: up

test: up
cargo test --test '*'

run: test
test-core: up
cargo test --test core

test-flight-sql: up
test-driver: up
cargo test --test driver
TEST_DATABEND_DSN=databend+flight://root:@localhost:8900/default?sslmode=disable cargo test --features flight-sql --test driver

test-bendsql: up
cd .. && ./cli/test.sh http
cd .. && ./cli/test.sh flight

run: test-core test-driver test-bendsql

down:
docker compose down

Expand Down