Skip to content

Commit

Permalink
fix by cr
Browse files Browse the repository at this point in the history
  • Loading branch information
poltao committed May 11, 2024
1 parent ea6ec60 commit 60f9083
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/servers/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use std::collections::HashMap;
use std::fmt::Display;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Mutex as StdMutex;
use std::time::Duration;

Expand All @@ -41,6 +42,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use snafu::{ensure, ResultExt};
use strum::EnumString;
use tokio::sync::oneshot::{self, Sender};
use tokio::sync::Mutex;
use tower::timeout::TimeoutLayer;
Expand Down Expand Up @@ -190,6 +192,9 @@ impl From<SchemaRef> for OutputSchema {
pub struct HttpRecordsOutput {
schema: OutputSchema,
rows: Vec<Vec<Value>>,
// total_rows is equal to rows.len() in most cases,
// the Dashboard query result may be truncated, so we need to return the total_rows.
total_rows: usize,

// plan level execution metrics
#[serde(skip_serializing_if = "HashMap::is_empty")]
Expand Down Expand Up @@ -224,6 +229,7 @@ impl HttpRecordsOutput {
Ok(HttpRecordsOutput {
schema: OutputSchema::from(schema),
rows: vec![],
total_rows: 0,
metrics: Default::default(),
})
} else {
Expand All @@ -244,6 +250,7 @@ impl HttpRecordsOutput {

Ok(HttpRecordsOutput {
schema: OutputSchema::from(schema),
total_rows: rows.len(),
rows,
metrics: Default::default(),
})
Expand Down Expand Up @@ -336,15 +343,16 @@ impl Display for Epoch {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumString)]
pub enum RequestSource {
#[strum(ascii_case_insensitive)]
Dashboard,
}

impl RequestSource {
pub fn parse(s: &str) -> Option<Self> {
match s {
"dashboard" => Some(RequestSource::Dashboard),
match RequestSource::from_str(s) {
Ok(v) => Some(v),
_ => None,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/servers/src/http/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ pub async fn sql(
.map(|s| Epoch::parse(s.as_str()).unwrap_or(Epoch::Millisecond));
let source = query_params
.source
.map(|s| RequestSource::parse(s.to_lowercase().as_str()))
.unwrap_or(None);
.and_then(|s| RequestSource::parse(s.as_str()));

let result = if let Some(sql) = &sql {
if let Some((status, msg)) = validate_schema(sql_handler.clone(), query_ctx.clone()).await {
Expand Down Expand Up @@ -155,7 +154,8 @@ pub async fn from_dashboard(resp: HttpResponse, ctx: QueryContextRef) -> HttpRes
continue;
};
if records.rows.len() > query_limit {
records.rows.resize(query_limit, vec![]);
records.rows.truncate(query_limit);
records.total_rows = query_limit;
}
outputs.push(GreptimeQueryOutput::Records(records));
}
Expand Down

0 comments on commit 60f9083

Please sign in to comment.