viirya commented on a change in pull request #31476: URL: https://github.com/apache/spark/pull/31476#discussion_r570503897
########## File path: sql/catalyst/src/main/java/org/apache/spark/sql/connector/read/CustomMetric.java ########## @@ -0,0 +1,38 @@ +/* + * 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.read; + +import org.apache.spark.annotation.Evolving; + +/** + * A general custom metric. + * + * @since 3.2.0 + */ +@Evolving +public interface CustomMetric { Review comment: The comment https://github.com/apache/spark/pull/31451#discussion_r569774028 suggested to name it `LongMetric`. But later I think if we may need keep flexibility in the base interface. So I left it as general as possible and add a `LongMetric` which reports a long value. ########## File path: sql/catalyst/src/main/java/org/apache/spark/sql/connector/read/CustomMetric.java ########## @@ -0,0 +1,38 @@ +/* + * 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.read; Review comment: Oh, yea, @rdblue suggested we can add to writes. Let me change the package. Thanks. ########## File path: sql/catalyst/src/main/java/org/apache/spark/sql/connector/read/LongMetric.java ########## @@ -0,0 +1,43 @@ +/* + * 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.read; + +import org.apache.spark.annotation.Evolving; + +/** + * A custom metric that reports a long value. + * + * @since 3.2.0 + */ +@Evolving +public interface LongMetric extends CustomMetric { + /** + * Returns the name of custom metric. + */ + String name(); Review comment: Oops, yea, no need to. ########## File path: sql/catalyst/src/main/java/org/apache/spark/sql/connector/read/Scan.java ########## @@ -102,4 +102,13 @@ default MicroBatchStream toMicroBatchStream(String checkpointLocation) { default ContinuousStream toContinuousStream(String checkpointLocation) { throw new UnsupportedOperationException(description() + ": Continuous scan are not supported"); } + + /** + * Returns an array of supported custom metrics with name and description. + * By default it returns empty array. + */ + default CustomMetric[] supportedCustomMetrics() { Review comment: Hmm, I'm okay on putting it into `SupportsReportMetrics`. From implementation view, I don't see it is much different. Seems we just need to additionally check if a `Scan` is a `SupportsReportMetrics` when we want to get the supported metric list. Semantically it sounds the same. A scan reports no custom metrics v.s. A scan does not support custom metrics. ########## File path: sql/catalyst/src/main/java/org/apache/spark/sql/connector/read/PartitionReader.java ########## @@ -48,4 +49,12 @@ * Return the current record. This method should return same value until `next` is called. */ T get(); + + /** + * Returns an array of custom metrics. By default it returns empty array. + */ + default CustomMetric[] getCustomMetrics() { Review comment: I see. I will make it as a trait. ########## File path: sql/catalyst/src/main/java/org/apache/spark/sql/connector/read/Scan.java ########## @@ -102,4 +102,13 @@ default MicroBatchStream toMicroBatchStream(String checkpointLocation) { default ContinuousStream toContinuousStream(String checkpointLocation) { throw new UnsupportedOperationException(description() + ": Continuous scan are not supported"); } + + /** + * Returns an array of supported custom metrics with name and description. + * By default it returns empty array. + */ + default CustomMetric[] supportedCustomMetrics() { Review comment: I'd prefer an optional method so it sounds good. @dongjoon-hyun @sunchao WDYT? ########## File path: sql/catalyst/src/main/java/org/apache/spark/sql/connector/CustomMetric.java ########## @@ -0,0 +1,38 @@ +/* + * 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; + +/** + * A custom metric. Review comment: I will add more information to the comment. Basically I will add a few metric classes based on `CustomMetric`. They are correspond to sum, size, timing metrics in `SQLMetric`. ---------------------------------------------------------------- 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]
