iceberg-cpp
Loading...
Searching...
No Matches
metrics_reporter.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <string>
26#include <string_view>
27#include <unordered_map>
28#include <utility>
29#include <variant>
30
34#include "iceberg/result.h"
35
36namespace iceberg {
37
40 kScanReport,
41 kCommitReport,
42};
43
45ICEBERG_EXPORT constexpr std::string_view ToString(MetricsReportType type) noexcept {
46 switch (type) {
47 case MetricsReportType::kScanReport:
48 return "scan";
49 case MetricsReportType::kCommitReport:
50 return "commit";
51 }
52 std::unreachable();
53}
54
59using MetricsReport = std::variant<ScanReport, CommitReport>;
60
65ICEBERG_EXPORT inline MetricsReportType GetReportType(const MetricsReport& report) {
66 return std::visit(
67 [](const auto& r) -> MetricsReportType {
68 using T = std::decay_t<decltype(r)>;
69 if constexpr (std::is_same_v<T, ScanReport>) {
70 return MetricsReportType::kScanReport;
71 } else {
72 return MetricsReportType::kCommitReport;
73 }
74 },
75 report);
76}
77
85class ICEBERG_EXPORT MetricsReporter {
86 public:
87 virtual ~MetricsReporter() = default;
88
94 virtual Status Initialize(
95 [[maybe_unused]] const std::unordered_map<std::string, std::string>& properties) {
96 return {};
97 }
98
105 virtual Status Report(const MetricsReport& report) = 0;
106};
107
108} // namespace iceberg
Interface for reporting metrics from Iceberg operations.
Definition metrics_reporter.h:85
virtual Status Initialize(const std::unordered_map< std::string, std::string > &properties)
Initialize the reporter with catalog properties after construction.
Definition metrics_reporter.h:94
virtual Status Report(const MetricsReport &report)=0
Report a metrics report.
Define commit metrics and reports.
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
ICEBERG_EXPORT std::string_view ToString(Expression::Operation op)
Returns a string representation of an expression operation.
MetricsReportType
The type of a metrics report.
Definition metrics_reporter.h:39
std::variant< ScanReport, CommitReport > MetricsReport
A metrics report, which can be either a ScanReport or CommitReport.
Definition metrics_reporter.h:59
ICEBERG_EXPORT MetricsReportType GetReportType(const MetricsReport &report)
Get the type of a metrics report.
Definition metrics_reporter.h:65
Define Result, Status, and error helpers.
Define scan metrics and reports.