Skip to content

Commit

Permalink
feat: support date_part function and more fields for extract (ris…
Browse files Browse the repository at this point in the history
…ingwavelabs#8830)

Signed-off-by: Runji Wang <wangrunji0408@163.com>
Co-authored-by: xiangjinwu <17769960+xiangjinwu@users.noreply.github.com>
  • Loading branch information
wangrunji0408 and xiangjinwu authored Apr 4, 2023
1 parent dca4ced commit bbe15be
Show file tree
Hide file tree
Showing 16 changed files with 548 additions and 243 deletions.
80 changes: 40 additions & 40 deletions e2e_test/batch/duckdb/join/iejoin/test_iejoin.test.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -140,46 +140,46 @@ WITH data_table AS (
GROUP BY bucket, low, high
ORDER BY bucket;
----
0 1577836800 1578627360 10
1 1578627360 1579417920 9
2 1579417920 1580208480 9
3 1580208480 1580999040 9
4 1580999040 1581789600 9
5 1581789600 1582580160 9
6 1582580160 1583370720 10
7 1583370720 1584161280 9
8 1584161280 1584951840 9
9 1584951840 1585742400 9
10 1585742400 1586532960 9
11 1586532960 1587323520 9
12 1587323520 1588114080 9
13 1588114080 1588904640 10
14 1588904640 1589695200 9
15 1589695200 1590485760 9
16 1590485760 1591276320 9
17 1591276320 1592066880 9
18 1592066880 1592857440 9
19 1592857440 1593648000 9
20 1593648000 1594438560 10
21 1594438560 1595229120 9
22 1595229120 1596019680 9
23 1596019680 1596810240 9
24 1596810240 1597600800 9
25 1597600800 1598391360 9
26 1598391360 1599181920 10
27 1599181920 1599972480 9
28 1599972480 1600763040 9
29 1600763040 1601553600 9
30 1601553600 1602344160 9
31 1602344160 1603134720 9
32 1603134720 1603925280 9
33 1603925280 1604715840 10
34 1604715840 1605506400 9
35 1605506400 1606296960 9
36 1606296960 1607087520 9
37 1607087520 1607878080 9
38 1607878080 1608668640 9
39 1608668640 1609459200 9
0 1577836800.000000 1578627360.000000 10
1 1578627360.000000 1579417920.000000 9
2 1579417920.000000 1580208480.000000 9
3 1580208480.000000 1580999040.000000 9
4 1580999040.000000 1581789600.000000 9
5 1581789600.000000 1582580160.000000 9
6 1582580160.000000 1583370720.000000 10
7 1583370720.000000 1584161280.000000 9
8 1584161280.000000 1584951840.000000 9
9 1584951840.000000 1585742400.000000 9
10 1585742400.000000 1586532960.000000 9
11 1586532960.000000 1587323520.000000 9
12 1587323520.000000 1588114080.000000 9
13 1588114080.000000 1588904640.000000 10
14 1588904640.000000 1589695200.000000 9
15 1589695200.000000 1590485760.000000 9
16 1590485760.000000 1591276320.000000 9
17 1591276320.000000 1592066880.000000 9
18 1592066880.000000 1592857440.000000 9
19 1592857440.000000 1593648000.000000 9
20 1593648000.000000 1594438560.000000 10
21 1594438560.000000 1595229120.000000 9
22 1595229120.000000 1596019680.000000 9
23 1596019680.000000 1596810240.000000 9
24 1596810240.000000 1597600800.000000 9
25 1597600800.000000 1598391360.000000 9
26 1598391360.000000 1599181920.000000 10
27 1599181920.000000 1599972480.000000 9
28 1599972480.000000 1600763040.000000 9
29 1600763040.000000 1601553600.000000 9
30 1601553600.000000 1602344160.000000 9
31 1602344160.000000 1603134720.000000 9
32 1603134720.000000 1603925280.000000 9
33 1603925280.000000 1604715840.000000 10
34 1604715840.000000 1605506400.000000 9
35 1605506400.000000 1606296960.000000 9
36 1606296960.000000 1607087520.000000 9
37 1607087520.000000 1607878080.000000 9
38 1607878080.000000 1608668640.000000 9
39 1608668640.000000 1609459200.000000 9


statement ok
Expand Down
1 change: 1 addition & 0 deletions proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ message ExprNode {
BITWISE_SHIFT_RIGHT = 36;
// date functions
EXTRACT = 101;
DATE_PART = 102;
TUMBLE_START = 103;
// From f64 to timestamp.
// e.g. `select to_timestamp(1672044740.0)`
Expand Down
6 changes: 3 additions & 3 deletions src/common/src/array/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ impl FromIntoArrow for Interval {

fn into_arrow(self) -> Self::ArrowType {
arrow_array::types::IntervalMonthDayNanoType::make_value(
self.get_months(),
self.get_days(),
self.months(),
self.days(),
// TODO: this may overflow and we need `try_into`
self.get_usecs() * 1000,
self.usecs() * 1000,
)
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/common/src/array/interval_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ mod tests {
}
let ret_arr = array_builder.finish();
for v in ret_arr.iter().flatten() {
assert_eq!(v.get_months(), 12);
assert_eq!(v.get_days(), 0);
assert_eq!(v.months(), 12);
assert_eq!(v.days(), 0);
}
let ret_arr = IntervalArray::from_iter([Some(Interval::from_ymd(1, 0, 0)), None]);
let v = ret_arr.value_at(0).unwrap();
assert_eq!(v.get_months(), 12);
assert_eq!(v.get_days(), 0);
assert_eq!(v.months(), 12);
assert_eq!(v.days(), 0);
let v = ret_arr.value_at(1);
assert_eq!(v, None);
let v = unsafe { ret_arr.value_at_unchecked(0).unwrap() };
assert_eq!(v.get_months(), 12);
assert_eq!(v.get_days(), 0);
assert_eq!(v.months(), 12);
assert_eq!(v.days(), 0);
}
}
8 changes: 4 additions & 4 deletions src/common/src/types/chrono_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,13 @@ impl CheckedAdd<Interval> for Timestamp {

fn checked_add(self, rhs: Interval) -> Option<Timestamp> {
let mut date = self.0.date();
if rhs.get_months() != 0 {
if rhs.months() != 0 {
// NaiveDate don't support add months. We need calculate manually
let mut day = date.day() as i32;
let mut month = date.month() as i32;
let mut year = date.year();
// Calculate the number of year in this interval
let interval_months = rhs.get_months();
let interval_months = rhs.months();
let year_diff = interval_months / 12;
year += year_diff;

Expand All @@ -556,8 +556,8 @@ impl CheckedAdd<Interval> for Timestamp {
date = NaiveDate::from_ymd_opt(year, month as u32, day as u32)?;
}
let mut datetime = NaiveDateTime::new(date, self.0.time());
datetime = datetime.checked_add_signed(Duration::days(rhs.get_days().into()))?;
datetime = datetime.checked_add_signed(Duration::microseconds(rhs.get_usecs()))?;
datetime = datetime.checked_add_signed(Duration::days(rhs.days().into()))?;
datetime = datetime.checked_add_signed(Duration::microseconds(rhs.usecs()))?;

Some(Timestamp::new(datetime))
}
Expand Down
Loading

0 comments on commit bbe15be

Please sign in to comment.