-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-35215][SQL] Update custom metric per certain rows and at the end of the task #32330
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,8 @@ import org.apache.spark.sql.connector.CustomMetric | |
| object CustomMetrics { | ||
| private[spark] val V2_CUSTOM = "v2Custom" | ||
|
|
||
| private[spark] val numRowsPerUpdate = 100L | ||
|
||
|
|
||
| /** | ||
| * Given a class name, builds and returns a metric type for a V2 custom metric class | ||
| * `CustomMetric`. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ import org.apache.spark.rdd.RDD | |
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.connector.read.InputPartition | ||
| import org.apache.spark.sql.connector.read.streaming.ContinuousPartitionReaderFactory | ||
| import org.apache.spark.sql.execution.metric.SQLMetric | ||
| import org.apache.spark.sql.execution.metric.{CustomMetrics, SQLMetric} | ||
| import org.apache.spark.sql.types.StructType | ||
| import org.apache.spark.util.NextIterator | ||
|
|
||
|
|
@@ -92,10 +92,18 @@ class ContinuousDataSourceRDD( | |
|
|
||
| val partitionReader = readerForPartition.getPartitionReader() | ||
| new NextIterator[InternalRow] { | ||
| private var numRow = 0L | ||
|
|
||
| override def getNext(): InternalRow = { | ||
| partitionReader.currentMetricsValues.foreach { metric => | ||
| customMetrics(metric.name()).set(metric.value()) | ||
| if (numRow % CustomMetrics.numRowsPerUpdate == 0) { | ||
| partitionReader.currentMetricsValues.foreach { metric => | ||
| assert(customMetrics.contains(metric.name()), | ||
|
||
| s"Custom metrics ${customMetrics.keys.mkString(", ")} do not contain the metric " + | ||
| s"${metric.name()}") | ||
| customMetrics(metric.name()).set(metric.value()) | ||
| } | ||
| } | ||
| numRow += 1 | ||
| readerForPartition.next() match { | ||
| case null => | ||
| finished = true | ||
|
|
||
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.
can we move it into a method to reuse code?
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.
sure.
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 a reused method.