Skip to content

feat: Add Spark months_between function#14909

Closed
zml1206 wants to merge 5 commits intofacebookincubator:mainfrom
zml1206:months_between
Closed

feat: Add Spark months_between function#14909
zml1206 wants to merge 5 commits intofacebookincubator:mainfrom
zml1206:months_between

Conversation

@zml1206
Copy link
Contributor

@zml1206 zml1206 commented Sep 19, 2025

@netlify
Copy link

netlify bot commented Sep 19, 2025

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit d3caae8
🔍 Latest deploy log https://app.netlify.com/projects/meta-velox/deploys/68d5b7530aa2dc00086b9f63

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 19, 2025

SELECT months_between('1997-02-28 10:30:00', '1996-10-30', true); -- 3.94959677
SELECT months_between('1997-02-28 10:30:00', '1996-10-30', false); -- 3.9495967741935485
SELECT months_between('1997-02-28 10:30:00', '1996-03-31 11:00:00', true); -- 11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spark-sql (default)> SELECT months_between('1997-02-28 10:30:00', '1996-03-31 11:00:00', true);
11.0

SELECT months_between('1997-02-28 10:30:00', '1996-10-30', true); -- 3.94959677
SELECT months_between('1997-02-28 10:30:00', '1996-10-30', false); -- 3.9495967741935485
SELECT months_between('1997-02-28 10:30:00', '1996-03-31 11:00:00', true); -- 11
SELECT months_between('1997-02-21 10:30:00', '1996-03-21 11:00:00', true); -- 11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spark-sql (default)> SELECT months_between('1997-02-21 10:30:00', '1996-03-21 11:00:00', true);
11.0

inline constexpr int64_t kSecondsInMinute = 60;
inline constexpr int64_t kSecondsInHour = 3600;
inline constexpr int64_t kSecondsInDay = 86'400;
inline constexpr int64_t kSecondsInMonth = 2'678'400;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a function such as kSecondsInDay * 31 to represent

std::optional<DateTimeUnit> unit_ = std::nullopt;
};

template <typename T>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TExec

}

FOLLY_ALWAYS_INLINE bool isEndDayOfMonth(const std::tm& tm) {
const auto endDay = util::getMaxDayOfMonth(getYear(tm), getMonth(tm));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove endDay since it is used only once

}

FOLLY_ALWAYS_INLINE double
monthsBetween(const std::tm& tm1, const std::tm& tm2, const bool roundOff) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const bool -> bool, remove cost when passing by value

"months_between(c0, c1, c2)", timestamp1, timestamp2, roundOff);
};

EXPECT_EQ(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add more roundOff false test to make sure it works well?

}

FOLLY_ALWAYS_INLINE double
monthsBetween(const std::tm& tm1, const std::tm& tm2, bool roundOff) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only SparkSql has this function, we could move it to struct MonthsBetweenFunction

Copy link
Collaborator

@jinchengchenghh jinchengchenghh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, could you also help take a look? Thanks! @rui-mo

@zml1206
Copy link
Contributor Author

zml1206 commented Sep 24, 2025

Fuzzer test
image

Copy link
Collaborator

@rui-mo rui-mo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please update apache/gluten#10782 to ensure all Spark tests pass? Thanks.

@zml1206
Copy link
Contributor Author

zml1206 commented Sep 25, 2025

Would you please update apache/incubator-gluten#10782 to ensure all Spark tests pass?

It seems that all Spark tests passed, is there something I missed?

address comments
@rui-mo
Copy link
Collaborator

rui-mo commented Sep 25, 2025

Would you please update apache/incubator-gluten#10782 to ensure all Spark tests pass?

It seems that all Spark tests passed, is there something I missed?

@zml1206 Just noticed some workflow failed, and want to make sure it works.

@zml1206
Copy link
Contributor Author

zml1206 commented Sep 25, 2025

Would you please update apache/incubator-gluten#10782 to ensure all Spark tests pass?

It seems that all Spark tests passed, is there something I missed?

@zml1206 Just noticed some workflow failed, and want to make sure it works.

They are Enhanced, velox is a branch of IBM.

Copy link
Collaborator

@rui-mo rui-mo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Just two nits. Looks good overall.

@rui-mo rui-mo added the ready-to-merge PR that have been reviewed and are ready for merging. PRs with this tag notify the Velox Meta oncall label Sep 26, 2025
@facebook-github-bot
Copy link
Contributor

@bikramSingh91 has imported this pull request. If you are a Meta employee, you can view this in D83490561.

@facebook-github-bot
Copy link
Contributor

@bikramSingh91 merged this pull request in a6fa169.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged ready-to-merge PR that have been reviewed and are ready for merging. PRs with this tag notify the Velox Meta oncall

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants