-
Notifications
You must be signed in to change notification settings - Fork 29.2k
[SPARK-56598][SQL] Custom metrics support for TruncatableTable #55511
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8bd8325
Metadata-only DELETE Metrics
ZiyaZa 8904a5f
Remove metadata-only DELETE Metrics
ZiyaZa 02b0dc0
Fix
ZiyaZa 48db8bc
Clean-up
ZiyaZa 165dc36
Address comments
ZiyaZa b71017c
Merge branch 'master' into custom-metrics
ZiyaZa 3a6ea98
Merge branch 'master' into custom-metrics
ZiyaZa 3ab64c8
Wrap TruncateTableExec.run in try-finally
ZiyaZa 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
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
80 changes: 80 additions & 0 deletions
80
...ain/scala/org/apache/spark/sql/execution/datasources/v2/SupportsCustomDriverMetrics.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,80 @@ | ||
| /* | ||
| * 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.spark.sql.execution.datasources.v2 | ||
|
|
||
| import org.apache.spark.sql.connector.metric.{CustomMetric, CustomTaskMetric} | ||
| import org.apache.spark.sql.execution.{SparkPlan, SQLExecution} | ||
| import org.apache.spark.sql.execution.metric.{SQLMetric, SQLMetrics} | ||
| import org.apache.spark.util.ArrayImplicits._ | ||
|
|
||
| /** | ||
| * A mixin for Spark plan nodes that expose driver-side custom metrics reported by a connector. | ||
| * Implementations declare the connector-owned metrics via [[customMetrics]]; after the underlying | ||
| * operation has executed they call [[postDriverMetrics]] with the connector's reported values so | ||
| * they are visible in the SQL UI. | ||
| * | ||
| * Nodes that also expose Spark-owned metrics supply them via [[sparkMetrics]]. Names in | ||
| * [[sparkMetrics]] are reserved: if the connector happens to report a value under the same name, | ||
| * Spark's value wins and the connector's is dropped. | ||
| */ | ||
| trait SupportsCustomDriverMetrics { self: SparkPlan => | ||
|
|
||
| /** | ||
| * The custom metrics the connector supports for this operation, keyed by name. | ||
| */ | ||
| def customMetrics: Map[String, SQLMetric] | ||
|
|
||
| /** | ||
| * Spark-owned metrics that should appear alongside the connector-declared ones. Values under | ||
| * these names are owned by Spark and take precedence on a name collision. | ||
| */ | ||
| protected def sparkMetrics: Map[String, SQLMetric] = Map.empty | ||
|
|
||
| override lazy val metrics: Map[String, SQLMetric] = customMetrics ++ sparkMetrics | ||
|
|
||
| /** | ||
| * Converts an array of connector-declared metrics into the map shape [[customMetrics]] uses. | ||
| */ | ||
| protected def createCustomMetrics(metrics: Array[CustomMetric]): Map[String, SQLMetric] = { | ||
| metrics.map { m => | ||
| m.name -> SQLMetrics.createV2CustomMetric(sparkContext, m) | ||
| }.toMap | ||
| } | ||
|
|
||
| /** | ||
| * Applies the values reported by the connector to the declared metrics and posts them so the | ||
| * SQL UI reflects the final values. Metrics not declared via [[customMetrics]] are ignored. | ||
| * Metrics whose name collides with [[sparkMetrics]] are also ignored so Spark-owned values | ||
| * are preserved. | ||
| */ | ||
| protected def postDriverMetrics(taskMetrics: Array[CustomTaskMetric]): Unit = { | ||
| val updated = taskMetrics.flatMap { t => | ||
| if (sparkMetrics.contains(t.name())) { | ||
| // Spark metrics take precedence on collisions. | ||
| None | ||
| } else { | ||
| metrics.get(t.name()).map { metric => | ||
| metric.set(t.value()) | ||
| metric | ||
| } | ||
| } | ||
| } | ||
| val executionId = sparkContext.getLocalProperty(SQLExecution.EXECUTION_ID_KEY) | ||
| SQLMetrics.postDriverMetricUpdates(sparkContext, executionId, updated.toImmutableArraySeq) | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need
@sincefor the new methods?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.