obelix74 commented on code in PR #4115:
URL: https://github.com/apache/polaris/pull/4115#discussion_r3251983154
##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/metrics/MetricsPersistence.java:
##########
@@ -73,4 +77,56 @@ default void writeScanReport(@Nonnull ScanMetricsRecord
record) {
default void writeCommitReport(@Nonnull CommitMetricsRecord record) {
// No-op by default - backends that don't support metrics silently ignore
}
+
+ /**
+ * Lists scan metrics reports for a given table, ordered by timestamp
descending.
+ *
+ * <p>Default implementation returns an empty page. Override in
implementations that support
+ * metrics reads.
+ *
+ * @param catalogId the internal catalog ID
+ * @param tableId the internal table entity ID
+ * @param snapshotId optional filter by snapshot ID
+ * @param principalName optional filter by principal name
+ * @param timestampFrom optional inclusive lower bound on timestamp (epoch
ms)
+ * @param timestampTo optional exclusive upper bound on timestamp (epoch ms)
+ * @param pageToken pagination token
+ * @return a page of scan metrics records
+ */
+ default Page<ScanMetricsRecord> listScanReports(
Review Comment:
The migration of metrics methods off `BasePersistence` is being driven by
#4397, and I plan to rebase this PR on top of that work once it lands. The sync
agreed that `MetricsPersistence` becomes its own top-level SPI — so the owner
of that migration is effectively #4397. I'll track the rebase here and make
sure the `listScanReports`/`listCommitReports` methods move to the disjoint
`MetricsPersistence` SPI rather than staying on the aggregated
`BasePersistence`.
##########
persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImpl.java:
##########
@@ -1336,4 +1337,141 @@ private void writeCommitMetricsReport(@Nonnull
ModelCommitMetricsReport report)
String.format("Failed to write commit metrics report due to %s",
e.getMessage()), e);
}
}
+
+ @Override
+ public Page<ScanMetricsRecord> listScanReports(
+ long catalogId,
+ long tableId,
+ @Nullable Long snapshotId,
+ @Nullable String principalName,
+ @Nullable Long timestampFrom,
+ @Nullable Long timestampTo,
+ @Nonnull PageToken pageToken) {
+ try {
+ PreparedQuery query =
+ buildMetricsQuery(
+ ModelScanMetricsReport.TABLE_NAME,
+ catalogId,
+ tableId,
+ snapshotId,
+ principalName,
+ timestampFrom,
+ timestampTo,
+ pageToken);
+ List<ModelScanMetricsReport> rows =
+ datasourceOperations.executeSelect(query,
ModelScanMetricsReport.CONVERTER);
+ return Page.mapped(
+ pageToken,
+ rows.stream().map(ModelScanMetricsReport::toRecord),
+ Function.identity(),
+ MetricsReportToken::fromRecord);
+ } catch (SQLException e) {
+ throw new RuntimeException(
+ String.format("Failed to list scan metrics reports: %s",
e.getMessage()), e);
+ }
+ }
+
+ @Override
+ public Page<CommitMetricsRecord> listCommitReports(
+ long catalogId,
+ long tableId,
+ @Nullable Long snapshotId,
+ @Nullable String principalName,
+ @Nullable Long timestampFrom,
+ @Nullable Long timestampTo,
+ @Nonnull PageToken pageToken) {
+ try {
+ PreparedQuery query =
+ buildMetricsQuery(
+ ModelCommitMetricsReport.TABLE_NAME,
+ catalogId,
+ tableId,
+ snapshotId,
+ principalName,
+ timestampFrom,
+ timestampTo,
+ pageToken);
+ List<ModelCommitMetricsReport> rows =
+ datasourceOperations.executeSelect(query,
ModelCommitMetricsReport.CONVERTER);
+ return Page.mapped(
+ pageToken,
+ rows.stream().map(ModelCommitMetricsReport::toRecord),
+ Function.identity(),
+ MetricsReportToken::fromRecord);
+ } catch (SQLException e) {
+ throw new RuntimeException(
+ String.format("Failed to list commit metrics reports: %s",
e.getMessage()), e);
+ }
+ }
+
+ /**
+ * Builds a parameterized SELECT query for a metrics report table using
keyset pagination.
+ *
+ * <p>Rows are ordered by {@code (timestamp_ms DESC, report_id DESC)}. The
cursor from {@link
+ * MetricsReportToken} drives the keyset predicate: {@code (timestamp_ms <
cursorTs) OR
+ * (timestamp_ms = cursorTs AND report_id < cursorId)}.
+ */
+ private PreparedQuery buildMetricsQuery(
Review Comment:
Exactly — the `tableName` param in `buildMetricsQuery` is intentionally
forward-compatible. When we consolidate to a single table, the only changes
needed in this method are: replace the `tableName` param with a constant, and
add a `WHERE metric_type = ?` clause. The rest of the filter/pagination/keyset
logic stays identical. My intent is to keep the read API shape stable across
that migration — the response records (`ScanMetricsReport`,
`CommitMetricsReport`) won't change, only the internal query routing will.
--
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]