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

Fetching wrong columns #21

Closed
makorne opened this issue Sep 25, 2021 · 1 comment
Closed

Fetching wrong columns #21

makorne opened this issue Sep 25, 2021 · 1 comment
Labels
wontfix This will not be worked on

Comments

@makorne
Copy link

makorne commented Sep 25, 2021

[tests/integration.rs:157] &row = MyRowResult {
    no: 500,
    result: 2,
}
[tests/integration.rs:157] &row = MyRowResult {
    no: 0,
    result: 501,
}

The second row must be:

[tests/integration.rs:157] &row = MyRowResult {
    no: 501,
    result: 2,
}

Test:


#[tokio::test]
async fn it_writes_then_reads_count() {
    let client = prepare("it_writes_then_reads_count").await;

    #[derive(Debug, Row, Serialize, Deserialize)]
    struct MyRow {
        no: u32,
        num: u32
    }

    #[derive(Debug, Row, Serialize, Deserialize)]
    struct MyRowResult {
        no: u32,
        result: u32
    }

    // Create a table.
    client
        .query(
            "
            CREATE TABLE some(no UInt32, num UInt32)
            ENGINE = MergeTree
            ORDER BY no
        ",
        )
        .execute()
        .await
        .expect("cannot create a table");

    // Write to the table.
    let mut insert = client.insert("some").expect("cannot insert");
    for i in 0..1000 {
        insert
            .write(&MyRow { no: i, num: i })
            .await
            .expect("cannot write()");
        insert
            .write(&MyRow { no: i, num: i+1 })
            .await
            .expect("cannot write()");
    }

    insert.end().await.expect("cannot end()");

    // Read from the table.
    let mut cursor = client
        .query("SELECT no, count(*) FROM some WHERE no BETWEEN ? AND ? GROUP BY no ORDER BY no")
        .bind(500)
        .bind(504)
        .fetch::<MyRowResult>()
        .expect("cannot fetch");

    let mut i = 500;

    while let Some(row) = cursor.next().await.expect("cannot next()") {
        dbg!(&row);
        assert_eq!(row.no, i);
        assert_eq!(row.result, 2);
        i += 1;
    }
}

The same with : count(*) as result

@loyd
Copy link
Owner

loyd commented Sep 25, 2021

Thanks for the issue.

The count returns UInt64 in terms of ClickHouse:

the type of the returned value is UInt64

Thus, using u64 (or any type that deserializes from it) for the result's type fixes your problem.

I don't like such silent errors and I'm going to move to RowBinaryWithNamesAndTypes in #10, because that format provides information about types of columns, that can be useful for conversions. However, even in this case, I think u64 -> u32 should be prohibited and lead to deserialization errors. Thus, I'm closing the issue.

@loyd loyd closed this as completed Sep 25, 2021
@loyd loyd added the wontfix This will not be worked on label Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants