Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]implement to_days function in FE (backport #51455) #51654

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,26 @@ public static ConstantOperator dateDiff(ConstantOperator first, ConstantOperator
first.getDatetime().truncatedTo(ChronoUnit.DAYS)).toDays());
}

<<<<<<< HEAD
@ConstantFunction(name = "years_add", argTypes = {DATETIME, INT}, returnType = DATETIME)
=======
@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 @@ -99,6 +99,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
Loading