Skip to content

Commit

Permalink
Support timestamp and interval arithmetic (#5764)
Browse files Browse the repository at this point in the history
* first implementation and tests of timestamp subtraction

* improvement after review

* postgre interval format option

* random tests extended

* corrections after review

* operator check

* flag is removed

* clippy fix

* toml conflict

* minor changes

* deterministic matches

* simplifications (clippy error)

* test format changed

* minor test fix

* Update scalar.rs

* Refactoring and simplifications

* Make ScalarValue support interval comparison

* naming tests

* macro renaming

* renaming macro

* ok till arrow kernel ops

* macro will replace matches inside evaluate

add tests

macro will replace matches inside evaluate

ready for review

* Code refactor

* retract changes in scalar and datetime

* ts op interval with chrono functions

* bug fix and refactor

* test refactor

* Enhance commenting

* new binary operation logic, handling the inside errors

* slt and minor changes

* tz parsing excluded

* replace try_binary and as_datetime, and keep timezone for ts+interval op

* fix after merge

* delete unused functions

---------

Co-authored-by: Mehmet Ozan Kabak <ozankabak@gmail.com>
Co-authored-by: metesynnada <100111937+metesynnada@users.noreply.github.com>
Co-authored-by: Mustafa Akur <mustafa.akur@synnada.ai>
  • Loading branch information
4 people authored Mar 30, 2023
1 parent c9bf3f3 commit 04ef5c1
Show file tree
Hide file tree
Showing 12 changed files with 1,515 additions and 346 deletions.
384 changes: 240 additions & 144 deletions datafusion-cli/Cargo.lock

Large diffs are not rendered by default.

24 changes: 23 additions & 1 deletion datafusion/common/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use arrow::{
Array, BinaryArray, BooleanArray, Date32Array, Date64Array, Decimal128Array,
DictionaryArray, FixedSizeBinaryArray, FixedSizeListArray, Float32Array,
Float64Array, GenericBinaryArray, GenericListArray, GenericStringArray,
Int32Array, Int64Array, LargeListArray, ListArray, MapArray, NullArray,
Int32Array, Int64Array, IntervalDayTimeArray, IntervalMonthDayNanoArray,
IntervalYearMonthArray, LargeListArray, ListArray, MapArray, NullArray,
OffsetSizeTrait, PrimitiveArray, StringArray, StructArray,
TimestampMicrosecondArray, TimestampMillisecondArray, TimestampNanosecondArray,
TimestampSecondArray, UInt32Array, UInt64Array, UnionArray,
Expand Down Expand Up @@ -168,6 +169,27 @@ pub fn as_timestamp_second_array(array: &dyn Array) -> Result<&TimestampSecondAr
Ok(downcast_value!(array, TimestampSecondArray))
}

// Downcast ArrayRef to IntervalYearMonthArray
pub fn as_interval_ym_array(
array: &dyn Array,
) -> Result<&IntervalYearMonthArray, DataFusionError> {
Ok(downcast_value!(array, IntervalYearMonthArray))
}

// Downcast ArrayRef to IntervalDayTimeArray
pub fn as_interval_dt_array(
array: &dyn Array,
) -> Result<&IntervalDayTimeArray, DataFusionError> {
Ok(downcast_value!(array, IntervalDayTimeArray))
}

// Downcast ArrayRef to IntervalMonthDayNanoArray
pub fn as_interval_mdn_array(
array: &dyn Array,
) -> Result<&IntervalMonthDayNanoArray, DataFusionError> {
Ok(downcast_value!(array, IntervalMonthDayNanoArray))
}

// Downcast ArrayRef to BinaryArray
pub fn as_binary_array(array: &dyn Array) -> Result<&BinaryArray> {
Ok(downcast_value!(array, BinaryArray))
Expand Down
Loading

0 comments on commit 04ef5c1

Please sign in to comment.