Skip to content

Commit 0e5d681

Browse files
committed
chore(query): migrate v2 agg sum avg count
1 parent 3d40a87 commit 0e5d681

39 files changed

+568
-3001
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/base/src/containers/array.rs

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/common/base/src/containers/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
mod array;
1615
mod pool;
1716
mod ttlhmap;
1817

19-
pub use array::concat;
2018
pub use pool::ItemManager;
2119
pub use pool::Pool;
2220
pub use ttlhmap::CleanPolicy;

src/common/base/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#![feature(backtrace)]
1616
#![feature(thread_local)]
1717
#![allow(incomplete_features)]
18-
#![feature(generic_const_exprs)]
19-
#![feature(const_maybe_uninit_as_mut_ptr)]
20-
#![feature(const_mut_refs)]
2118

2219
pub mod base;
2320
pub mod containers;

src/query/codegen/src/writes/arithmetics_type_v2.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub trait ResultTypeOfBinary: Sized {{
6767
6868
pub trait ResultTypeOfUnary: Sized {{
6969
type Negate: Number;
70+
type Sum: Number;
7071
7172
fn checked_add(self, _rhs: Self) -> Option<Self>;
7273
@@ -126,6 +127,7 @@ impl ResultTypeOfBinary for ({}, {}) {{
126127

127128
for arg in &number_types {
128129
let negate = neg_coercion(*arg);
130+
let sum = sum_coercion(*arg);
129131

130132
match negate {
131133
NumberDataType::Float32 | NumberDataType::Float64 => {
@@ -134,6 +136,7 @@ impl ResultTypeOfBinary for ({}, {}) {{
134136
"
135137
impl ResultTypeOfUnary for {} {{
136138
type Negate = {};
139+
type Sum = {};
137140
138141
fn checked_add(self, rhs: Self) -> Option<Self> {{
139142
Some(self + rhs)
@@ -157,6 +160,7 @@ impl ResultTypeOfUnary for {} {{
157160
}}",
158161
to_primitive_str(*arg),
159162
to_primitive_str(negate),
163+
to_primitive_str(sum),
160164
)
161165
.unwrap();
162166
}
@@ -167,6 +171,7 @@ impl ResultTypeOfUnary for {} {{
167171
"
168172
impl ResultTypeOfUnary for {} {{
169173
type Negate = {};
174+
type Sum = {};
170175
171176
fn checked_add(self, rhs: Self) -> Option<Self> {{
172177
self.checked_add(rhs)
@@ -190,6 +195,7 @@ impl ResultTypeOfUnary for {} {{
190195
}}",
191196
to_primitive_str(*arg),
192197
to_primitive_str(negate),
198+
to_primitive_str(sum),
193199
)
194200
.unwrap();
195201
}
@@ -251,6 +257,16 @@ fn neg_coercion(a: NumberDataType) -> NumberDataType {
251257
NumberDataType::new(bit_width, true, a.is_float())
252258
}
253259

260+
fn sum_coercion(a: NumberDataType) -> NumberDataType {
261+
if a.is_float() {
262+
NumberDataType::Float64
263+
} else if a.is_signed() {
264+
NumberDataType::Int64
265+
} else {
266+
NumberDataType::UInt64
267+
}
268+
}
269+
254270
const fn next_bit_width(width: u8) -> u8 {
255271
if width < 64 { width * 2 } else { 64 }
256272
}

src/query/expression/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#![feature(associated_type_defaults)]
2222
#![allow(clippy::len_without_is_empty)]
2323
#![allow(clippy::needless_lifetimes)]
24+
#![feature(const_maybe_uninit_as_mut_ptr)]
25+
#![feature(const_mut_refs)]
26+
#![feature(generic_const_exprs)]
27+
28+
#![allow(incomplete_features)]
2429

2530
#[allow(dead_code)]
2631
mod chunk;

src/query/expression/src/types.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub use self::string::StringType;
4848
pub use self::timestamp::TimestampType;
4949
pub use self::variant::VariantType;
5050
use crate::property::Domain;
51+
use crate::util::concat_array;
5152
use crate::values::Column;
5253
use crate::values::Scalar;
5354
use crate::ScalarRef;
@@ -72,6 +73,20 @@ pub enum DataType {
7273
Generic(usize),
7374
}
7475

76+
pub const ALL_INTEGER_TYPES: &[NumberDataType; 8] = &[
77+
NumberDataType::UInt8,
78+
NumberDataType::UInt16,
79+
NumberDataType::UInt32,
80+
NumberDataType::UInt64,
81+
NumberDataType::Int8,
82+
NumberDataType::Int16,
83+
NumberDataType::Int32,
84+
NumberDataType::Int64,
85+
];
86+
87+
pub const ALL_FLOAT_TYPES: &[NumberDataType; 2] = &[NumberDataType::Float32, NumberDataType::Float64];
88+
pub const ALL_NUMERICS_TYPES: &[NumberDataType; 10] = &concat_array(ALL_INTEGER_TYPES, ALL_FLOAT_TYPES);
89+
7590
impl DataType {
7691
pub fn wrap_nullable(&self) -> Self {
7792
match self {
@@ -101,6 +116,7 @@ pub trait ValueType: Debug + Clone + PartialEq + Sized + 'static {
101116

102117
fn try_downcast_scalar<'a>(scalar: &'a ScalarRef) -> Option<Self::ScalarRef<'a>>;
103118
fn try_downcast_column<'a>(col: &'a Column) -> Option<Self::Column>;
119+
104120
fn try_downcast_domain(domain: &Domain) -> Option<Self::Domain>;
105121
fn upcast_scalar(scalar: Self::Scalar) -> Scalar;
106122
fn upcast_column(col: Self::Column) -> Column;

src/query/expression/src/types/arithmetics_type.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub trait ResultTypeOfBinary: Sized {
2828

2929
pub trait ResultTypeOfUnary: Sized {
3030
type Negate: Number;
31+
type Sum: Number;
3132

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

@@ -842,6 +843,7 @@ impl ResultTypeOfBinary for (F64, F64) {
842843

843844
impl ResultTypeOfUnary for u8 {
844845
type Negate = i16;
846+
type Sum = u64;
845847

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

867869
impl ResultTypeOfUnary for u16 {
868870
type Negate = i32;
871+
type Sum = u64;
869872

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

891894
impl ResultTypeOfUnary for u32 {
892895
type Negate = i64;
896+
type Sum = u64;
893897

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

915919
impl ResultTypeOfUnary for u64 {
916920
type Negate = i64;
921+
type Sum = u64;
917922

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

939944
impl ResultTypeOfUnary for i8 {
940945
type Negate = i8;
946+
type Sum = i64;
941947

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

963969
impl ResultTypeOfUnary for i16 {
964970
type Negate = i16;
971+
type Sum = i64;
965972

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

987994
impl ResultTypeOfUnary for i32 {
988995
type Negate = i32;
996+
type Sum = i64;
989997

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

10111019
impl ResultTypeOfUnary for i64 {
10121020
type Negate = i64;
1021+
type Sum = i64;
10131022

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

10351044
impl ResultTypeOfUnary for F32 {
10361045
type Negate = F32;
1046+
type Sum = F64;
10371047

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

10591069
impl ResultTypeOfUnary for F64 {
10601070
type Negate = F64;
1071+
type Sum = F64;
10611072

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

0 commit comments

Comments
 (0)