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

Erroneous behaviour when selecting multiple booleans #112

Closed
thomask opened this issue Jul 20, 2024 · 2 comments
Closed

Erroneous behaviour when selecting multiple booleans #112

thomask opened this issue Jul 20, 2024 · 2 comments

Comments

@thomask
Copy link

thomask commented Jul 20, 2024

I've just cloned the repo and added the following (failing) test case:

#[tokio::test]
async fn multiple_booleans() {
    let client = prepare_database!();

    #[derive(Row, Deserialize)]
    struct Row {
        a: bool,
        b: bool,
    }

    let row = client
        .query("WITH
            (
                select true
            ) as a,
            (
                select true
            ) as b
            SELECT
                ?fields"
        )
        .fetch_one::<Row>()
        .await
        .unwrap();


    assert_eq!(row.a, true);
    assert_eq!(row.b, true);
}

One bool is false, the other is true.

I haven't had time yet to dig into the library code to diagnose the issue. Perhaps this is an easy fix for the author. If not, I'd be more than happy to look in to this next week.

@loyd
Copy link
Collaborator

loyd commented Jul 25, 2024

Oh, wait, it's four bytes instead of two, compared to

clickhouse-client -q 'SELECT true AS a, true AS b FORMAT RowBinary' | hx
0x000000: 0x01 0x01                                         ..
   bytes: 2

The reason is that the actual returned type corresponding to Option<bool>:

    #[derive(Debug, Row, Deserialize)]
    struct Row {
        a: Option<bool>,
        b: Option<bool>,
    }

    let row = client
        .query("WITH (SELECT true) as a, (SELECT true) as b SELECT ?fields")
        .fetch_one::<Row>()
        .await
        .unwrap();

    assert_eq!(row.a, Some(true));
    assert_eq!(row.b, Some(true));

RowBinaryWithNamesAndTypes also confirms this:

clickhouse-client -q 'WITH (SELECT true) AS a, (SELECT true) AS b SELECT a, b FORMAT RowBinaryWithNamesAndTypes' | hx
0x000000: 0x02 0x01 0x61 0x01 0x62 0x0e 0x4e 0x75 0x6c 0x6c ..a.b.Null
0x00000a: 0x61 0x62 0x6c 0x65 0x28 0x42 0x6f 0x6f 0x6c 0x29 able(Bool)
0x000014: 0x0e 0x4e 0x75 0x6c 0x6c 0x61 0x62 0x6c 0x65 0x28 .Nullable(
0x00001e: 0x42 0x6f 0x6f 0x6c 0x29 0x00 0x01 0x00 0x01      Bool)....
   bytes: 39

I don't think it can be fixed (more precisely, made more prominent) without #10 (or moving to the Native format), where it can be cast to the requested type.

@loyd
Copy link
Collaborator

loyd commented Jul 25, 2024

Closing in favor of #10 because nothing can be done additionally here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants