viirya commented on a change in pull request #31476: URL: https://github.com/apache/spark/pull/31476#discussion_r580807887
########## File path: sql/catalyst/src/main/java/org/apache/spark/sql/connector/CustomMetric.java ########## @@ -0,0 +1,61 @@ +/* + * 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(); + + /** + * 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 Review comment: As you can see, the metric API here is a logical representation of metrics from DS v2. We are not going to re-invent a whole metric API. SQLMetrics are internal to Spark. It is not exposed to end users and data source developers, so I don't think it worries me too much. I'm not saying that we should not build a good API for DS v2 developers. Seems to me some points in above comments are from end user perspective, I'd like to point out this is for different scenarios. As this is used for DS v2 purpose, it is for SQL metrics and internally it is converted to SQL metrics. To make SQLMetric support Accmulator and let DS v2 reports Accmulator does not sound bad idea to me. But I'd doubt if it is worth. One argued point is to define arbitrary combine behavior. Once making SQLMetric support Accmulator, does it mean that we can use arbitrary Accmulator? No, basically SQLMetric allows certain types of metrics, we still need to change SQLMetric to support new metrics. So the only benefit I thought is to not have another metric API. And I don't think it is serious for this case at the beginning. This API is pretty simple as it is just logical representation and we only need small change internally to convert collected metrics from DS v2 to SQL metrics. I just read through the code path to be touched in order to make SQLMetric support Accmulator. Seems it involves more changes not only in DS v2 but maybe also in sql/core, etc. Although I doubt if it is worth, I'm open to the suggested Accmulator approach. Let's gather more thoughts from others? cc @cloud-fan @dongjoon-hyun @rdblue @Ngone51 @sunchao WDYT? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
