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

chore(query): migrate agg (count, sum, avg) and combinators into v2 #7615

Merged
merged 15 commits into from
Sep 16, 2022
Merged
13 changes: 10 additions & 3 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions src/common/base/src/containers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

mod array;
mod pool;
mod ttlhmap;

pub use array::concat;
pub use pool::ItemManager;
pub use pool::Pool;
pub use ttlhmap::CleanPolicy;
Expand Down
3 changes: 0 additions & 3 deletions src/common/base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#![feature(backtrace)]
#![feature(thread_local)]
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
#![feature(const_maybe_uninit_as_mut_ptr)]
#![feature(const_mut_refs)]

pub mod base;
pub mod containers;
Expand Down
2 changes: 1 addition & 1 deletion src/common/hashtable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test = false
common-base = { path = "../base" }

# Crates.io dependencies
ordered-float = "3.0.0"
ordered-float = { git = "https://github.com/andylokandy/rust-ordered-float.git", branch = "as", features = ["serde"] }
BohuTANG marked this conversation as resolved.
Show resolved Hide resolved
primitive-types = "0.11.1"

[dev-dependencies]
Expand Down
16 changes: 16 additions & 0 deletions src/query/codegen/src/writes/arithmetics_type_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub trait ResultTypeOfBinary: Sized {{

pub trait ResultTypeOfUnary: Sized {{
type Negate: Number;
type Sum: Number;

fn checked_add(self, _rhs: Self) -> Option<Self>;

Expand Down Expand Up @@ -126,6 +127,7 @@ impl ResultTypeOfBinary for ({}, {}) {{

for arg in &number_types {
let negate = neg_coercion(*arg);
let sum = sum_coercion(*arg);

match negate {
NumberDataType::Float32 | NumberDataType::Float64 => {
Expand All @@ -134,6 +136,7 @@ impl ResultTypeOfBinary for ({}, {}) {{
"
impl ResultTypeOfUnary for {} {{
type Negate = {};
type Sum = {};

fn checked_add(self, rhs: Self) -> Option<Self> {{
Some(self + rhs)
Expand All @@ -157,6 +160,7 @@ impl ResultTypeOfUnary for {} {{
}}",
to_primitive_str(*arg),
to_primitive_str(negate),
to_primitive_str(sum),
)
.unwrap();
}
Expand All @@ -167,6 +171,7 @@ impl ResultTypeOfUnary for {} {{
"
impl ResultTypeOfUnary for {} {{
type Negate = {};
type Sum = {};

fn checked_add(self, rhs: Self) -> Option<Self> {{
self.checked_add(rhs)
Expand All @@ -190,6 +195,7 @@ impl ResultTypeOfUnary for {} {{
}}",
to_primitive_str(*arg),
to_primitive_str(negate),
to_primitive_str(sum),
)
.unwrap();
}
Expand Down Expand Up @@ -251,6 +257,16 @@ fn neg_coercion(a: NumberDataType) -> NumberDataType {
NumberDataType::new(bit_width, true, a.is_float())
}

fn sum_coercion(a: NumberDataType) -> NumberDataType {
if a.is_float() {
NumberDataType::Float64
} else if a.is_signed() {
NumberDataType::Int64
} else {
NumberDataType::UInt64
}
}

const fn next_bit_width(width: u8) -> u8 {
if width < 64 { width * 2 } else { 64 }
}
4 changes: 4 additions & 0 deletions src/query/expression/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#![feature(associated_type_defaults)]
#![allow(clippy::len_without_is_empty)]
#![allow(clippy::needless_lifetimes)]
#![feature(const_maybe_uninit_as_mut_ptr)]
#![feature(const_mut_refs)]
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

#[allow(dead_code)]
mod chunk;
Expand Down
34 changes: 34 additions & 0 deletions src/query/expression/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub use self::string::StringType;
pub use self::timestamp::TimestampType;
pub use self::variant::VariantType;
use crate::property::Domain;
use crate::util::concat_array;
use crate::values::Column;
use crate::values::Scalar;
use crate::ScalarRef;
Expand All @@ -72,6 +73,38 @@ pub enum DataType {
Generic(usize),
}

pub const ALL_INTEGER_TYPES: &[NumberDataType; 8] = &[
NumberDataType::UInt8,
NumberDataType::UInt16,
NumberDataType::UInt32,
NumberDataType::UInt64,
NumberDataType::Int8,
NumberDataType::Int16,
NumberDataType::Int32,
NumberDataType::Int64,
];

pub const ALL_FLOAT_TYPES: &[NumberDataType; 2] =
&[NumberDataType::Float32, NumberDataType::Float64];
pub const ALL_NUMERICS_TYPES: &[NumberDataType; 10] =
&concat_array(ALL_INTEGER_TYPES, ALL_FLOAT_TYPES);

impl DataType {
pub fn wrap_nullable(&self) -> Self {
match self {
DataType::Nullable(_) => self.clone(),
_ => Self::Nullable(Box::new(self.clone())),
}
}
pub fn is_nullable_or_null(&self) -> bool {
matches!(self, &DataType::Nullable(_) | &DataType::Null)
}

pub fn can_inside_nullable(&self) -> bool {
!self.is_nullable_or_null()
}
}

pub trait ValueType: Debug + Clone + PartialEq + Sized + 'static {
type Scalar: Debug + Clone + PartialEq;
type ScalarRef<'a>: Debug + Clone + PartialEq;
Expand All @@ -85,6 +118,7 @@ pub trait ValueType: Debug + Clone + PartialEq + Sized + 'static {

fn try_downcast_scalar<'a>(scalar: &'a ScalarRef) -> Option<Self::ScalarRef<'a>>;
fn try_downcast_column<'a>(col: &'a Column) -> Option<Self::Column>;

fn try_downcast_domain(domain: &Domain) -> Option<Self::Domain>;
fn upcast_scalar(scalar: Self::Scalar) -> Scalar;
fn upcast_column(col: Self::Column) -> Column;
Expand Down
11 changes: 11 additions & 0 deletions src/query/expression/src/types/arithmetics_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub trait ResultTypeOfBinary: Sized {

pub trait ResultTypeOfUnary: Sized {
type Negate: Number;
type Sum: Number;

fn checked_add(self, _rhs: Self) -> Option<Self>;

Expand Down Expand Up @@ -842,6 +843,7 @@ impl ResultTypeOfBinary for (F64, F64) {

impl ResultTypeOfUnary for u8 {
type Negate = i16;
type Sum = u64;

fn checked_add(self, rhs: Self) -> Option<Self> {
self.checked_add(rhs)
Expand All @@ -866,6 +868,7 @@ impl ResultTypeOfUnary for u8 {

impl ResultTypeOfUnary for u16 {
type Negate = i32;
type Sum = u64;

fn checked_add(self, rhs: Self) -> Option<Self> {
self.checked_add(rhs)
Expand All @@ -890,6 +893,7 @@ impl ResultTypeOfUnary for u16 {

impl ResultTypeOfUnary for u32 {
type Negate = i64;
type Sum = u64;

fn checked_add(self, rhs: Self) -> Option<Self> {
self.checked_add(rhs)
Expand All @@ -914,6 +918,7 @@ impl ResultTypeOfUnary for u32 {

impl ResultTypeOfUnary for u64 {
type Negate = i64;
type Sum = u64;

fn checked_add(self, rhs: Self) -> Option<Self> {
self.checked_add(rhs)
Expand All @@ -938,6 +943,7 @@ impl ResultTypeOfUnary for u64 {

impl ResultTypeOfUnary for i8 {
type Negate = i8;
type Sum = i64;

fn checked_add(self, rhs: Self) -> Option<Self> {
self.checked_add(rhs)
Expand All @@ -962,6 +968,7 @@ impl ResultTypeOfUnary for i8 {

impl ResultTypeOfUnary for i16 {
type Negate = i16;
type Sum = i64;

fn checked_add(self, rhs: Self) -> Option<Self> {
self.checked_add(rhs)
Expand All @@ -986,6 +993,7 @@ impl ResultTypeOfUnary for i16 {

impl ResultTypeOfUnary for i32 {
type Negate = i32;
type Sum = i64;

fn checked_add(self, rhs: Self) -> Option<Self> {
self.checked_add(rhs)
Expand All @@ -1010,6 +1018,7 @@ impl ResultTypeOfUnary for i32 {

impl ResultTypeOfUnary for i64 {
type Negate = i64;
type Sum = i64;

fn checked_add(self, rhs: Self) -> Option<Self> {
self.checked_add(rhs)
Expand All @@ -1034,6 +1043,7 @@ impl ResultTypeOfUnary for i64 {

impl ResultTypeOfUnary for F32 {
type Negate = F32;
type Sum = F64;

fn checked_add(self, rhs: Self) -> Option<Self> {
Some(self + rhs)
Expand All @@ -1058,6 +1068,7 @@ impl ResultTypeOfUnary for F32 {

impl ResultTypeOfUnary for F64 {
type Negate = F64;
type Sum = F64;

fn checked_add(self, rhs: Self) -> Option<Self> {
Some(self + rhs)
Expand Down