karuppayya commented on code in PR #7447: URL: https://github.com/apache/iceberg/pull/7447#discussion_r1262870999
########## spark/v3.4/spark/src/test/java/org/apache/iceberg/spark/source/TestSparkReadMetrics.java: ########## @@ -0,0 +1,58 @@ +/* + * 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.iceberg.spark.source; + +import static scala.collection.JavaConverters.seqAsJavaListConverter; + +import java.util.List; +import java.util.Map; +import org.apache.iceberg.spark.SparkTestBaseWithCatalog; +import org.apache.spark.sql.Dataset; +import org.apache.spark.sql.Row; +import org.apache.spark.sql.catalyst.analysis.NoSuchTableException; +import org.apache.spark.sql.execution.SparkPlan; +import org.apache.spark.sql.execution.metric.SQLMetric; +import org.junit.After; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import scala.collection.JavaConverters; + +public class TestSparkReadMetrics extends SparkTestBaseWithCatalog { Review Comment: Added test for v1 and v2 tables. Metatdata tables(apart from [positional deletes table](https://github.com/apache/iceberg/blob/master/core/src/main/java/org/apache/iceberg/PositionDeletesTable.java#L187)) , dont update `org.apache.iceberg.SnapshotScan#scanMetrics`. Since we dont have delete manifest metric in this PR, skipping the test for positional delete metadata table. ########## spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/source/metrics/TaskScannedDataManifests.java: ########## @@ -0,0 +1,47 @@ +/* + * 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.iceberg.spark.source.metrics; + +import org.apache.iceberg.metrics.CounterResult; +import org.apache.iceberg.metrics.ScanReport; +import org.apache.spark.sql.connector.metric.CustomTaskMetric; + +public class TaskScannedDataManifests implements CustomTaskMetric { + private final long value; + + public TaskScannedDataManifests(long value) { + this.value = value; + } + + @Override + public String name() { + return ScannedDataManifests.NAME; + } + + @Override + public long value() { + return value; + } + + public static TaskScannedDataManifests from(ScanReport scanReport) { + CounterResult counter = scanReport.scanMetrics().scannedDataManifests(); + long value = counter != null ? counter.value() : -1; Review Comment: I dont see any CustomTaskMetricImpl in Spark handling no data. Should we send 0 here (I think ["N/A"](https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/ui/SQLAppStatusListener.scala#L230) might not be a good idea and might convey that this data scan manifest was not releveant, WDYT) ########## spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java: ########## @@ -170,8 +189,35 @@ public String description() { table(), branch(), Spark3Util.describe(filterExpressions), groupingKeyFieldNamesAsString); } + @Override + public CustomTaskMetric[] reportDriverMetrics() { + ScanReport scanReport = metricsReportSupplier != null ? metricsReportSupplier.get() : null; + if (scanReport == null) { + return new CustomTaskMetric[0]; + } + + List<CustomTaskMetric> driverMetrics = Lists.newArrayList(); + driverMetrics.add(TaskTotalFileSize.from(scanReport)); Review Comment: I had added all metrics from ScanMetricsResult at the point in time when the change was done, Should we add the remaining now or take in a different PR(since this cange is already reviewed almost)? ########## spark/v3.4/spark/src/test/java/org/apache/iceberg/spark/source/TestSparkReadMetrics.java: ########## @@ -0,0 +1,58 @@ +/* + * 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.iceberg.spark.source; + +import static scala.collection.JavaConverters.seqAsJavaListConverter; + +import java.util.List; +import java.util.Map; +import org.apache.iceberg.spark.SparkTestBaseWithCatalog; +import org.apache.spark.sql.Dataset; +import org.apache.spark.sql.Row; +import org.apache.spark.sql.catalyst.analysis.NoSuchTableException; +import org.apache.spark.sql.execution.SparkPlan; +import org.apache.spark.sql.execution.metric.SQLMetric; +import org.junit.After; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import scala.collection.JavaConverters; + +public class TestSparkReadMetrics extends SparkTestBaseWithCatalog { + + @After + public void removeTables() { + sql("DROP TABLE IF EXISTS %s", tableName); + } + + @Test + public void testReadMetrics() throws NoSuchTableException { + sql("CREATE TABLE %s (id BIGINT) USING iceberg", tableName); + + spark.range(10000).coalesce(1).writeTo(tableName).append(); + + Dataset<Row> df = spark.sql(String.format("select * from %s", tableName)); + df.collect(); + + List<SparkPlan> sparkPlans = + seqAsJavaListConverter(df.queryExecution().executedPlan().collectLeaves()).asJava(); + Map<String, SQLMetric> metricsMap = + JavaConverters.mapAsJavaMapConverter(sparkPlans.get(0).metrics()).asJava(); + Assertions.assertEquals(1, metricsMap.get("scannedDataManifests").value()); Review Comment: Changed it to use `org.assertj.core.api.Assertions` Added more checks ########## spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/source/SparkScan.java: ########## @@ -170,8 +189,35 @@ public String description() { table(), branch(), Spark3Util.describe(filterExpressions), groupingKeyFieldNamesAsString); } + @Override + public CustomTaskMetric[] reportDriverMetrics() { + ScanReport scanReport = metricsReportSupplier != null ? metricsReportSupplier.get() : null; + if (scanReport == null) { Review Comment: I made it ``` public ScanReport scanReport() { Preconditions.checkArgument( metricsReport == null || metricsReport instanceof ScanReport, "Metric report is not a scan report"); return (ScanReport) metricsReport; } ``` -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
