Skip to content

Commit

Permalink
optimize performance
Browse files Browse the repository at this point in the history
  • Loading branch information
KeXiangWang committed Feb 20, 2024
1 parent 36630f4 commit ca31707
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
28 changes: 14 additions & 14 deletions src/common/src/types/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,15 @@ impl ToText for Date {
/// ```
fn write<W: std::fmt::Write>(&self, f: &mut W) -> std::fmt::Result {
let (ce, year) = self.0.year_ce();
write!(f, "{:04}-{:02}-{:02}", year, self.0.month(), self.0.day())?;
if ce {
Ok(())
} else {
f.write_str(" BC")
}
let suffix = if ce { "" } else { " BC" };
write!(
f,
"{:04}-{:02}-{:02}{}",
year,
self.0.month(),
self.0.day(),
suffix
)
}

fn write_with_type<W: std::fmt::Write>(&self, ty: &DataType, f: &mut W) -> std::fmt::Result {
Expand All @@ -360,19 +363,16 @@ impl ToText for Time {
impl ToText for Timestamp {
fn write<W: std::fmt::Write>(&self, f: &mut W) -> std::fmt::Result {
let (ce, year) = self.0.year_ce();
let suffix = if ce { "" } else { " BC" };
write!(
f,
"{:04}-{:02}-{:02} {}",
"{:04}-{:02}-{:02} {}{}",
year,
self.0.month(),
self.0.day(),
self.0.time()
)?;
if ce {
Ok(())
} else {
f.write_str(" BC")
}
self.0.time(),
suffix
)
}

fn write_with_type<W: std::fmt::Write>(&self, ty: &DataType, f: &mut W) -> std::fmt::Result {
Expand Down
13 changes: 6 additions & 7 deletions src/common/src/types/timestamptz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,12 @@ pub fn write_date_time_tz(
year,
date.month(),
date.day(),
instant_local.format("%H:%M:%S%.f%:z")
)?;
if ce {
std::fmt::Result::Ok(())
} else {
writer.write_str(" BC")
}
instant_local.format(if ce {
"%H:%M:%S%.f%:z"
} else {
"%H:%M:%S%.f%:z BC"
})
)
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/handler/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::sync::Arc;
use std::task::{Context, Poll};

use anyhow::Context as _;
use bytes::Bytes;
use bytes::{Bytes, BytesMut};
use futures::Stream;
use itertools::Itertools;
use pgwire::pg_field_descriptor::PgFieldDescriptor;
Expand Down Expand Up @@ -139,7 +139,7 @@ fn timestamptz_to_string_with_session_data(
let tz = d.into_timestamptz();
let time_zone = Timestamptz::lookup_time_zone(&session_data.timezone).unwrap();
let instant_local = tz.to_datetime_in_zone(time_zone);
let mut result_string = String::new();
let mut result_string = BytesMut::new();
write_date_time_tz(instant_local, &mut result_string).unwrap();
result_string.into()
}
Expand Down

0 comments on commit ca31707

Please sign in to comment.