srielau opened a new pull request, #60395: URL: https://github.com/apache/spark/pull/60395
### What changes were proposed in this pull request? This is a draft prototype that adds `common/libmpd` (package `org.mpdec`), a Java port of the core of libmpdec, the General Decimal Arithmetic (GDA) library behind CPython's `decimal`. It is capped at 100 digits of precision. Contents: - `Mpd`, `MpdLimbs`: value type with base-10^9 limbs and the limb arithmetic (Knuth Algorithm D division, Newton sqrt seeded from a double). - `MpdOps`: quiet arithmetic: add, sub, mul, div, sqrt, fma, compare. - `MpdContext`, `MpdRound`, `MpdStatus`: precision, emin/emax, rounding modes, clamping, sticky status flags; IEEE 754 presets for decimal16/34/70 exponent ranges. - `MpdFormat`, `MpdMath`: parse/format (including Inf, NaN, sNaN, signed zero) and allocating convenience wrappers. - `src/test`: `MpdSuite` (JUnit 5) checks against `BigDecimal` for basic ops, cohorts, random ops, sqrt, and specials. `MpdBenchmark` is a hand-rolled timing harness; `BidBridge` optionally compares against a prebuilt libbid jar via reflection, enabled only when `MPD_BID_JAR` is set. No libbid sources are imported. - `pom.xml` and `project/SparkBuild.scala`: register the module. It is not published (`publish / skip := true`). Explicitly out of scope: exp, ln, log10, pow, trigonometric functions, and FFT-based multiplication; precision above 100 digits. `MpdFormat.fromBigDecimal` truncates coefficients longer than 100 digits. No Spark code consumes this module yet. The purpose is to evaluate GDA semantics and performance against `BigDecimal` and libbid before choosing an implementation for DECFLOAT. ### Why are the changes needed? Spark needs DECFLOAT with IEEE 754-style non-finite values and GDA cohort semantics. The options evaluated are a `BigDecimal` wrapper, a port of libbid (about 170k lines, plus optimizations), and a port of libmpdec. This module measures the cost of the libmpdec route on the operations DECFLOAT needs, restricted to a precision cap to keep the port small. ### Does this PR introduce _any_ user-facing change? No. The module is not referenced from any other Spark module and is not published. ### How was this patch tested? - `build/sbt 'libmpd/testOnly org.mpdec.MpdSuite'`: 6/6 passing. - `./dev/lint-java`: Checkstyle passed. - `./dev/lint-scala`: Scalastyle passed. Scalafmt in that script only checks `sql/api` and `sql/connect`, which this PR does not touch. - Manual check for non-ASCII characters and lines over 100 columns in added code. Benchmark results are not part of this PR. In the local prototype, MPD was slower than `BigDecimal` and libbid for divide and sqrt, and faster for add, fma, and multiply at higher precision. Those numbers were gathered on a shared dev host and are not a reviewed baseline. They should be reproduced on the GitHub Actions benchmark environment before any decision is made. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Cursor (Auto agent) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
