Skip to content

Commit

Permalink
feat: Support distinct binary expression types
Browse files Browse the repository at this point in the history
  • Loading branch information
MazterQyou committed Mar 18, 2024
1 parent 6dae83c commit b051b03
Show file tree
Hide file tree
Showing 9 changed files with 799 additions and 91 deletions.
188 changes: 181 additions & 7 deletions datafusion-cli/Cargo.lock

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

2 changes: 1 addition & 1 deletion datafusion/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ pub use column::Column;
pub use dfschema::{DFField, DFSchema, DFSchemaRef, ExprSchema, ToDFSchema};
pub use error::{DataFusionError, Result};
pub use outer_query_cursor::OuterQueryCursor;
pub use scalar::{ScalarType, ScalarValue};
pub use scalar::{scalar_negate_interval_day_time, ScalarType, ScalarValue};
19 changes: 18 additions & 1 deletion datafusion/common/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,9 @@ impl ScalarValue {
| ScalarValue::Int16(None)
| ScalarValue::Int32(None)
| ScalarValue::Int64(None)
| ScalarValue::Float32(None) => self.clone(),
| ScalarValue::Float32(None)
| ScalarValue::IntervalYearMonth(None)
| ScalarValue::IntervalDayTime(None) => self.clone(),
ScalarValue::Float64(Some(v)) => ScalarValue::Float64(Some(-v)),
ScalarValue::Float32(Some(v)) => ScalarValue::Float32(Some(-v)),
ScalarValue::Int8(Some(v)) => ScalarValue::Int8(Some(-v)),
Expand All @@ -627,6 +629,12 @@ impl ScalarValue {
ScalarValue::Decimal128(Some(v), precision, scale) => {
ScalarValue::Decimal128(Some(-v), *precision, *scale)
}
ScalarValue::IntervalYearMonth(Some(v)) => {
ScalarValue::IntervalYearMonth(Some(-v))
}
ScalarValue::IntervalDayTime(Some(v)) => {
ScalarValue::IntervalDayTime(Some(scalar_negate_interval_day_time(*v)))
}
_ => panic!("Cannot run arithmetic negate on scalar value: {:?}", self),
}
}
Expand Down Expand Up @@ -1989,3 +1997,12 @@ impl ScalarType<i64> for TimestampNanosecondType {
ScalarValue::TimestampNanosecond(r, None)
}
}

pub fn scalar_negate_interval_day_time(value: i64) -> i64 {
let value = value as u64;
let days: i32 = ((value & 0xFFFFFFFF00000000) >> 32) as i32;
let milliseconds: i32 = (value & 0xFFFFFFFF) as i32;
let days = -days; // TODO: panics on i32::MIN
let milliseconds = -milliseconds; // TODO: panics on i32::MIN
(((days as u64) << 32) | (milliseconds as u64)) as i64
}
Loading

0 comments on commit b051b03

Please sign in to comment.