Skip to content

Commit

Permalink
fix(driver): better handle null datatype (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc authored Apr 28, 2023
1 parent a1a5220 commit 9412d2f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion driver/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "databend-driver"
version = "0.2.20"
version = "0.2.21"
edition = "2021"
license = "Apache-2.0"
description = "Databend Driver for Rust"
Expand Down
4 changes: 2 additions & 2 deletions driver/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl TryFrom<&TypeDesc<'_>> for DataType {

fn try_from(desc: &TypeDesc) -> Result<Self> {
let dt = match desc.name {
"Null" => DataType::Null,
"Null" | "NULL" => DataType::Null,
"Boolean" => DataType::Boolean,
"String" => DataType::String,
"Int8" => DataType::Number(NumberDataType::Int8),
Expand Down Expand Up @@ -256,7 +256,7 @@ impl TryFrom<&Arc<ArrowField>> for Field {
)))
}
};
if f.is_nullable() {
if f.is_nullable() && !matches!(dt, DataType::Null) {
dt = DataType::Nullable(Box::new(dt));
}
Ok(Field {
Expand Down
12 changes: 11 additions & 1 deletion driver/tests/driver/select_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ async fn prepare() -> Box<dyn Connection> {
new_connection(dsn).unwrap()
}

#[tokio::test]
async fn select_null() {
let conn = prepare().await;
let row = conn.query_row("select null").await.unwrap();
assert!(row.is_some());
let row = row.unwrap();
let (val,): (Option<u8>,) = row.try_into().unwrap();
assert_eq!(val, None);
}

#[tokio::test]
async fn select_string() {
let conn = prepare().await;
Expand Down Expand Up @@ -109,7 +119,7 @@ async fn select_datetime() {
}

#[tokio::test]
async fn select_null() {
async fn select_nullable() {
let conn = prepare().await;
let row = conn
.query_row("select sum(number) from numbers(0)")
Expand Down
4 changes: 2 additions & 2 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
default: run

run: test-core test-driver test-bendsql down

prepare:
mkdir -p data/databend

Expand All @@ -19,8 +21,6 @@ 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

0 comments on commit 9412d2f

Please sign in to comment.