Skip to content

Commit

Permalink
[Enhancement]implement to_days function in FE (#51455)
Browse files Browse the repository at this point in the history
Signed-off-by: evenhuang <[email protected]>
(cherry picked from commit dfb309d)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rewrite/ScalarOperatorFunctions.java
  • Loading branch information
even986025158 authored and mergify[bot] committed Oct 9, 2024
1 parent c672fc6 commit d96e856
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,26 @@ public static ConstantOperator dateDiff(ConstantOperator first, ConstantOperator
first.getDatetime().truncatedTo(ChronoUnit.DAYS)).toDays());
}

<<<<<<< HEAD
@ConstantFunction(name = "years_add", argTypes = {DATETIME, INT}, returnType = DATETIME, isMonotonic = true)
=======
@ConstantFunction.List(list = {
@ConstantFunction(name = "to_days", argTypes = {DATETIME}, returnType = INT, isMonotonic = true),
@ConstantFunction(name = "to_days", argTypes = {DATE}, returnType = INT, isMonotonic = true)
})
public static ConstantOperator to_days(ConstantOperator first) {
ConstantOperator second = ConstantOperator.createDatetime(LocalDateTime.of(0000, 01, 01, 00, 00, 00));
return ConstantOperator.createInt((int) Duration.between(
second.getDatetime().truncatedTo(ChronoUnit.DAYS),
first.getDatetime().truncatedTo(ChronoUnit.DAYS)).toDays());
}

@ConstantFunction.List(list = {
@ConstantFunction(name = "years_add", argTypes = {DATETIME,
INT}, returnType = DATETIME, isMonotonic = true),
@ConstantFunction(name = "years_add", argTypes = {DATE, INT}, returnType = DATE, isMonotonic = true)
})
>>>>>>> dfb309d973 ([Enhancement]implement to_days function in FE (#51455))
public static ConstantOperator yearsAdd(ConstantOperator date, ConstantOperator year) {
return ConstantOperator.createDatetime(date.getDatetime().plusYears(year.getInt()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public void dateDiff() {
assertEquals(-1572, ScalarOperatorFunctions.dateDiff(O_DT_20101202_023010, O_DT_20150323_092355).getInt());
}

@Test
public void to_days() {
assertEquals(734443, ScalarOperatorFunctions.to_days(O_DT_20101102_183010).getInt());
}

@Test
public void yearsAdd() {
assertEquals("2025-03-23T09:23:55",
Expand Down

0 comments on commit d96e856

Please sign in to comment.