Protryon / klickhouse

Rust crate for accessing Clickhouse

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Execute large query failed with error:unexpected end of file

bmmcq opened this issue · comments

commented

I submit a SQL query that was expected to return 7 million rows, but the client threw an error :
"
ERROR [tokio-runtime-worker] [/Users/bmmcq/.cargo/registry/src/github.com-1ecc6299db9ec823/klickhouse-0.2.1/src/client.rs:168] clickhouse client failed: unexpected end of file
"
and exit with the wrong number of rows.

There is the code:

#[tokio::main]
async fn main() {
    pegasus_common::logs::init_log();
    let mut opt = ClientOptions::default();
    opt.default_database = "mydb".to_owned();
    let client = Client::connect("myip:9000", opt)
        .await
        .unwrap();
    let query = "select * from mytable where my_id in (8,10,11,13,15,17,19,20,22,24,26,28,30)";
    let start = Instant::now();
    let mut all_rows = client
        .query_raw(query)
        .await
        .unwrap();

    let mut count = 0u64;
    while let Some(row) = all_rows.next().await {
        println!("row {}", row.rows);
        count += row.rows;
    }
    println!("total received {} records, used {:?};", count, start.elapsed());
}

The query_raw function returns blocks (which are sets of columns) that clickhouse has assembled. Use query if you want to look at individual rows. As for the unexpected EOF, try a newer version, but it's likely the connection just died.