Skip to content

Commit e9b9645

Browse files
berkaysynnadamustafasrepoozankabak
authored
Interval Arithmetic Updates (#8276)
* Interval lib can be accessible from logical plan * committed to merge precision PR * minor fix after merge, adding ts-interval handling * bound openness removed * Remove all interval bound related code * test fix * fix docstrings * Fix after merge * Minor changes * Simplifications * Resolve linter errors * Addressing reviews * Fix win tests * Update interval_arithmetic.rs * Code simplifications * Review Part 1 * Review Part 2 * Addressing Ozan's feedback * Resolving conflicts * Review Part 3 * Better cardinality calculation * fix clippy * Review Part 4 * type check, test polish, bug fix * Constructs filter graph with datatypes * Update Cargo.lock * Update Cargo.toml * Review * Other expectations of AND * OR operator implementation * Certainly false asserting comparison operators * Update interval_arithmetic.rs * Tests added, is_superset renamed * Final review * Resolving conflicts * Address review feedback --------- Co-authored-by: Mustafa Akur <mustafa.akur@synnada.ai> Co-authored-by: Mehmet Ozan Kabak <ozankabak@gmail.com>
1 parent 58483fb commit e9b9645

28 files changed

+4406
-2773
lines changed

datafusion-cli/Cargo.lock

+23-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/common/Cargo.toml

+10-2
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,22 @@ backtrace = []
3838
pyarrow = ["pyo3", "arrow/pyarrow", "parquet"]
3939

4040
[dependencies]
41-
ahash = { version = "0.8", default-features = false, features = ["runtime-rng"] }
42-
apache-avro = { version = "0.16", default-features = false, features = ["bzip", "snappy", "xz", "zstandard"], optional = true }
41+
ahash = { version = "0.8", default-features = false, features = [
42+
"runtime-rng",
43+
] }
44+
apache-avro = { version = "0.16", default-features = false, features = [
45+
"bzip",
46+
"snappy",
47+
"xz",
48+
"zstandard",
49+
], optional = true }
4350
arrow = { workspace = true }
4451
arrow-array = { workspace = true }
4552
arrow-buffer = { workspace = true }
4653
arrow-schema = { workspace = true }
4754
chrono = { workspace = true }
4855
half = { version = "2.1", default-features = false }
56+
libc = "0.2.140"
4957
num_cpus = { workspace = true }
5058
object_store = { workspace = true, optional = true }
5159
parquet = { workspace = true, optional = true, default-features = true }

datafusion/common/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod file_options;
3434
pub mod format;
3535
pub mod hash_utils;
3636
pub mod parsers;
37+
pub mod rounding;
3738
pub mod scalar;
3839
pub mod stats;
3940
pub mod test_util;

datafusion/physical-expr/src/intervals/rounding.rs renamed to datafusion/common/src/rounding.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
2323
use std::ops::{Add, BitAnd, Sub};
2424

25-
use datafusion_common::Result;
26-
use datafusion_common::ScalarValue;
25+
use crate::Result;
26+
use crate::ScalarValue;
2727

2828
// Define constants for ARM
2929
#[cfg(all(target_arch = "aarch64", not(target_os = "windows")))]
@@ -162,7 +162,7 @@ impl FloatBits for f64 {
162162
/// # Examples
163163
///
164164
/// ```
165-
/// use datafusion_physical_expr::intervals::rounding::next_up;
165+
/// use datafusion_common::rounding::next_up;
166166
///
167167
/// let f: f32 = 1.0;
168168
/// let next_f = next_up(f);
@@ -195,7 +195,7 @@ pub fn next_up<F: FloatBits + Copy>(float: F) -> F {
195195
/// # Examples
196196
///
197197
/// ```
198-
/// use datafusion_physical_expr::intervals::rounding::next_down;
198+
/// use datafusion_common::rounding::next_down;
199199
///
200200
/// let f: f32 = 1.0;
201201
/// let next_f = next_down(f);

datafusion/common/src/scalar.rs

+42
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,48 @@ impl ScalarValue {
988988
Self::try_from_array(r.as_ref(), 0)
989989
}
990990

991+
/// Wrapping multiplication of `ScalarValue`
992+
///
993+
/// NB: operating on `ScalarValue` directly is not efficient, performance sensitive code
994+
/// should operate on Arrays directly, using vectorized array kernels.
995+
pub fn mul<T: Borrow<ScalarValue>>(&self, other: T) -> Result<ScalarValue> {
996+
let r = mul_wrapping(&self.to_scalar()?, &other.borrow().to_scalar()?)?;
997+
Self::try_from_array(r.as_ref(), 0)
998+
}
999+
1000+
/// Checked multiplication of `ScalarValue`
1001+
///
1002+
/// NB: operating on `ScalarValue` directly is not efficient, performance sensitive code
1003+
/// should operate on Arrays directly, using vectorized array kernels.
1004+
pub fn mul_checked<T: Borrow<ScalarValue>>(&self, other: T) -> Result<ScalarValue> {
1005+
let r = mul(&self.to_scalar()?, &other.borrow().to_scalar()?)?;
1006+
Self::try_from_array(r.as_ref(), 0)
1007+
}
1008+
1009+
/// Performs `lhs / rhs`
1010+
///
1011+
/// Overflow or division by zero will result in an error, with exception to
1012+
/// floating point numbers, which instead follow the IEEE 754 rules.
1013+
///
1014+
/// NB: operating on `ScalarValue` directly is not efficient, performance sensitive code
1015+
/// should operate on Arrays directly, using vectorized array kernels.
1016+
pub fn div<T: Borrow<ScalarValue>>(&self, other: T) -> Result<ScalarValue> {
1017+
let r = div(&self.to_scalar()?, &other.borrow().to_scalar()?)?;
1018+
Self::try_from_array(r.as_ref(), 0)
1019+
}
1020+
1021+
/// Performs `lhs % rhs`
1022+
///
1023+
/// Overflow or division by zero will result in an error, with exception to
1024+
/// floating point numbers, which instead follow the IEEE 754 rules.
1025+
///
1026+
/// NB: operating on `ScalarValue` directly is not efficient, performance sensitive code
1027+
/// should operate on Arrays directly, using vectorized array kernels.
1028+
pub fn rem<T: Borrow<ScalarValue>>(&self, other: T) -> Result<ScalarValue> {
1029+
let r = rem(&self.to_scalar()?, &other.borrow().to_scalar()?)?;
1030+
Self::try_from_array(r.as_ref(), 0)
1031+
}
1032+
9911033
pub fn is_unsigned(&self) -> bool {
9921034
matches!(
9931035
self,

datafusion/expr/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ path = "src/lib.rs"
3535
[features]
3636

3737
[dependencies]
38-
ahash = { version = "0.8", default-features = false, features = ["runtime-rng"] }
38+
ahash = { version = "0.8", default-features = false, features = [
39+
"runtime-rng",
40+
] }
3941
arrow = { workspace = true }
4042
arrow-array = { workspace = true }
4143
datafusion-common = { workspace = true }
44+
paste = "^1.0"
4245
sqlparser = { workspace = true }
4346
strum = { version = "0.25.0", features = ["derive"] }
4447
strum_macros = "0.25.0"

0 commit comments

Comments
 (0)