Skip to content

Custom("premature end of input") on max(DateTime64) query on empty table #218

@enomado

Description

@enomado

Describe the bug

field:
my_time DateTime64(3, 'UTC') CODEC(Delta, ZSTD),

struct:
max_time: chrono::DateTime<chrono::Utc>,

query:
select max(my_time) AS max_time from data_real;

table is empty

.fetch_optional(), .next() - everything returns an Err - Custom("premature end of input")

When I remove max - everything works;

When I query in clickhouse-client - it gives 1970-1-1

more details:

CREATE TABLE IF NOT EXISTS data_real (
   my_time DateTime64(3, 'UTC') CODEC(Delta, ZSTD),
) ENGINE = MergeTree
ORDER BY my_time
#[derive(Row, Deserialize, Debug)]
pub struct LastTime {
    max_time: chrono::DateTime<chrono::Utc>,
}

pub async fn get_last_id(&self) -> Option<LastTime> {
        let q = r#"
SELECT
       max(my_time) AS max_time
FROM data_real"#;

        let q = self.client.query(q);
        let mut s = q.fetch::<LastTime>().unwrap();
        let y = s.next().await;

        let y = y.unwrap(); // ---- panic here -----
        y
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions