fix(MachineLearningScorer, v1.2): splice metric_list verbatim instead of double-encoding - #7003
Open
Yicong-Huang wants to merge 1 commit into
Open
Conversation
…uble-encoding (#6805) ### What changes were proposed in this PR? Fixes a double-encoding bug in `MachineLearningScorerOpDesc` where the selected metrics collapse into a single malformed `metric_list` element. `getSelectedMetrics()` returns the chosen metric names as one comma-separated, already-quoted fragment (e.g. `'Accuracy','F1 Score'`) and is spliced into the generated Python as a list: ``` metric_list = [${getSelectedMetrics()}] ``` Its return type was **`EncodableString`**, so the Python template builder **re-encoded the whole fragment as one Python string value** instead of splicing it verbatim. The emitted code became: ```python metric_list = [self.decode_python_template('J0FjY3VyYWN5JywnRjEgU2NvcmUn')] ``` where the base64 `J0FjY3VyYWN5JywnRjEgU2NvcmUn` decodes to `'Accuracy','F1 Score'` — i.e. the entire quoted list collapses into **one** decoded string element: ```python metric_list = ["'Accuracy','F1 Score'"] # ONE element, incl. inner quotes ``` instead of the intended: ```python metric_list = ['Accuracy', 'F1 Score'] ``` So every downstream `if 'X' in metric_list` and `for metric in metric_list` / `metrics_func[metric]` operates on that single malformed element — the selected metrics are never matched, and the classification path hits a `KeyError` on the bogus key. The Scorer produces wrong/empty output for both the classification and regression paths. **Fix:** change `getSelectedMetrics()`'s return type from `EncodableString` to plain `String`, so the builder splices it verbatim into `metric_list = ['Accuracy','F1 Score']`. The method body is unchanged. ```diff - private def getSelectedMetrics(): EncodableString = { + private def getSelectedMetrics(): String = { val metric = if (isRegression) regressionMetrics else classificationMetrics metric.map(metric => getMetricName(metric)).mkString("'", "','", "'") } ``` ### Any related issues, documentation, discussions? Closes #6790 ### How was this PR tested? Added a regression test to `MachineLearningScorerOpDescSpec` that constructs the descriptor with `classificationMetrics = List(accuracy, f1Score)`, calls `generatePythonCode()`, and asserts: - the emitted code contains `metric_list = ['Accuracy','F1 Score']` (verbatim), and - the metric names are **not** base64-re-encoded through the template builder. Both assertions fail on `main` (the line is emitted as `metric_list = [self.decode_python_template('J0FjY3VyYWN5JywnRjEgU2NvcmUn')]`) and pass with this change. Ran the full suite locally: ``` sbt "WorkflowOperator/testOnly org.apache.texera.amber.operator.machineLearning.Scorer.MachineLearningScorerOpDescSpec" ... Tests: succeeded 7, failed 0, canceled 0, ignored 0, pending 0 All tests passed. ``` ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 4.8) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- (backported from commit 3a51bfb) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Automated Reviewer SuggestionsBased on the
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/v1.2 #7003 +/- ##
==================================================
- Coverage 53.95% 52.37% -1.58%
- Complexity 1441 2487 +1046
==================================================
Files 809 1077 +268
Lines 34144 42267 +8123
Branches 3448 4548 +1100
==================================================
+ Hits 18421 22138 +3717
- Misses 14815 18819 +4004
- Partials 908 1310 +402
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this PR?
Backport of #6805 to
release/v1.2, cherry-picked from 3a51bfb.Source fix only. The test changes from #6805 were omitted: the touched test spec(s) do not exist on
release/v1.2(or depend on main-only test infrastructure), so backporting them cleanly is not possible. Only the source fix is carried over, per maintainer guidance.Any related issues, documentation, discussions?
Backport of #6805. Originally linked #6790.
How was this PR tested?
Release-branch CI runs on this PR. The source change cherry-picked cleanly; test changes were intentionally dropped (see above).
Was this PR authored or co-authored using generative AI tooling?
Yes — backport prepared with Claude Code (mechanical cherry-pick + conflict resolution; the change itself is #6805 by its original author).
🤖 Generated with Claude Code