-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-34366][SQL] Add interface for DS v2 metrics #31476
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 6 commits
623f193
89e2f3d
38fb966
00842c4
b8c762a
cce58a5
f46b733
eb9d94a
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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * 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.connector; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
| import org.apache.spark.sql.connector.read.PartitionReader; | ||
| import org.apache.spark.sql.connector.read.Scan; | ||
|
|
||
| /** | ||
| * A custom metric. This is a logical representation of a metric reported by data sources during | ||
| * read path. Data sources can report supported metric list by {@link Scan} to Spark in query | ||
| * planning. During query execution, Spark will collect the metrics per partition by | ||
| * {@link PartitionReader} and combine metrics from partitions to the final result. How Spark | ||
| * combines metrics depends on the metric type. For streaming query, Spark will collect and combine | ||
| * metrics for a final result per micro batch. | ||
| * | ||
| * The metrics will be gathered during query execution back to the driver and then combined. The | ||
| * final result will be shown up in the physical operator in Spark UI. | ||
| * | ||
| * @since 3.2.0 | ||
| */ | ||
| @Evolving | ||
| public interface CustomMetric { | ||
| /** | ||
| * Returns the name of custom metric. | ||
| */ | ||
| String name(); | ||
|
|
||
| /** | ||
| * Returns the description of custom metric. | ||
| */ | ||
| String description(); | ||
|
|
||
| /** | ||
| * Returns the long value of custom metric. | ||
| */ | ||
| long value(); | ||
|
|
||
| /** | ||
| * Supported metric type. The metric types must be supported by Spark SQL internal metrics. | ||
| * SUM: Spark sums up metrics from partitions as the final result. | ||
| */ | ||
| enum MetricType { | ||
| SUM | ||
|
||
| } | ||
|
|
||
| /** | ||
| * Returns the type of custom metric. | ||
| */ | ||
| MetricType type(); | ||
| } | ||
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.
Spark SQL internal metrics always return a long value. Do we still need the
LongMetricinterface if metrics types are limited to SQL internal metrics?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.
For now a
CustomMetricwhich returns long value should be enough. Previously there is a suggestion to name it justLongMetricbecause it always returns long value. But it sounds too concrete.So I think is it good to leave some flexibility here? Then I extract
LongMetricout as a separate interface which returns long value.I'm fine to just return long in
CustomMetric(and maybe name it toLongMetric).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.
I'll be +1 on returning the long value directly in
CustomMetric. I don't have a strong opinion about the naming.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.
Okay, let me move it back. See if others have different thoughts.
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.
It sounds weird that we require users to understand internal private APIs when using a public API.
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.
"The metric types must be supported by Spark SQL internal metrics." is more for the developers trying to add new metrics here, instead of using the API. I can remove it if it sounds inappropriate.
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.
+1 for removing it. I think users just need to know the below line:
SUM: Spark sums up metrics from partitions as the final result..