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

Bug Cannot read all data, after calling end() #59

Closed
kylinholmes opened this issue May 4, 2023 · 4 comments
Closed

Bug Cannot read all data, after calling end() #59

kylinholmes opened this issue May 4, 2023 · 4 comments

Comments

@kylinholmes
Copy link

kylinholmes commented May 4, 2023

Panic info

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BadResponse("Code: 33. DB::Exception: Cannot read all data. Bytes read: 6. Bytes expected: 56.: (at row 2)\n: While executing BinaryRowInputFormat. (CANNOT_READ_ALL_DATA) (version 23.1.2.9 (official build))")', src/xxx.rs:181:40

error occur in insert.end().await.unwrap()

Source code

  for (symbol_id, (total, cnt)) in records.iter() {
      let cli = make_client(url, db, table).await?;
      let mut insert = cli.inserter(table)?;
      ...
      insert.write(&r).await.unwrap();
      insert.commit().await.unwrap();
      insert.end().await.unwrap();
  };

here I tried cli.insert() cli.inserter(),
also try to drop table, and create a new one,
but it doesn't help

@kylinholmes
Copy link
Author

Sorry, I made a mistake, I use a duplicate value as primary key.
I realized it, after I print the record.

@loyd
Copy link
Owner

loyd commented May 5, 2023

@kylinholmes, can you provide more info (for instance, what's the definition of a row?) because using duplicate values as PK is valid for CH

@kylinholmes
Copy link
Author

kylinholmes commented May 5, 2023

Ok, the structure is like:

#[derive(Debug, Row, Deserialize, Serialize)]
struct Stat {
    datetime: i64,
    xxx: String,
    yyy: i32,
}

and I use datetime as PK, following code to create a table:

cli.query(r"
CREATE TABLE IF NOT EXISTS ?.?(
    datetime DateTime64(0, 'Asia/Shanghai'),
    ....
)
ENGINE = MergeTree
ORDER BY datetime
PRIMARY KEY datetime
")
.bind(sql::Identifier(db))
.bind(sql::Identifier(table))
.execute().await?;

When I calling end().await?, the panic just happened.
after I checked data, I found that the value of datetime is duplicate as following, which I never thought it would be.
image

Therefore, I guess using more field may help, which are not the same.
After I changed ddl, everything is Ok:

CREATE TABLE IF NOT EXISTS ?.?(
    datetime DateTime64(0, 'Asia/Shanghai'),
    xxx String,
    yyy Int32,
    ...
)
ENGINE = MergeTree
ORDER BY (datetime, xxx, yyy)
PRIMARY KEY (datetime, xxx, yyy)

@kylinholmes kylinholmes reopened this May 5, 2023
@kylinholmes
Copy link
Author

@loyd Do you have any thoughts on this bug?

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

No branches or pull requests

2 participants