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

Batch aggregation framework #4533

Merged
merged 6 commits into from
Apr 17, 2019
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
2 changes: 1 addition & 1 deletion src/coprocessor/codec/data_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use crate::coprocessor::codec::mysql::{Decimal, Duration, Json, Time as Date

// Dynamic eval types.
pub use self::scalar::ScalarValue;
pub use self::vector::VectorValue;
pub use self::vector::{VectorValue, VectorValueExt};
pub use self::vector_like::{VectorLikeValueRef, VectorLikeValueRefSpecialized};

use crate::coprocessor::dag::expr::EvalContext;
Expand Down
50 changes: 39 additions & 11 deletions src/coprocessor/codec/data_type/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,20 @@ macro_rules! impl_as_slice {
}
}

// `AsMut` is not implemented intentionally.
// TODO: We should only expose interface for push value, not the entire Vec.
impl AsMut<Vec<Option<$ty>>> for VectorValue {
#[inline]
fn as_mut(&mut self) -> &mut Vec<Option<$ty>> {
match self {
VectorValue::$ty(ref mut vec) => vec,
other => panic!(
"Cannot retrieve a mutable `{}` vector over a {} column",
stringify!($ty),
other.eval_type()
),
}
}
}
};
}

Expand All @@ -662,16 +675,22 @@ impl_as_slice! { DateTime, as_date_time_slice }
impl_as_slice! { Duration, as_duration_slice }
impl_as_slice! { Json, as_json_slice }

macro_rules! impl_push {
($ty:tt, $name:ident) => {
pub trait VectorValueExt<T: Evaluable> {
fn push(&mut self, v: Option<T>);
}

macro_rules! impl_ext {
($ty:tt, $push_name:ident) => {
// Explicit version

impl VectorValue {
/// Pushes a value in specified concrete type into current column.
///
/// # Panics
///
/// Panics if the current column does not match the type.
#[inline]
pub fn $name(&mut self, v: Option<$ty>) {
pub fn $push_name(&mut self, v: Option<$ty>) {
match self {
VectorValue::$ty(ref mut vec) => vec.push(v),
other => panic!(
Expand All @@ -682,16 +701,25 @@ macro_rules! impl_push {
};
}
}

// Implicit version

impl VectorValueExt<$ty> for VectorValue {
#[inline]
fn push(&mut self, v: Option<$ty>) {
self.$push_name(v);
}
}
};
}

impl_push! { Int, push_int }
impl_push! { Real, push_real }
impl_push! { Decimal, push_decimal }
impl_push! { Bytes, push_bytes }
impl_push! { DateTime, push_date_time }
impl_push! { Duration, push_duration }
impl_push! { Json, push_json }
impl_ext! { Int, push_int }
impl_ext! { Real, push_real }
impl_ext! { Decimal, push_decimal }
impl_ext! { Bytes, push_bytes }
impl_ext! { DateTime, push_date_time }
impl_ext! { Duration, push_duration }
impl_ext! { Json, push_json }

macro_rules! impl_from {
($ty:tt) => {
Expand Down
Loading