databend icon indicating copy to clipboard operation
databend copied to clipboard

NULL value are not correctly distinguished via the HTTP API

Open wyhaya opened this issue 1 year ago โ€ข 3 comments

Summary

create table users (name string);
insert into users (name) values (null), ('NULL');
curl -u root: -X POST
     -H "Content-Type: application/json" 
     -d '{"sql":"select * from users;"}' 
     http://localhost:8000/v1/query
Output
"schema": [
    {"name": "name",  "type": "Nullable(String)"}
],
"data": [
    ["NULL"],
    ["NULL"]
],

There is no way to tell which of these two values is NULL and which is "NULL".


If we use the Rust driver, we get two NULL, which is wrong.

[driver/examples/test.rs:10:5] query = [
    Row(
        [
            Null,
        ],
    ),
    Row(
        [
            Null,
        ],
    ),
]

The expected result is:

[driver/examples/test.rs:10:5] query = [
    Row(
        [
            Null,
        ],
    ),
    Row(
        [
            String(
                "NULL",
            ),
        ],
    ),
]

wyhaya avatar Jul 19 '24 08:07 wyhaya

There's a similar problem in ClickHouse, but it returns a weird แดบแตแดธแดธ as long as your string isn't "แดบแตแดธแดธ" then it is properly distinguished in most cases.

"data":[
    ["แดบแตแดธแดธ"]
],

ClickHouse Query

wyhaya avatar Jul 19 '24 09:07 wyhaya

we will fix it by representing null just as json null. inside, StringBlock should be [[Option<String>]] instead of [[String]]

youngsofun avatar Jul 24 '24 07:07 youngsofun

   pub session: Option<SessionState>,
   pub schema: Vec<SchemaField>,
-  pub data: Vec<Vec<String>>,
+  pub data: Vec<Vec<Option<String>>>,

Previously all values โ€‹โ€‹were String, but now the value may be String | Null. How to ensure client compatibility?

wyhaya avatar Jul 24 '24 08:07 wyhaya