-
Notifications
You must be signed in to change notification settings - Fork 5.5k
RuntimeStatsMetric Reporter for table scans in Iceberg Connector #24904
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
base: master
Are you sure you want to change the base?
Changes from all commits
3bd3c8e
afe94e5
f46a0e5
e01409f
d3b78a6
e416ff6
0831294
e5c733f
b66ff2a
27fc795
0a4b2b8
1625a0f
2254777
d944e2f
0bea095
7bcdc29
6bc1e84
84c3cf8
f4eecbd
9c23516
9ef6b65
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,183 @@ | ||
/* | ||
* Licensed 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 com.facebook.presto.iceberg; | ||
|
||
import com.facebook.presto.common.RuntimeStats; | ||
import com.facebook.presto.common.RuntimeUnit; | ||
import org.apache.iceberg.metrics.MetricsReport; | ||
import org.apache.iceberg.metrics.MetricsReporter; | ||
import org.apache.iceberg.metrics.ScanReport; | ||
|
||
/** | ||
* A MetricsReporter implementation for reporting | ||
* Iceberg scan metrics to Presto's RuntimeStats. | ||
*/ | ||
|
||
public final class RuntimeStatsMetricsReporter | ||
implements MetricsReporter | ||
{ | ||
/** | ||
* RuntimeStats variable used for storing scan metrics from Iceberg reports. | ||
*/ | ||
private final RuntimeStats runtimeStats; | ||
|
||
/** | ||
* Constructs a RuntimeStatsMetricsReporter. | ||
* | ||
* @param runtimeStat the RuntimeStats instance to report metrics to | ||
*/ | ||
public RuntimeStatsMetricsReporter(final RuntimeStats runtimeStat) | ||
{ | ||
this.runtimeStats = runtimeStat; | ||
} | ||
|
||
/** | ||
* Helper method to construct the full metric name for a table scan. | ||
* | ||
* @param tableName the name of the table | ||
* @param metricName the name of the metric | ||
* @return the composed metric name in the format: table.scan.metric | ||
*/ | ||
private String tableScanString(final String tableName, final String metricName) | ||
{ | ||
return tableName + ".scan." + metricName; | ||
} | ||
Comment on lines
+45
to
+55
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. nit: move this private method to the bottom, and it can be declared static. |
||
|
||
@Override | ||
public void report(final MetricsReport report) | ||
{ | ||
if (!(report instanceof ScanReport)) { | ||
return; | ||
} | ||
|
||
ScanReport scanReport = (ScanReport) report; | ||
String tableName = scanReport.tableName(); | ||
|
||
if (scanReport.scanMetrics().totalPlanningDuration() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "totalPlanningDuration"), | ||
RuntimeUnit.NANO, | ||
scanReport.scanMetrics().totalPlanningDuration() | ||
.totalDuration().toNanos()); | ||
} | ||
|
||
if (scanReport.scanMetrics().resultDataFiles() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "resultDataFiles"), | ||
RuntimeUnit.NONE, | ||
scanReport.scanMetrics().resultDataFiles().value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().resultDeleteFiles() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "resultDeleteFiles"), | ||
RuntimeUnit.NONE, | ||
scanReport.scanMetrics().resultDeleteFiles().value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().totalDataManifests() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "totalDataManifests"), | ||
RuntimeUnit.NONE, | ||
scanReport.scanMetrics().totalDataManifests().value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().totalDeleteManifests() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "totalDeleteManifests"), | ||
RuntimeUnit.NONE, | ||
scanReport.scanMetrics().totalDeleteManifests().value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().scannedDataManifests() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "scannedDataManifests"), | ||
RuntimeUnit.NONE, | ||
scanReport.scanMetrics().scannedDataManifests().value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().skippedDataManifests() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "skippedDataManifests"), | ||
RuntimeUnit.NONE, | ||
scanReport.scanMetrics().skippedDataManifests().value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().totalFileSizeInBytes() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "totalFileSizeInBytes"), | ||
RuntimeUnit.BYTE, | ||
scanReport.scanMetrics().totalFileSizeInBytes() | ||
.value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().totalDeleteFileSizeInBytes() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "totalDeleteFileSizeInBytes"), | ||
RuntimeUnit.BYTE, | ||
scanReport.scanMetrics().totalDeleteFileSizeInBytes() | ||
.value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().skippedDataFiles() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "skippedDataFiles"), | ||
RuntimeUnit.NONE, | ||
scanReport.scanMetrics().skippedDataFiles() | ||
.value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().skippedDeleteFiles() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "skippedDeleteFiles"), | ||
RuntimeUnit.NONE, | ||
scanReport.scanMetrics().skippedDeleteFiles().value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().scannedDeleteManifests() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "scannedDeleteManifests"), | ||
RuntimeUnit.NONE, | ||
scanReport.scanMetrics().scannedDeleteManifests().value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().skippedDeleteManifests() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "skippedDeleteManifests"), | ||
RuntimeUnit.NONE, | ||
scanReport.scanMetrics().skippedDeleteManifests().value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().indexedDeleteFiles() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "indexedDeleteFiles"), | ||
RuntimeUnit.NONE, | ||
scanReport.scanMetrics().indexedDeleteFiles().value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().equalityDeleteFiles() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "equalityDeleteFiles"), | ||
RuntimeUnit.NONE, | ||
scanReport.scanMetrics().equalityDeleteFiles().value()); | ||
} | ||
|
||
if (scanReport.scanMetrics().positionalDeleteFiles() != null) { | ||
runtimeStats.addMetricValue( | ||
tableScanString(tableName, "positionalDeleteFiles"), | ||
RuntimeUnit.NONE, | ||
scanReport.scanMetrics().positionalDeleteFiles().value()); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,14 +168,15 @@ public static TableStatistics getTableStatistics( | |
Table icebergTable, | ||
List<IcebergColumnHandle> columns) | ||
{ | ||
return new TableStatisticsMaker(icebergTable, session, typeManager).makeTableStatistics(statisticsFileCache, tableHandle, currentPredicate, constraint, columns); | ||
return new TableStatisticsMaker(icebergTable, session, typeManager).makeTableStatistics(statisticsFileCache, tableHandle, currentPredicate, constraint, columns, session); | ||
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. nit: newly added parameter |
||
} | ||
|
||
private TableStatistics makeTableStatistics(StatisticsFileCache statisticsFileCache, | ||
IcebergTableHandle tableHandle, | ||
Optional<TupleDomain<IcebergColumnHandle>> currentPredicate, | ||
Constraint constraint, | ||
List<IcebergColumnHandle> selectedColumns) | ||
List<IcebergColumnHandle> selectedColumns, | ||
ConnectorSession session) | ||
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. nit: newly added parameter |
||
{ | ||
if (!tableHandle.getIcebergTableName().getSnapshotId().isPresent() || constraint.getSummary().isNone()) { | ||
return TableStatistics.builder() | ||
|
@@ -282,6 +283,7 @@ private Partition getDataTableSummary(IcebergTableHandle tableHandle, | |
List<PartitionField> partitionFields) | ||
{ | ||
TableScan tableScan = icebergTable.newScan() | ||
.metricsReporter(new RuntimeStatsMetricsReporter(session.getRuntimeStats())) | ||
.filter(toIcebergExpression(intersection)) | ||
.select(selectedColumns.stream().map(IcebergColumnHandle::getName).collect(Collectors.toList())) | ||
.useSnapshot(tableHandle.getIcebergTableName().getSnapshotId().get()) | ||
|
@@ -301,7 +303,8 @@ private Partition getEqualityDeleteTableSummary(IcebergTableHandle tableHandle, | |
tableHandle.getIcebergTableName().getSnapshotId().get(), | ||
intersection, | ||
tableHandle.getPartitionSpecId(), | ||
tableHandle.getEqualityFieldIds()); | ||
tableHandle.getEqualityFieldIds(), | ||
session.getRuntimeStats()); | ||
CloseableIterable<ContentFile<?>> files = CloseableIterable.transform(deleteFiles, deleteFile -> deleteFile); | ||
return getSummaryFromFiles(files, idToTypeMapping, nonPartitionPrimitiveColumns, partitionFields); | ||
} | ||
|
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.
Couldn't comment above, so commenting here. Should we also register metrics reporter for CHANGELOG table scan?