-
Notifications
You must be signed in to change notification settings - Fork 612
[CORE] Add customMetrics extension point to ShuffleWriterMetrics for backend-specific shuffle stats #12114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
luis4a0
wants to merge
2
commits into
apache:main
Choose a base branch
from
luis4a0:lpenaranda/pr-custom-metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[CORE] Add customMetrics extension point to ShuffleWriterMetrics for backend-specific shuffle stats #12114
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
116 changes: 116 additions & 0 deletions
116
gluten-arrow/src/test/scala/org/apache/gluten/vectorized/GlutenSplitResultSuite.scala
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.gluten.vectorized | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
|
|
||
| /** | ||
| * Unit tests for [[GlutenSplitResult]]'s `customMetrics` reassembly logic. The marshalled form | ||
| * across JNI is two parallel arrays (keys + values); the POJO reassembles them lazily on first | ||
| * `getCustomMetrics()` access and caches an unmodifiable map. These tests exercise the JVM-side | ||
| * boundary without needing a Spark / native-library round-trip. | ||
| */ | ||
| class GlutenSplitResultSuite extends SparkFunSuite { | ||
|
|
||
| private def newResult(keys: Array[String], values: Array[Long]): GlutenSplitResult = { | ||
| new GlutenSplitResult( | ||
| 0L, | ||
| 0L, | ||
| 0L, | ||
| 0L, | ||
| 0L, | ||
| 0L, | ||
| 0L, | ||
| 0L, | ||
| 0L, | ||
| 0L, | ||
| 0.0d, | ||
| 0L, | ||
| Array.empty[Long], | ||
| Array.empty[Long], | ||
| keys, | ||
| values) | ||
| } | ||
|
|
||
| test("getCustomMetrics returns empty map when native side passed no entries") { | ||
| val r = newResult(Array.empty[String], Array.empty[Long]) | ||
| val m = r.getCustomMetrics | ||
| assert(m.isEmpty) | ||
| } | ||
|
|
||
| test("getCustomMetrics returns empty map when native side passed null arrays") { | ||
| val r = newResult(null, null) | ||
| val m = r.getCustomMetrics | ||
| assert(m.isEmpty) | ||
| } | ||
|
|
||
| test("getCustomMetrics reassembles the parallel-array form into a Map") { | ||
| val keys = Array("Velox.InputEncoding.Flat", "Velox.InputEncoding.Dictionary") | ||
| val values = Array(123L, 7L) | ||
| val r = newResult(keys, values) | ||
| val m = r.getCustomMetrics | ||
| assert(m.size() == 2) | ||
| assert(m.get("Velox.InputEncoding.Flat") == 123L) | ||
| assert(m.get("Velox.InputEncoding.Dictionary") == 7L) | ||
| } | ||
|
|
||
| test("getCustomMetrics caches the reassembled map across calls") { | ||
| val r = newResult(Array("k"), Array(1L)) | ||
| val first = r.getCustomMetrics | ||
| val second = r.getCustomMetrics | ||
| // Same identity: cached result is returned on subsequent calls. | ||
| assert(first eq second) | ||
| } | ||
|
|
||
| test("getCustomMetrics returns an unmodifiable map") { | ||
| val r = newResult(Array("k"), Array(1L)) | ||
| val m = r.getCustomMetrics | ||
| intercept[UnsupportedOperationException] { | ||
| m.put("x", 2L) | ||
| } | ||
| } | ||
|
|
||
| test("getCustomMetrics is null-safe for code reading from older Gluten libs") { | ||
| // Older Gluten native builds may construct GlutenSplitResult without | ||
| // the customMetrics arrays at all — simulate by passing null/null. We | ||
| // already covered that, but assert here that the *empty* map is | ||
| // distinguishable from a populated one. | ||
| val empty = newResult(null, null).getCustomMetrics | ||
| val populated = newResult(Array("a"), Array(1L)).getCustomMetrics | ||
| assert(empty.isEmpty) | ||
| assert(!populated.isEmpty) | ||
| } | ||
|
|
||
| test("getCustomMetrics fails loudly on mismatched key/value array lengths") { | ||
| // A future native-side producer that ships mismatched arrays must not | ||
| // silently corrupt the metrics map (and must not leave the lazy cache | ||
| // field unassigned so subsequent calls re-enter and re-throw). Assert | ||
| // that the first call throws IllegalStateException with both lengths | ||
| // mentioned, and that a second call still throws (the cache field is | ||
| // never assigned to a partial map). | ||
| val r = newResult(Array("a", "b"), Array(1L)) | ||
| val ex = intercept[IllegalStateException](r.getCustomMetrics) | ||
| assert(ex.getMessage.contains("2") && ex.getMessage.contains("1")) | ||
| intercept[IllegalStateException](r.getCustomMetrics) | ||
| } | ||
|
|
||
| test("getCustomMetrics fails loudly when values array is null but keys is non-empty") { | ||
| val r = newResult(Array("a"), null) | ||
| val ex = intercept[IllegalStateException](r.getCustomMetrics) | ||
| assert(ex.getMessage.contains("null")) | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.