zhengruifeng opened a new pull request, #58184:
URL: https://github.com/apache/spark/pull/58184
### What changes were proposed in this pull request?
This PR backports #58147 to `branch-4.x`.
It computes decision tree model stats in a single traversal of the root
node. It adds
`Node.computeStats`, which returns a `NodeStats` value containing the
subtree depth, number of
descendants, and number of leaves. Decision tree classification and
regression models compute
these stats once and `DecisionTreeModel` reuses them for `numNodes`,
`depth`, and leaf metadata.
This also renames the package-private `numLeave` helper to `numLeaves`. In
this backport, the
MiMa exclusions are placed in the 4.4 compatibility section.
### Why are the changes needed?
Before this change, decision tree model metadata could traverse the tree
separately for depth,
node count, and leaf count. Computing these values together avoids redundant
tree walks.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Manually tested with:
```
git diff --check upstream/branch-4.x...HEAD
git diff -U0 upstream/branch-4.x...HEAD -- '*.scala' | awk '/^\+[^+]/ {
line=substr($0, 2); if (length(line)>100 && line !~
/^[[:space:]]*(import|package) / && line !~ /https?:\/\//) print
FILENAME":"NR": "length(line)" chars: "line }'
git diff -U0 upstream/branch-4.x...HEAD -- '*.scala' | awk '/^\+[^+]/ &&
/[^\x00-\x7F]/ { print }'
```
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex
--
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]