mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-26 09:50:40 +00:00
fix: csv format escaping (#6061)
* fix: csv format escaping * chore: change status code * fix: crate version
This commit is contained in:
@@ -28,7 +28,7 @@ common-runtime.workspace = true
|
||||
common-telemetry.workspace = true
|
||||
common-time.workspace = true
|
||||
crossbeam-utils.workspace = true
|
||||
csv = "1.3.0"
|
||||
csv = "1.3"
|
||||
dashmap.workspace = true
|
||||
datafusion.workspace = true
|
||||
datafusion-common.workspace = true
|
||||
|
||||
@@ -50,6 +50,7 @@ common-session.workspace = true
|
||||
common-telemetry.workspace = true
|
||||
common-time.workspace = true
|
||||
common-version = { workspace = true, features = ["codec"] }
|
||||
csv = "1.3"
|
||||
dashmap.workspace = true
|
||||
datafusion.workspace = true
|
||||
datafusion-common.workspace = true
|
||||
|
||||
@@ -12,13 +12,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::fmt::Write;
|
||||
|
||||
use axum::http::{header, HeaderValue};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use common_error::status_code::StatusCode;
|
||||
use common_query::Output;
|
||||
use itertools::Itertools;
|
||||
use mime_guess::mime;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -72,6 +69,22 @@ impl CsvResponse {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! http_try {
|
||||
($handle: expr) => {
|
||||
match $handle {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
let msg = err.to_string();
|
||||
return HttpResponse::Error(ErrorResponse::from_error_message(
|
||||
StatusCode::Unexpected,
|
||||
msg,
|
||||
))
|
||||
.into_response();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl IntoResponse for CsvResponse {
|
||||
fn into_response(mut self) -> Response {
|
||||
debug_assert!(
|
||||
@@ -87,12 +100,15 @@ impl IntoResponse for CsvResponse {
|
||||
format!("{n}\n")
|
||||
}
|
||||
Some(GreptimeQueryOutput::Records(records)) => {
|
||||
let mut result = String::new();
|
||||
let mut wtr = csv::Writer::from_writer(Vec::new());
|
||||
|
||||
for row in records.rows {
|
||||
let row = row.iter().map(|v| v.to_string()).join(",");
|
||||
writeln!(result, "{row}").unwrap();
|
||||
http_try!(wtr.serialize(row));
|
||||
}
|
||||
result
|
||||
http_try!(wtr.flush());
|
||||
|
||||
let bytes = http_try!(wtr.into_inner());
|
||||
http_try!(String::from_utf8(bytes))
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user