Skip to content

Commit 4bf8af6

Browse files
committed
refactor: unify enum string conversion
1 parent 1cea1e9 commit 4bf8af6

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

src/iceberg/json_internal.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <cstdint>
2424
#include <format>
2525
#include <regex>
26-
#include <type_traits>
2726
#include <unordered_set>
2827
#include <utility>
2928

@@ -351,8 +350,8 @@ nlohmann::json ToJson(const SortField& sort_field) {
351350
nlohmann::json json;
352351
json[kTransform] = std::format("{}", *sort_field.transform());
353352
json[kSourceId] = sort_field.source_id();
354-
json[kDirection] = SortDirectionToString(sort_field.direction());
355-
json[kNullOrder] = NullOrderToString(sort_field.null_order());
353+
json[kDirection] = std::format("{}", sort_field.direction());
354+
json[kNullOrder] = std::format("{}", sort_field.null_order());
356355
return json;
357356
}
358357

@@ -491,7 +490,7 @@ nlohmann::json ToJson(const Schema& schema) {
491490
nlohmann::json ToJson(const SnapshotRef& ref) {
492491
nlohmann::json json;
493492
json[kSnapshotId] = ref.snapshot_id;
494-
json[kType] = SnapshotRefTypeToString(ref.type());
493+
json[kType] = std::format("{}", ref.type());
495494
if (ref.type() == SnapshotRefType::kBranch) {
496495
const auto& branch = std::get<SnapshotRef::Branch>(ref.retention);
497496
SetOptionalField(json, kMinSnapshotsToKeep, branch.min_snapshots_to_keep);

src/iceberg/snapshot.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ enum class SnapshotRefType {
4343
};
4444

4545
/// \brief Get the relative snapshot reference type name
46-
ICEBERG_EXPORT constexpr std::string_view SnapshotRefTypeToString(
47-
SnapshotRefType type) noexcept {
46+
ICEBERG_EXPORT constexpr std::string_view ToString(SnapshotRefType type) noexcept {
4847
switch (type) {
4948
case SnapshotRefType::kBranch:
5049
return "branch";

src/iceberg/sort_field.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ NullOrder SortField::null_order() const { return null_order_; }
4444
std::string SortField::ToString() const {
4545
return std::format(
4646
"sort_field(source_id={}, transform={}, direction={}, null_order={})", source_id_,
47-
*transform_, SortDirectionToString(direction_), NullOrderToString(null_order_));
47+
*transform_, direction_, null_order_);
4848
}
4949

5050
bool SortField::Equals(const SortField& other) const {

src/iceberg/sort_field.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ enum class SortDirection {
4242
kDescending,
4343
};
4444
/// \brief Get the relative sort direction name
45-
ICEBERG_EXPORT constexpr std::string_view SortDirectionToString(SortDirection direction) {
45+
ICEBERG_EXPORT constexpr std::string_view ToString(SortDirection direction) {
4646
switch (direction) {
4747
case SortDirection::kAscending:
4848
return "asc";
@@ -67,7 +67,7 @@ enum class NullOrder {
6767
kLast,
6868
};
6969
/// \brief Get the relative null order name
70-
ICEBERG_EXPORT constexpr std::string_view NullOrderToString(NullOrder null_order) {
70+
ICEBERG_EXPORT constexpr std::string_view ToString(NullOrder null_order) {
7171
switch (null_order) {
7272
case NullOrder::kFirst:
7373
return "nulls-first";

0 commit comments

Comments
 (0)