Skip to content

Commit 97d4978

Browse files
authored
Merge pull request #7514 from ariesdevil/num_func_v2
feat(function-v2): migrate math functions to function-v2
2 parents 46ea5a2 + b592c46 commit 97d4978

File tree

10 files changed

+716
-18
lines changed

10 files changed

+716
-18
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2022 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Concat two arrays of different lengths
16+
pub const fn concat<T, const A: usize, const B: usize>(a: &[T; A], b: &[T; B]) -> [T; A + B] {
17+
let mut result = std::mem::MaybeUninit::uninit();
18+
let dest = result.as_mut_ptr() as *mut T;
19+
unsafe {
20+
std::ptr::copy_nonoverlapping(a.as_ptr(), dest, A);
21+
std::ptr::copy_nonoverlapping(b.as_ptr(), dest.add(A), B);
22+
result.assume_init()
23+
}
24+
}

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

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

15+
mod array;
1516
mod pool;
1617
mod ttlhmap;
1718

19+
pub use array::concat;
1820
pub use pool::ItemManager;
1921
pub use pool::Pool;
2022
pub use ttlhmap::CleanPolicy;

src/common/base/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
#![feature(backtrace)]
1616
#![feature(thread_local)]
17+
#![allow(incomplete_features)]
18+
#![feature(generic_const_exprs)]
19+
#![feature(const_maybe_uninit_as_mut_ptr)]
20+
#![feature(const_mut_refs)]
1721

1822
pub mod base;
1923
pub mod containers;

src/query/functions-v2/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ doctest = false
1212
[dependencies] # In alphabetical order
1313
# Workspace dependencies
1414
common-arrow = { path = "../../common/arrow" }
15+
common-base = { path = "../../common/base" }
1516
common-expression = { path = "../expression" }
1617

1718
# Crates.io dependencies
1819
base64 = "0.13.0"
1920
bstr = "0.2.17"
21+
crc32fast = "1.3.2"
2022
hex = "0.4.3"
2123
itertools = "0.10.3"
2224
match-template = "0.0.1"
2325
num-traits = "0.2.15"
26+
rand = { version = "0.8.5", features = ["small_rng"] }
2427
strength_reduce = "0.2.3"
2528

2629
[dev-dependencies]

src/query/functions-v2/src/scalars/arithmetic.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use common_expression::FunctionProperty;
2222
use common_expression::FunctionRegistry;
2323

2424
use super::arithmetic_modulo::vectorize_modulo;
25+
use crate::scalars::ALL_NUMERICS_TYPES;
2526

2627
pub fn register(registry: &mut FunctionRegistry) {
2728
registry.register_aliases("plus", &["add"]);
@@ -31,21 +32,8 @@ pub fn register(registry: &mut FunctionRegistry) {
3132
// TODO support modulo
3233
// registry.register_aliases("%", &["mod", "modulo"]);
3334

34-
let all_numerics_types = &[
35-
DataType::UInt8,
36-
DataType::UInt16,
37-
DataType::UInt32,
38-
DataType::UInt64,
39-
DataType::Int8,
40-
DataType::Int16,
41-
DataType::Int32,
42-
DataType::Int64,
43-
DataType::Float32,
44-
DataType::Float64,
45-
];
46-
4735
// Unary OP for minus and plus
48-
for left in all_numerics_types {
36+
for left in ALL_NUMERICS_TYPES {
4937
with_number_mapped_type!(L, match left {
5038
DataType::L => {
5139
type T = <L as ResultTypeOfUnary>::Negate;
@@ -78,8 +66,8 @@ pub fn register(registry: &mut FunctionRegistry) {
7866
});
7967
}
8068

81-
for left in all_numerics_types {
82-
for right in all_numerics_types {
69+
for left in ALL_NUMERICS_TYPES {
70+
for right in ALL_NUMERICS_TYPES {
8371
with_number_mapped_type!(L, match left {
8472
DataType::L => with_number_mapped_type!(R, match right {
8573
DataType::R => {

0 commit comments

Comments
 (0)