Skip to content

Commit

Permalink
fix: partial field in series
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanArhancet committed Jul 12, 2024
1 parent 5b0e339 commit 7e610e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 2 additions & 4 deletions influxdb3/tests/server/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,7 @@ async fn api_v1_query_chunked() {
[1, "a", 0.9],
[2, "a", 0.89],
[3, "a", 0.85]
],
"partial": true
]
}
],
"statement_id": 0,
Expand Down Expand Up @@ -1108,8 +1107,7 @@ async fn api_v1_query_chunked() {
"columns": ["time","host","usage"],
"values": [
[3, "a", 0.85]
],
"partial": true
]
}
],
"statement_id": 0,
Expand Down
17 changes: 13 additions & 4 deletions influxdb3_server/src/http/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,15 @@ impl ChunkBuffer {
}
}

/// This function returns true if the number of rows in the current series exceeds the chunk size
fn is_partial_series(&self) -> bool {
if let (Some(size), Some(m)) = (self.size, self.series.back()) {
m.1.len() > size
} else {
false
}
}

/// The [`ChunkBuffer`] is operating in chunked mode, and can flush a chunk
fn can_flush(&self) -> bool {
if let (Some(size), Some(m)) = (self.size, self.series.back()) {
Expand Down Expand Up @@ -550,22 +559,22 @@ impl QueryResponseStream {
fn flush_one(&mut self) -> QueryResponse {
let columns = self.columns();

let partial = self.buffer.can_flush().then_some(true);

let partial_series = self.buffer.is_partial_series().then_some(true);
let partial_results = self.buffer.can_flush().then_some(true);
// this unwrap is okay because we only ever call flush_one
// after calling can_flush on the buffer:
let (name, values) = self.buffer.flush_one().unwrap();
let series = vec![Series {
name,
columns,
values,
partial,
partial: partial_series,
}];
QueryResponse {
results: vec![StatementResponse {
statement_id: self.statement_id,
series,
partial,
partial: partial_results,
}],
format: self.format,
}
Expand Down

0 comments on commit 7e610e7

Please sign in to comment.