pub struct ConstantFolding;Expand description
Folds constant expressions such as 1 + 2 into a single literal.
§Examples
use vlorql_core::optimizer::{ConstantFolding, PlanRewriter};
use vlorql_core::schema::{
BinaryOperator, DataType, Expression, FromClause, Projection, QueryPlan,
};
let plan = QueryPlan {
select: vec![Projection::Expr {
expression: Expression::BinaryOp {
left: Box::new(Expression::Literal { value: 1.into(), data_type: DataType::Int }),
op: BinaryOperator::Add,
right: Box::new(Expression::Literal { value: 2.into(), data_type: DataType::Int }),
},
alias: Some("three".to_owned()),
}],
from: FromClause { table: "t".to_owned(), alias: None },
r#where: None, group_by: None, having: None,
order_by: None, limit: None, offset: None, joins: None, ctes: None, distinct: false, distinct_on: None, set_operation: None,
};
let folded = ConstantFolding.rewrite(&plan).unwrap();
assert_eq!(
folded.select[0],
Projection::Expr {
expression: Expression::Literal { value: 3.into(), data_type: DataType::Int },
alias: Some("three".to_owned()),
},
);Trait Implementations§
Source§impl Clone for ConstantFolding
impl Clone for ConstantFolding
Source§fn clone(&self) -> ConstantFolding
fn clone(&self) -> ConstantFolding
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for ConstantFolding
Source§impl Debug for ConstantFolding
impl Debug for ConstantFolding
Source§impl Default for ConstantFolding
impl Default for ConstantFolding
Source§fn default() -> ConstantFolding
fn default() -> ConstantFolding
Returns the “default value” for a type. Read more
Source§impl PlanRewriter for ConstantFolding
impl PlanRewriter for ConstantFolding
Auto Trait Implementations§
impl Freeze for ConstantFolding
impl RefUnwindSafe for ConstantFolding
impl Send for ConstantFolding
impl Sync for ConstantFolding
impl Unpin for ConstantFolding
impl UnsafeUnpin for ConstantFolding
impl UnwindSafe for ConstantFolding
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request