This is an automated email from the ASF dual-hosted git repository.

fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new 5f41a7e  refactor: unify enum string conversion (#248)
5f41a7e is described below

commit 5f41a7ed359119830ba044b4a68fa286dc84e01f
Author: Li Feiyang <[email protected]>
AuthorDate: Mon Sep 29 23:13:39 2025 +0800

    refactor: unify enum string conversion (#248)
---
 src/iceberg/json_internal.cc | 7 +++----
 src/iceberg/snapshot.h       | 3 +--
 src/iceberg/sort_field.cc    | 2 +-
 src/iceberg/sort_field.h     | 4 ++--
 4 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/iceberg/json_internal.cc b/src/iceberg/json_internal.cc
index ad470a2..64ec9aa 100644
--- a/src/iceberg/json_internal.cc
+++ b/src/iceberg/json_internal.cc
@@ -23,7 +23,6 @@
 #include <cstdint>
 #include <format>
 #include <regex>
-#include <type_traits>
 #include <unordered_set>
 #include <utility>
 
@@ -351,8 +350,8 @@ nlohmann::json ToJson(const SortField& sort_field) {
   nlohmann::json json;
   json[kTransform] = std::format("{}", *sort_field.transform());
   json[kSourceId] = sort_field.source_id();
-  json[kDirection] = SortDirectionToString(sort_field.direction());
-  json[kNullOrder] = NullOrderToString(sort_field.null_order());
+  json[kDirection] = std::format("{}", sort_field.direction());
+  json[kNullOrder] = std::format("{}", sort_field.null_order());
   return json;
 }
 
@@ -491,7 +490,7 @@ nlohmann::json ToJson(const Schema& schema) {
 nlohmann::json ToJson(const SnapshotRef& ref) {
   nlohmann::json json;
   json[kSnapshotId] = ref.snapshot_id;
-  json[kType] = SnapshotRefTypeToString(ref.type());
+  json[kType] = std::format("{}", ref.type());
   if (ref.type() == SnapshotRefType::kBranch) {
     const auto& branch = std::get<SnapshotRef::Branch>(ref.retention);
     SetOptionalField(json, kMinSnapshotsToKeep, branch.min_snapshots_to_keep);
diff --git a/src/iceberg/snapshot.h b/src/iceberg/snapshot.h
index 579c67e..d41795d 100644
--- a/src/iceberg/snapshot.h
+++ b/src/iceberg/snapshot.h
@@ -43,8 +43,7 @@ enum class SnapshotRefType {
 };
 
 /// \brief Get the relative snapshot reference type name
-ICEBERG_EXPORT constexpr std::string_view SnapshotRefTypeToString(
-    SnapshotRefType type) noexcept {
+ICEBERG_EXPORT constexpr std::string_view ToString(SnapshotRefType type) 
noexcept {
   switch (type) {
     case SnapshotRefType::kBranch:
       return "branch";
diff --git a/src/iceberg/sort_field.cc b/src/iceberg/sort_field.cc
index e121826..e9b3bf7 100644
--- a/src/iceberg/sort_field.cc
+++ b/src/iceberg/sort_field.cc
@@ -44,7 +44,7 @@ NullOrder SortField::null_order() const { return null_order_; 
}
 std::string SortField::ToString() const {
   return std::format(
       "sort_field(source_id={}, transform={}, direction={}, null_order={})", 
source_id_,
-      *transform_, SortDirectionToString(direction_), 
NullOrderToString(null_order_));
+      *transform_, direction_, null_order_);
 }
 
 bool SortField::Equals(const SortField& other) const {
diff --git a/src/iceberg/sort_field.h b/src/iceberg/sort_field.h
index f255033..459472c 100644
--- a/src/iceberg/sort_field.h
+++ b/src/iceberg/sort_field.h
@@ -42,7 +42,7 @@ enum class SortDirection {
   kDescending,
 };
 /// \brief Get the relative sort direction name
-ICEBERG_EXPORT constexpr std::string_view SortDirectionToString(SortDirection 
direction) {
+ICEBERG_EXPORT constexpr std::string_view ToString(SortDirection direction) {
   switch (direction) {
     case SortDirection::kAscending:
       return "asc";
@@ -67,7 +67,7 @@ enum class NullOrder {
   kLast,
 };
 /// \brief Get the relative null order name
-ICEBERG_EXPORT constexpr std::string_view NullOrderToString(NullOrder 
null_order) {
+ICEBERG_EXPORT constexpr std::string_view ToString(NullOrder null_order) {
   switch (null_order) {
     case NullOrder::kFirst:
       return "nulls-first";

Reply via email to