Skip to content

[AURON#1327] Implement native function of round#1426

Merged
zuston merged 5 commits intoapache:masterfrom
slfan1989:auron-1327
Oct 11, 2025
Merged

[AURON#1327] Implement native function of round#1426
zuston merged 5 commits intoapache:masterfrom
slfan1989:auron-1327

Conversation

@slfan1989
Copy link
Contributor

@slfan1989 slfan1989 commented Oct 9, 2025

Which issue does this PR close?

Closes #1327.

Rationale for this change

spark_round is a Rust implementation of an Apache Spark-style round function for the DataFusion query engine. Its primary purpose is to perform rounding operations on numerical values, adhering to Spark's HALF_UP rounding mode (i.e., 0.5 rounds to 1, -0.5 rounds to -1). It supports multiple data types (Float64, Float32, Int16, Int32, Int64, Decimal128) and can handle negative precision and null values.

What changes are included in this PR?

  • We implemented the Round function following Spark’s HALF_UP rounding semantics,
    ensuring full behavioral alignment with Spark SQL.

  • For validation, we directly reused the unit tests from MathExpressionsSuite#round/bround,
    comparing our implementation against Spark’s native results using:

checkEvaluation(Round(doublePi, scale), doubleResults(i), EmptyRow)
checkEvaluation(Round(shortPi, scale), shortResults(i), EmptyRow)
checkEvaluation(Round(intPi, scale), intResults(i), EmptyRow)
checkEvaluation(Round(longPi, scale), longResults(i), EmptyRow)
checkEvaluation(Round(floatPi, scale), floatResults(i), EmptyRow)
  • We also added additional boundary test cases to ensure that spark_round
    behaves correctly under edge conditions such as large numbers, small numbers, and negative scales.

Are there any user-facing changes?

No.

How was this patch tested?

Unit Test.

@slfan1989
Copy link
Contributor Author

@richox @cxzl25 Could you please help review this PR? Thanks a lot!

In #1327, I conducted a detailed comparison between Spark and DataFusion regarding the behavior of the Round function. After identifying the differences, I implemented this version by referring to the implementation of other functions, such as spark_sha2. This implementation has been verified with Spark’s unit tests, and the results are as expected.

@slfan1989 slfan1989 marked this pull request as ready for review October 9, 2025 11:37
Copy link
Member

@zuston zuston left a comment

Choose a reason for hiding this comment

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

looks good, if we could involve the more spark tests here, it will be better.

@slfan1989
Copy link
Contributor Author

looks good, if we could involve the more spark tests here, it will be better.

@zuston Thank you very much for reviewing the code. I have implemented the Spark validation logic based on your suggestions, and it runs as expected in local testing.

@slfan1989
Copy link
Contributor Author

@richox @cxzl25 @zuston Could you please review this PR? Thank you very much!

@zuston zuston changed the title [AURON#1327] Implement native function: round(). [AURON#1327] Implement native function of round Oct 11, 2025
@zuston zuston merged commit 4c52bf4 into apache:master Oct 11, 2025
84 checks passed
@zuston
Copy link
Member

zuston commented Oct 11, 2025

@richox @cxzl25 @zuston Could you please review this PR? Thank you very much!

Merged. Thanks for your contribution! @slfan1989

@slfan1989
Copy link
Contributor Author

@richox @cxzl25 @zuston Could you please review this PR? Thank you very much!

Merged. Thanks for your contribution! @slfan1989

Thank you very much for reviewing the code!

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: round()

2 participants