Skip to content

Commit

Permalink
chore: try split number cast function impl (#17155)
Browse files Browse the repository at this point in the history
* chore: try split number cast function impl

* divnull div0 only register once
  • Loading branch information
TCeason authored Jan 8, 2025
1 parent 53ce6b3 commit a2b69dd
Show file tree
Hide file tree
Showing 12 changed files with 431 additions and 542 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ members = [
"src/query/functions/src/scalars/timestamp",
"src/query/functions/src/scalars/numeric_basic_arithmetic",
"src/query/functions/src/scalars/arithmetic",
"src/query/functions/src/scalars/integer_arithmetic",
"src/query/management",
"src/query/pipeline/core",
"src/query/pipeline/sinks",
Expand Down Expand Up @@ -196,6 +197,7 @@ databend-functions-scalar-arithmetic = { path = "src/query/functions/src/scalars
databend-functions-scalar-datetime = { path = "src/query/functions/src/scalars/timestamp" }
databend-functions-scalar-decimal = { path = "src/query/functions/src/scalars/decimal" }
databend-functions-scalar-geo = { path = "src/query/functions/src/scalars/geographic" }
databend-functions-scalar-integer-basic-arithmetic = { path = "src/query/functions/src/scalars/integer_arithmetic" }
databend-functions-scalar-math = { path = "src/query/functions/src/scalars/mathematics" }
databend-functions-scalar-numeric-basic-arithmetic = { path = "src/query/functions/src/scalars/numeric_basic_arithmetic" }
databend-meta = { path = "src/meta/service" }
Expand Down
1 change: 1 addition & 0 deletions src/query/functions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ databend-functions-scalar-arithmetic = { workspace = true }
databend-functions-scalar-datetime = { workspace = true }
databend-functions-scalar-decimal = { workspace = true }
databend-functions-scalar-geo = { workspace = true }
databend-functions-scalar-integer-basic-arithmetic = { workspace = true }
databend-functions-scalar-math = { workspace = true }
databend-functions-scalar-numeric-basic-arithmetic = { workspace = true }
ethnum = { workspace = true }
Expand Down
434 changes: 243 additions & 191 deletions src/query/functions/src/scalars/arithmetic/src/arithmetic.rs

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/query/functions/src/scalars/integer_arithmetic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "databend-functions-scalar-integer-basic-arithmetic"
version = "0.1.0"
edition = "2021"

[dependencies]
databend-common-expression = { workspace = true }
databend-functions-scalar-numeric-basic-arithmetic = { workspace = true }
match-template = { workspace = true }
num-traits = { workspace = true }

[package.metadata.cargo-machete]
ignored = ["match-template"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use databend_common_expression::arithmetics_type::ResultTypeOfBinary;
use databend_common_expression::types::Number;
use databend_common_expression::types::NumberDataType;
use databend_common_expression::types::NumberType;
use databend_common_expression::types::SimpleDomain;
use databend_common_expression::types::ALL_INTEGER_TYPES;
use databend_common_expression::types::F64;
use databend_common_expression::vectorize_with_builder_2_arg;
use databend_common_expression::with_integer_mapped_type;
use databend_common_expression::FunctionDomain;
use databend_common_expression::FunctionRegistry;
use databend_functions_scalar_numeric_basic_arithmetic::numeric_basic_arithmetic::divide_function;
use databend_functions_scalar_numeric_basic_arithmetic::register_basic_arithmetic;
use databend_functions_scalar_numeric_basic_arithmetic::register_divide;
use databend_functions_scalar_numeric_basic_arithmetic::register_intdiv;
use databend_functions_scalar_numeric_basic_arithmetic::register_minus;
use databend_functions_scalar_numeric_basic_arithmetic::register_modulo;
use databend_functions_scalar_numeric_basic_arithmetic::register_multiply;
use databend_functions_scalar_numeric_basic_arithmetic::register_plus;
use databend_functions_scalar_numeric_basic_arithmetic::vectorize_modulo;
use num_traits::AsPrimitive;

pub fn register_integer_basic_arithmetic(registry: &mut FunctionRegistry) {
for left in ALL_INTEGER_TYPES {
for right in ALL_INTEGER_TYPES {
with_integer_mapped_type!(|L| match left {
NumberDataType::L => with_integer_mapped_type!(|R| match right {
NumberDataType::R => {
register_basic_arithmetic!(L, R, registry);
}
_ => unreachable!(),
}),
_ => unreachable!(),
});
}
}
}
29 changes: 29 additions & 0 deletions src/query/functions/src/scalars/integer_arithmetic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![allow(clippy::arc_with_non_send_sync)]
#![allow(clippy::uninlined_format_args)]
#![allow(clippy::ptr_arg)]
#![allow(clippy::type_complexity)]
#![allow(internal_features)]
#![feature(core_intrinsics)]
#![feature(box_patterns)]
#![feature(type_ascription)]
#![feature(try_blocks)]
#![feature(downcast_unchecked)]
#![feature(str_internals)]

pub mod integer_arithmetic;

pub use integer_arithmetic::*;
2 changes: 2 additions & 0 deletions src/query/functions/src/scalars/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub fn register(registry: &mut FunctionRegistry) {
variant::register(registry);
arithmetic::register(registry);
// register basic arithmetic operation (+ - * / %)
databend_functions_scalar_decimal::register_decimal_arithmetic(registry);
databend_functions_scalar_integer_basic_arithmetic::register_integer_basic_arithmetic(registry);
register_numeric_basic_arithmetic(registry);
arithmetic::register_binary_arithmetic(registry);
arithmetic::register_unary_arithmetic(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition = "2021"

[dependencies]
databend-common-expression = { workspace = true }
databend-functions-scalar-decimal = { workspace = true }
match-template = { workspace = true }
num-traits = { workspace = true }
strength_reduce = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
#![feature(downcast_unchecked)]
#![feature(str_internals)]

mod arithmetic_modulo;
pub mod arithmetic_modulo;
pub mod numeric_basic_arithmetic;

pub use arithmetic_modulo::vectorize_modulo;
pub use numeric_basic_arithmetic::div0_function;
pub use numeric_basic_arithmetic::divide_function;
pub use numeric_basic_arithmetic::divnull_function;
pub use numeric_basic_arithmetic::register_numeric_basic_arithmetic;
Loading

0 comments on commit a2b69dd

Please sign in to comment.