-
Notifications
You must be signed in to change notification settings - Fork 3k
Spark: Add custom metric for number of file splits read by a SparkScan #4395
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 all commits
c547869
b0ebc47
dd5f50a
43d9e1e
0cf77ca
30767e2
2faea77
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,45 @@ | ||
| /* | ||
| * 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 java.text.NumberFormat; | ||
| import org.apache.spark.sql.connector.metric.CustomMetric; | ||
|
|
||
| public class NumSplits implements CustomMetric { | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return "numSplits"; | ||
| } | ||
|
|
||
| @Override | ||
| public String description() { | ||
| return "number of file splits read"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Start with a Capital leter
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I explained in #4588 that I lowercase "number" to be consistent with the standard metrics shown in the Spark UI. |
||
| } | ||
|
|
||
| @Override | ||
| public String aggregateTaskMetrics(long[] taskMetrics) { | ||
| long sum = initialValue; | ||
| for (int i = 0; i < taskMetrics.length; i++) { | ||
| sum += taskMetrics[i]; | ||
| } | ||
| return NumberFormat.getIntegerInstance().format(sum); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * 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.spark.sql.connector.metric.CustomTaskMetric; | ||
|
|
||
| public class TaskNumSplits implements CustomTaskMetric { | ||
| private final long value; | ||
|
|
||
| public TaskNumSplits(long value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return "numSplits"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we say numFileSplits? I'm always worried about how overloaded the term "split" is especially in Spark. I believe you used this in the debug statement above.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This name is internal. The name in the I had previously changed the numFiles/NumFiles in names to numSplits/NumSplits at your suggestion. Do you really think it is necessary to change all those names again? |
||
| } | ||
|
|
||
| @Override | ||
| public long value() { | ||
| return value; | ||
| } | ||
| } | ||
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.
CustomSumMetric fits this a bit better and you will not need to reimplement the Aggregate
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 explained in #4588 why there is no benefit to extend
CustomSumMetric.