Skip to content

[AURON #2134] Implement native function of months_between#2149

Open
weimingdiit wants to merge 2 commits intoapache:masterfrom
weimingdiit:feat/months_between-native-function
Open

[AURON #2134] Implement native function of months_between#2149
weimingdiit wants to merge 2 commits intoapache:masterfrom
weimingdiit:feat/months_between-native-function

Conversation

@weimingdiit
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #2134

Rationale for this change

Spark months_between(...) was not supported in Auron’s native execution path, so queries using it fell back instead of being planned and executed natively.

This change adds native support through the extension-function path and keeps the behavior aligned with Spark semantics for DATE and TIMESTAMP inputs, including roundOff handling and session time zone aware calculations.

What changes are included in this PR?

This PR:

  • adds Spark MonthsBetween expression conversion in NativeConverters
  • adds buildMonthsBetweenExt to pass date1, date2, roundOff, and session time zone to the native function
  • registers Spark_MonthsBetween in datafusion-ext-functions
  • implements spark_months_between in spark_dates.rs
  • handles Spark-compatible same-day and last-day-of-month cases, fractional month calculation, rounding, and null propagation
  • adds regression coverage in AuronFunctionSuite
  • adds Rust unit tests for core months_between semantics

Are there any user-facing changes?

NO.

How was this patch tested?

CI.

Spark `months_between(...)` was not supported in Auron’s native execution path, so queries using it fell back instead of being planned and executed natively.

This change adds native support through the extension-function path and keeps the behavior aligned with Spark semantics for `DATE` and `TIMESTAMP` inputs, including `roundOff` handling and session time zone aware calculations.

This PR:
- adds Spark `MonthsBetween` expression conversion in `NativeConverters`
- adds `buildMonthsBetweenExt` to pass `date1`, `date2`, `roundOff`, and session time zone to the native function
- registers `Spark_MonthsBetween` in `datafusion-ext-functions`
- implements `spark_months_between` in `spark_dates.rs`
- handles Spark-compatible same-day and last-day-of-month cases, fractional month calculation, rounding, and null propagation
- adds regression coverage in `AuronFunctionSuite`
- adds Rust unit tests for core `months_between` semantics

---------

Signed-off-by: weimingdiit <weimingdiit@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds native execution support for Spark months_between(...) via Auron’s extension-function path so queries can be planned/executed natively instead of falling back.

Changes:

  • Convert Spark MonthsBetween expressions in NativeConverters and build an ext-function call including roundOff and (when needed) session time zone.
  • Register and implement Spark_MonthsBetween in the native DataFusion ext-functions crate with Spark-compatible edge-case handling.
  • Add Scala regression coverage and Rust unit tests for months_between semantics.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
spark-extension/src/main/scala/org/apache/spark/sql/auron/NativeConverters.scala Adds Spark MonthsBetween conversion and builds the ext-function call arguments (incl. roundOff + tz).
spark-extension-shims-spark/src/test/scala/org/apache/auron/AuronFunctionSuite.scala Adds an end-to-end Spark regression test exercising months_between native execution.
native-engine/datafusion-ext-functions/src/spark_dates.rs Implements spark_months_between and adds unit tests for core semantics.
native-engine/datafusion-ext-functions/src/lib.rs Registers Spark_MonthsBetween in the ext-function factory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: weimingdiit <weimingdiit@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement native function of months_between

4 participants