Skip to content

Commit

Permalink
Expose PyAtModifier::at
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
messense committed May 22, 2024
1 parent 56e0365 commit c1d4dd1
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions src/expr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::SystemTime;

use chrono::Duration;
use promql_parser::label::Label;
use promql_parser::parser::{
Expand Down Expand Up @@ -305,17 +307,7 @@ impl PySubqueryExpr {
),
None => None,
},
at: match at {
Some(at) => {
let typ = match at {
AtModifier::Start => PyAtModifierType::Start,
AtModifier::End => PyAtModifierType::End,
AtModifier::At(_) => PyAtModifierType::At,
};
Some(PyAtModifier { r#type: typ })
}
None => None,
},
at: at.map(|at| at.into()),
range: Duration::from_std(range)
.map_err(|e| PyOverflowError::new_err(e.to_string()))?,
step: match step {
Expand All @@ -335,7 +327,19 @@ impl PySubqueryExpr {
pub struct PyAtModifier {
#[pyo3(get)]
r#type: PyAtModifierType,
// at: Option<SystemTime>,
#[pyo3(get)]
at: Option<SystemTime>,
}

impl From<AtModifier> for PyAtModifier {
fn from(at: AtModifier) -> Self {
let (typ, at) = match at {
AtModifier::Start => (PyAtModifierType::Start, None),
AtModifier::End => (PyAtModifierType::End, None),
AtModifier::At(at) => (PyAtModifierType::At, Some(at)),
};
PyAtModifier { r#type: typ, at }
}
}

#[pyclass(name = "AtModifierType", module = "promql_parser")]
Expand Down Expand Up @@ -502,17 +506,7 @@ impl PyVectorSelector {
),
None => None,
},
at: match at {
Some(at) => {
let typ = match at {
AtModifier::Start => PyAtModifierType::Start,
AtModifier::End => PyAtModifierType::End,
AtModifier::At(_) => PyAtModifierType::At,
};
Some(PyAtModifier { r#type: typ })
}
None => None,
},
at: at.map(|at| at.into()),
});
Ok(Py::new(py, initializer)?.into_py(py))
}
Expand Down

0 comments on commit c1d4dd1

Please sign in to comment.