Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace ouroboros with self_cell #10316

Merged
merged 3 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 7 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/expr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ hex = "0.4.3"
itertools = "0.10"
md5 = "0.7.0"
num-traits = "0.2"
ouroboros = "0.15"
parse-display = "0.6"
paste = "1"
regex = "1"
Expand All @@ -43,6 +42,7 @@ risingwave_expr_macro = { path = "macro" }
risingwave_pb = { path = "../prost" }
risingwave_udf = { path = "../udf" }
rust_decimal = { version = "1", features = ["db-postgres", "maths"] }
self_cell = "1.0.0"
serde_json = "1"
sha1 = "0.10.5"
sha2 = "0.10.6"
Expand Down
4 changes: 2 additions & 2 deletions src/expr/src/expr/expr_to_char_const_tmpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Expression for ExprToCharConstTmpl {
let mut writer = output.writer().begin();
let fmt = data
.0
.format_with_items(self.ctx.chrono_pattern.borrow_items().iter());
.format_with_items(self.ctx.chrono_pattern.borrow_dependent().iter());
write!(writer, "{fmt}").unwrap();
writer.finish();
} else {
Expand All @@ -72,7 +72,7 @@ impl Expression for ExprToCharConstTmpl {
Ok(if let Some(ScalarImpl::Timestamp(data)) = data {
Some(
data.0
.format_with_items(self.ctx.chrono_pattern.borrow_items().iter())
.format_with_items(self.ctx.chrono_pattern.borrow_dependent().iter())
.to_string()
.into(),
)
Expand Down
27 changes: 13 additions & 14 deletions src/expr/src/vector_op/to_char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@ use std::sync::LazyLock;

use aho_corasick::{AhoCorasick, AhoCorasickBuilder};
use chrono::format::StrftimeItems;
use ouroboros::self_referencing;
use risingwave_common::types::Timestamp;
use static_assertions::const_assert_eq;

#[self_referencing]
pub struct ChronoPattern {
pub(crate) tmpl: String,
#[borrows(tmpl)]
#[covariant]
pub(crate) items: Vec<chrono::format::Item<'this>>,
type Pattern<'a> = Vec<chrono::format::Item<'a>>;

self_cell::self_cell! {
pub struct ChronoPattern {
owner: String,
#[covariant]
dependent: Pattern,
}
}

impl Debug for ChronoPattern {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ChronoPattern")
.field("tmpl", self.borrow_tmpl())
.field("tmpl", self.borrow_owner())
.finish()
}
}
Expand Down Expand Up @@ -67,16 +68,14 @@ pub fn compile_pattern_to_chrono(tmpl: &str) -> ChronoPattern {
true
});
tracing::debug!(tmpl, chrono_tmpl, "compile_pattern_to_chrono");
ChronoPatternBuilder {
tmpl: chrono_tmpl,
items_builder: |tmpl| StrftimeItems::new(tmpl).collect::<Vec<_>>(),
}
.build()
ChronoPattern::new(chrono_tmpl, |tmpl| {
StrftimeItems::new(tmpl).collect::<Vec<_>>()
})
}

// #[function("to_char(timestamp, varchar) -> varchar")]
pub fn to_char_timestamp(data: Timestamp, tmpl: &str, writer: &mut dyn Write) {
let pattern = compile_pattern_to_chrono(tmpl);
let format = data.0.format_with_items(pattern.borrow_items().iter());
let format = data.0.format_with_items(pattern.borrow_dependent().iter());
write!(writer, "{}", format).unwrap();
}
2 changes: 1 addition & 1 deletion src/expr/src/vector_op/to_timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::Result;
#[inline(always)]
pub fn to_timestamp_const_tmpl(s: &str, tmpl: &ChronoPattern) -> Result<Timestamp> {
let mut parsed = Parsed::new();
chrono::format::parse(&mut parsed, s, tmpl.borrow_items().iter())?;
chrono::format::parse(&mut parsed, s, tmpl.borrow_dependent().iter())?;

// chrono will only assign the default value for seconds/nanoseconds fields, and raise an error
// for other ones. We should specify the default value manually.
Expand Down