This is an automated email from the ASF dual-hosted git repository.
xuanwo 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 0fc2a67 refactor: consolidate result type (#67)
0fc2a67 is described below
commit 0fc2a6748299575808cb0348b29e01d9c7ade2e3
Author: Guotao Yu <[email protected]>
AuthorDate: Fri Apr 11 10:44:21 2025 +0800
refactor: consolidate result type (#67)
---
src/iceberg/arrow/arrow_error_transform_internal.h | 2 +-
src/iceberg/arrow/arrow_fs_file_io.cc | 11 ++++----
src/iceberg/arrow/arrow_fs_file_io.h | 9 +++----
src/iceberg/catalog.h | 29 +++++++++++-----------
src/iceberg/file_io.h | 12 ++++-----
src/iceberg/json_internal.cc | 22 ++++++++--------
src/iceberg/json_internal.h | 12 ++++-----
src/iceberg/{error.h => result.h} | 13 ++++++++++
src/iceberg/schema_internal.cc | 10 ++++----
src/iceberg/schema_internal.h | 8 +++---
src/iceberg/sort_field.h | 7 +++---
src/iceberg/table.h | 20 +++++++--------
src/iceberg/transform.h | 2 +-
test/matchers.h | 2 +-
14 files changed, 82 insertions(+), 77 deletions(-)
diff --git a/src/iceberg/arrow/arrow_error_transform_internal.h
b/src/iceberg/arrow/arrow_error_transform_internal.h
index 588bab5..73255c0 100644
--- a/src/iceberg/arrow/arrow_error_transform_internal.h
+++ b/src/iceberg/arrow/arrow_error_transform_internal.h
@@ -22,8 +22,8 @@
#include <arrow/result.h>
#include <arrow/status.h>
-#include "iceberg/error.h"
#include "iceberg/expected.h"
+#include "iceberg/result.h"
namespace iceberg::arrow {
diff --git a/src/iceberg/arrow/arrow_fs_file_io.cc
b/src/iceberg/arrow/arrow_fs_file_io.cc
index 270ecb7..5352309 100644
--- a/src/iceberg/arrow/arrow_fs_file_io.cc
+++ b/src/iceberg/arrow/arrow_fs_file_io.cc
@@ -26,8 +26,8 @@
namespace iceberg::arrow {
/// \brief Read the content of the file at the given location.
-expected<std::string, Error> ArrowFileSystemFileIO::ReadFile(
- const std::string& file_location, std::optional<size_t> length) {
+Result<std::string> ArrowFileSystemFileIO::ReadFile(const std::string&
file_location,
+ std::optional<size_t>
length) {
::arrow::fs::FileInfo file_info(file_location);
if (length.has_value()) {
file_info.set_size(length.value());
@@ -52,8 +52,8 @@ expected<std::string, Error> ArrowFileSystemFileIO::ReadFile(
}
/// \brief Write the given content to the file at the given location.
-expected<void, Error> ArrowFileSystemFileIO::WriteFile(const std::string&
file_location,
- std::string_view
content) {
+Status ArrowFileSystemFileIO::WriteFile(const std::string& file_location,
+ std::string_view content) {
ICEBERG_ARROW_ASSIGN_OR_RETURN(auto file,
arrow_fs_->OpenOutputStream(file_location));
ICEBERG_ARROW_RETURN_NOT_OK(file->Write(content.data(), content.size()));
ICEBERG_ARROW_RETURN_NOT_OK(file->Flush());
@@ -62,8 +62,7 @@ expected<void, Error> ArrowFileSystemFileIO::WriteFile(const
std::string& file_l
}
/// \brief Delete a file at the given location.
-expected<void, Error> ArrowFileSystemFileIO::DeleteFile(
- const std::string& file_location) {
+Status ArrowFileSystemFileIO::DeleteFile(const std::string& file_location) {
ICEBERG_ARROW_RETURN_NOT_OK(arrow_fs_->DeleteFile(file_location));
return {};
}
diff --git a/src/iceberg/arrow/arrow_fs_file_io.h
b/src/iceberg/arrow/arrow_fs_file_io.h
index e79e75f..b55af5d 100644
--- a/src/iceberg/arrow/arrow_fs_file_io.h
+++ b/src/iceberg/arrow/arrow_fs_file_io.h
@@ -37,15 +37,14 @@ class ICEBERG_BUNDLE_EXPORT ArrowFileSystemFileIO : public
FileIO {
~ArrowFileSystemFileIO() override = default;
/// \brief Read the content of the file at the given location.
- expected<std::string, Error> ReadFile(const std::string& file_location,
- std::optional<size_t> length) override;
+ Result<std::string> ReadFile(const std::string& file_location,
+ std::optional<size_t> length) override;
/// \brief Write the given content to the file at the given location.
- expected<void, Error> WriteFile(const std::string& file_location,
- std::string_view content) override;
+ Status WriteFile(const std::string& file_location, std::string_view content)
override;
/// \brief Delete a file at the given location.
- expected<void, Error> DeleteFile(const std::string& file_location) override;
+ Status DeleteFile(const std::string& file_location) override;
private:
std::shared_ptr<::arrow::fs::FileSystem> arrow_fs_;
diff --git a/src/iceberg/catalog.h b/src/iceberg/catalog.h
index 8ab51dd..121b0da 100644
--- a/src/iceberg/catalog.h
+++ b/src/iceberg/catalog.h
@@ -19,14 +19,13 @@
#pragma once
-#include <map>
#include <memory>
#include <string>
#include <string_view>
+#include <unordered_map>
#include <vector>
-#include "iceberg/error.h"
-#include "iceberg/expected.h"
+#include "iceberg/result.h"
#include "iceberg/table_identifier.h"
#include "iceberg/type_fwd.h"
@@ -48,8 +47,7 @@ class ICEBERG_EXPORT Catalog {
/// \param ns a namespace
/// \return a list of identifiers for tables or ErrorKind::kNoSuchNamespace
/// if the namespace does not exist
- virtual expected<std::vector<TableIdentifier>, Error> ListTables(
- const Namespace& ns) const = 0;
+ virtual Result<std::vector<TableIdentifier>> ListTables(const Namespace& ns)
const = 0;
/// \brief Create a table
///
@@ -59,10 +57,10 @@ class ICEBERG_EXPORT Catalog {
/// \param location a location for the table; leave empty if unspecified
/// \param properties a string map of table properties
/// \return a Table instance or ErrorKind::kAlreadyExists if the table
already exists
- virtual expected<std::unique_ptr<Table>, Error> CreateTable(
+ virtual Result<std::unique_ptr<Table>> CreateTable(
const TableIdentifier& identifier, const Schema& schema, const
PartitionSpec& spec,
const std::string& location,
- const std::map<std::string, std::string>& properties) = 0;
+ const std::unordered_map<std::string, std::string>& properties) = 0;
/// \brief Update a table
///
@@ -70,7 +68,7 @@ class ICEBERG_EXPORT Catalog {
/// \param requirements a list of table requirements
/// \param updates a list of table updates
/// \return a Table instance or ErrorKind::kAlreadyExists if the table
already exists
- virtual expected<std::unique_ptr<Table>, Error> UpdateTable(
+ virtual Result<std::unique_ptr<Table>> UpdateTable(
const TableIdentifier& identifier,
const std::vector<std::unique_ptr<UpdateRequirement>>& requirements,
const std::vector<std::unique_ptr<MetadataUpdate>>& updates) = 0;
@@ -84,10 +82,10 @@ class ICEBERG_EXPORT Catalog {
/// \param properties a string map of table properties
/// \return a Transaction to create the table or ErrorKind::kAlreadyExists
if the table
/// already exists
- virtual expected<std::shared_ptr<Transaction>, Error> StageCreateTable(
+ virtual Result<std::shared_ptr<Transaction>> StageCreateTable(
const TableIdentifier& identifier, const Schema& schema, const
PartitionSpec& spec,
const std::string& location,
- const std::map<std::string, std::string>& properties) = 0;
+ const std::unordered_map<std::string, std::string>& properties) = 0;
/// \brief Check whether table exists
///
@@ -110,7 +108,7 @@ class ICEBERG_EXPORT Catalog {
/// \param identifier a table identifier
/// \return instance of Table implementation referred to by identifier or
/// ErrorKind::kNoSuchTable if the table does not exist
- virtual expected<std::shared_ptr<Table>, Error> LoadTable(
+ virtual Result<std::shared_ptr<Table>> LoadTable(
const TableIdentifier& identifier) const = 0;
/// \brief Register a table with the catalog if it does not exist
@@ -118,7 +116,7 @@ class ICEBERG_EXPORT Catalog {
/// \param identifier a table identifier
/// \param metadata_file_location the location of a metadata file
/// \return a Table instance or ErrorKind::kAlreadyExists if the table
already exists
- virtual expected<std::shared_ptr<Table>, Error> RegisterTable(
+ virtual Result<std::shared_ptr<Table>> RegisterTable(
const TableIdentifier& identifier, const std::string&
metadata_file_location) = 0;
/// \brief Initialize a catalog given a custom name and a map of catalog
properties
@@ -129,8 +127,9 @@ class ICEBERG_EXPORT Catalog {
///
/// \param name a custom name for the catalog
/// \param properties catalog properties
- virtual void Initialize(const std::string& name,
- const std::map<std::string, std::string>&
properties) = 0;
+ virtual void Initialize(
+ const std::string& name,
+ const std::unordered_map<std::string, std::string>& properties) = 0;
/// \brief Instantiate a builder to either create a table or start a
create/replace
/// transaction
@@ -169,7 +168,7 @@ class ICEBERG_EXPORT Catalog {
/// \param properties key/value properties
/// \return this for method chaining
virtual TableBuilder& WithProperties(
- const std::map<std::string, std::string>& properties) = 0;
+ const std::unordered_map<std::string, std::string>& properties) = 0;
/// \brief Adds a key/value property to the table
///
diff --git a/src/iceberg/file_io.h b/src/iceberg/file_io.h
index 03922f6..c31d39b 100644
--- a/src/iceberg/file_io.h
+++ b/src/iceberg/file_io.h
@@ -23,9 +23,8 @@
#include <string>
#include <string_view>
-#include "iceberg/error.h"
-#include "iceberg/expected.h"
#include "iceberg/iceberg_export.h"
+#include "iceberg/result.h"
namespace iceberg {
@@ -50,8 +49,8 @@ class ICEBERG_EXPORT FileIO {
/// the length to read, e.g. S3 `GetObject` has a Range parameter.
/// \return The content of the file if the read succeeded, an error code if
the read
/// failed.
- virtual expected<std::string, Error> ReadFile(const std::string&
file_location,
- std::optional<size_t> length) {
+ virtual Result<std::string> ReadFile(const std::string& file_location,
+ std::optional<size_t> length) {
// We provide a default implementation to avoid Windows linker error
LNK2019.
return unexpected<Error>{
{.kind = ErrorKind::kNotImplemented, .message = "ReadFile not
implemented"}};
@@ -64,8 +63,7 @@ class ICEBERG_EXPORT FileIO {
/// \param overwrite If true, overwrite the file if it exists. If false,
fail if the
/// file exists.
/// \return void if the write succeeded, an error code if the write failed.
- virtual expected<void, Error> WriteFile(const std::string& file_location,
- std::string_view content) {
+ virtual Status WriteFile(const std::string& file_location, std::string_view
content) {
return unexpected<Error>{
{.kind = ErrorKind::kNotImplemented, .message = "WriteFile not
implemented"}};
}
@@ -74,7 +72,7 @@ class ICEBERG_EXPORT FileIO {
///
/// \param file_location The location of the file to delete.
/// \return void if the delete succeeded, an error code if the delete failed.
- virtual expected<void, Error> DeleteFile(const std::string& file_location) {
+ virtual Status DeleteFile(const std::string& file_location) {
return unexpected<Error>{
{.kind = ErrorKind::kNotImplemented, .message = "DeleteFile not
implemented"}};
}
diff --git a/src/iceberg/json_internal.cc b/src/iceberg/json_internal.cc
index 6847b3a..5307aa5 100644
--- a/src/iceberg/json_internal.cc
+++ b/src/iceberg/json_internal.cc
@@ -24,8 +24,8 @@
#include <nlohmann/json.hpp>
-#include "iceberg/error.h"
#include "iceberg/expected.h"
+#include "iceberg/result.h"
#include "iceberg/schema.h"
#include "iceberg/schema_internal.h"
#include "iceberg/sort_order.h"
@@ -69,7 +69,7 @@ constexpr std::string_view kElementRequired =
"element-required";
constexpr std::string_view kValueRequired = "value-required";
template <typename T>
-expected<T, Error> GetJsonValue(const nlohmann::json& json, std::string_view
key) {
+Result<T> GetJsonValue(const nlohmann::json& json, std::string_view key) {
if (!json.contains(key)) {
return unexpected<Error>({
.kind = ErrorKind::kJsonParseError,
@@ -109,8 +109,7 @@ nlohmann::json ToJson(const SortOrder& sort_order) {
return json;
}
-expected<std::unique_ptr<SortField>, Error> SortFieldFromJson(
- const nlohmann::json& json) {
+Result<std::unique_ptr<SortField>> SortFieldFromJson(const nlohmann::json&
json) {
ICEBERG_ASSIGN_OR_RAISE(auto source_id, GetJsonValue<int32_t>(json,
kSourceId));
ICEBERG_ASSIGN_OR_RAISE(
auto transform,
@@ -125,8 +124,7 @@ expected<std::unique_ptr<SortField>, Error>
SortFieldFromJson(
null_order);
}
-expected<std::unique_ptr<SortOrder>, Error> SortOrderFromJson(
- const nlohmann::json& json) {
+Result<std::unique_ptr<SortOrder>> SortOrderFromJson(const nlohmann::json&
json) {
ICEBERG_ASSIGN_OR_RAISE(auto order_id, GetJsonValue<int32_t>(json,
kOrderId));
ICEBERG_ASSIGN_OR_RAISE(auto fields, GetJsonValue<nlohmann::json>(json,
kFields));
@@ -232,7 +230,7 @@ nlohmann::json SchemaToJson(const Schema& schema) {
namespace {
-expected<std::unique_ptr<Type>, Error> StructTypeFromJson(const
nlohmann::json& json) {
+Result<std::unique_ptr<Type>> StructTypeFromJson(const nlohmann::json& json) {
ICEBERG_ASSIGN_OR_RAISE(auto json_fields, GetJsonValue<nlohmann::json>(json,
kFields));
std::vector<SchemaField> fields;
@@ -244,7 +242,7 @@ expected<std::unique_ptr<Type>, Error>
StructTypeFromJson(const nlohmann::json&
return std::make_unique<StructType>(std::move(fields));
}
-expected<std::unique_ptr<Type>, Error> ListTypeFromJson(const nlohmann::json&
json) {
+Result<std::unique_ptr<Type>> ListTypeFromJson(const nlohmann::json& json) {
ICEBERG_ASSIGN_OR_RAISE(auto element_type, TypeFromJson(json[kElement]));
ICEBERG_ASSIGN_OR_RAISE(auto element_id, GetJsonValue<int32_t>(json,
kElementId));
ICEBERG_ASSIGN_OR_RAISE(auto element_required,
@@ -255,7 +253,7 @@ expected<std::unique_ptr<Type>, Error>
ListTypeFromJson(const nlohmann::json& js
std::move(element_type), !element_required));
}
-expected<std::unique_ptr<Type>, Error> MapTypeFromJson(const nlohmann::json&
json) {
+Result<std::unique_ptr<Type>> MapTypeFromJson(const nlohmann::json& json) {
ICEBERG_ASSIGN_OR_RAISE(
auto key_type, GetJsonValue<nlohmann::json>(json,
kKey).and_then(TypeFromJson));
ICEBERG_ASSIGN_OR_RAISE(
@@ -274,7 +272,7 @@ expected<std::unique_ptr<Type>, Error>
MapTypeFromJson(const nlohmann::json& jso
} // namespace
-expected<std::unique_ptr<Type>, Error> TypeFromJson(const nlohmann::json&
json) {
+Result<std::unique_ptr<Type>> TypeFromJson(const nlohmann::json& json) {
if (json.is_string()) {
std::string type_str = json.get<std::string>();
if (type_str == "boolean") {
@@ -346,7 +344,7 @@ expected<std::unique_ptr<Type>, Error> TypeFromJson(const
nlohmann::json& json)
}
}
-expected<std::unique_ptr<SchemaField>, Error> FieldFromJson(const
nlohmann::json& json) {
+Result<std::unique_ptr<SchemaField>> FieldFromJson(const nlohmann::json& json)
{
ICEBERG_ASSIGN_OR_RAISE(
auto type, GetJsonValue<nlohmann::json>(json,
kType).and_then(TypeFromJson));
ICEBERG_ASSIGN_OR_RAISE(auto field_id, GetJsonValue<int32_t>(json, kId));
@@ -357,7 +355,7 @@ expected<std::unique_ptr<SchemaField>, Error>
FieldFromJson(const nlohmann::json
!required);
}
-expected<std::unique_ptr<Schema>, Error> SchemaFromJson(const nlohmann::json&
json) {
+Result<std::unique_ptr<Schema>> SchemaFromJson(const nlohmann::json& json) {
ICEBERG_ASSIGN_OR_RAISE(auto schema_id, GetJsonValue<int32_t>(json,
kSchemaId));
ICEBERG_ASSIGN_OR_RAISE(auto type, TypeFromJson(json));
diff --git a/src/iceberg/json_internal.h b/src/iceberg/json_internal.h
index c23eec7..5ea4d47 100644
--- a/src/iceberg/json_internal.h
+++ b/src/iceberg/json_internal.h
@@ -24,8 +24,8 @@
#include <nlohmann/json_fwd.hpp>
-#include "iceberg/error.h"
#include "iceberg/expected.h"
+#include "iceberg/result.h"
#include "iceberg/type_fwd.h"
namespace iceberg {
@@ -59,7 +59,7 @@ nlohmann::json ToJson(const SortOrder& sort_order);
/// \param json The JSON object representing a `SortField`.
/// \return An `expected` value containing either a `SortField` object or an
error. If the
/// JSON is malformed or missing expected fields, an error will be returned.
-expected<std::unique_ptr<SortField>, Error> SortFieldFromJson(const
nlohmann::json& json);
+Result<std::unique_ptr<SortField>> SortFieldFromJson(const nlohmann::json&
json);
/// \brief Deserializes a JSON object into a `SortOrder` object.
///
@@ -70,7 +70,7 @@ expected<std::unique_ptr<SortField>, Error>
SortFieldFromJson(const nlohmann::js
/// \param json The JSON object representing a `SortOrder`.
/// \return An `expected` value containing either a `SortOrder` object or an
error. If the
/// JSON is malformed or missing expected fields, an error will be returned.
-expected<std::unique_ptr<SortOrder>, Error> SortOrderFromJson(const
nlohmann::json& json);
+Result<std::unique_ptr<SortOrder>> SortOrderFromJson(const nlohmann::json&
json);
/// \brief Convert an Iceberg Schema to JSON.
///
@@ -94,18 +94,18 @@ nlohmann::json FieldToJson(const SchemaField& field);
///
/// \param[in] json The JSON representation of the schema.
/// \return The Iceberg schema or an error if the conversion fails.
-expected<std::unique_ptr<Schema>, Error> SchemaFromJson(const nlohmann::json&
json);
+Result<std::unique_ptr<Schema>> SchemaFromJson(const nlohmann::json& json);
/// \brief Convert JSON to an Iceberg Type.
///
/// \param[in] json The JSON representation of the type.
/// \return The Iceberg type or an error if the conversion fails.
-expected<std::unique_ptr<Type>, Error> TypeFromJson(const nlohmann::json&
json);
+Result<std::unique_ptr<Type>> TypeFromJson(const nlohmann::json& json);
/// \brief Convert JSON to an Iceberg SchemaField.
///
/// \param[in] json The JSON representation of the field.
/// \return The Iceberg field or an error if the conversion fails.
-expected<std::unique_ptr<SchemaField>, Error> FieldFromJson(const
nlohmann::json& json);
+Result<std::unique_ptr<SchemaField>> FieldFromJson(const nlohmann::json& json);
} // namespace iceberg
diff --git a/src/iceberg/error.h b/src/iceberg/result.h
similarity index 82%
rename from src/iceberg/error.h
rename to src/iceberg/result.h
index a296fcc..7d12f36 100644
--- a/src/iceberg/error.h
+++ b/src/iceberg/result.h
@@ -21,6 +21,7 @@
#include <string>
+#include "iceberg/expected.h"
#include "iceberg/iceberg_export.h"
namespace iceberg {
@@ -47,4 +48,16 @@ struct ICEBERG_EXPORT [[nodiscard]] Error {
std::string message;
};
+/// /brief Default error trait
+template <typename T>
+struct DefaultError {
+ using type = Error;
+};
+
+/// \brief Result alias
+template <typename T, typename E = typename DefaultError<T>::type>
+using Result = expected<T, E>;
+
+using Status = Result<void>;
+
} // namespace iceberg
diff --git a/src/iceberg/schema_internal.cc b/src/iceberg/schema_internal.cc
index 5a9620e..a00c0a1 100644
--- a/src/iceberg/schema_internal.cc
+++ b/src/iceberg/schema_internal.cc
@@ -169,7 +169,7 @@ ArrowErrorCode ToArrowSchema(const Type& type, bool
optional, std::string_view n
} // namespace
-expected<void, Error> ToArrowSchema(const Schema& schema, ArrowSchema* out) {
+Status ToArrowSchema(const Schema& schema, ArrowSchema* out) {
if (out == nullptr) [[unlikely]] {
return unexpected<Error>{{.kind = ErrorKind::kInvalidArgument,
.message = "Output Arrow schema cannot be
null"}};
@@ -206,9 +206,9 @@ int32_t GetFieldId(const ArrowSchema& schema) {
return std::stoi(std::string(field_id_value.data,
field_id_value.size_bytes));
}
-expected<std::shared_ptr<Type>, Error> FromArrowSchema(const ArrowSchema&
schema) {
+Result<std::shared_ptr<Type>> FromArrowSchema(const ArrowSchema& schema) {
auto to_schema_field =
- [](const ArrowSchema& schema) -> expected<std::unique_ptr<SchemaField>,
Error> {
+ [](const ArrowSchema& schema) -> Result<std::unique_ptr<SchemaField>> {
auto field_type_result = FromArrowSchema(schema);
if (!field_type_result) {
return unexpected<Error>(field_type_result.error());
@@ -341,8 +341,8 @@ std::unique_ptr<Schema> FromStructType(StructType&&
struct_type, int32_t schema_
return std::make_unique<Schema>(schema_id, std::move(fields));
}
-expected<std::unique_ptr<Schema>, Error> FromArrowSchema(const ArrowSchema&
schema,
- int32_t schema_id) {
+Result<std::unique_ptr<Schema>> FromArrowSchema(const ArrowSchema& schema,
+ int32_t schema_id) {
auto type_result = FromArrowSchema(schema);
if (!type_result) {
return unexpected<Error>(type_result.error());
diff --git a/src/iceberg/schema_internal.h b/src/iceberg/schema_internal.h
index ab7f1ab..de0283f 100644
--- a/src/iceberg/schema_internal.h
+++ b/src/iceberg/schema_internal.h
@@ -23,8 +23,8 @@
#include <nanoarrow/nanoarrow.h>
-#include "iceberg/error.h"
#include "iceberg/expected.h"
+#include "iceberg/result.h"
#include "iceberg/type_fwd.h"
namespace iceberg {
@@ -39,15 +39,15 @@ constexpr std::string_view kFieldIdKey = "ICEBERG:field_id";
/// \param[in] schema The Iceberg schema to convert.
/// \param[out] out The Arrow schema to convert to.
/// \return An error if the conversion fails.
-expected<void, Error> ToArrowSchema(const Schema& schema, ArrowSchema* out);
+Status ToArrowSchema(const Schema& schema, ArrowSchema* out);
/// \brief Convert an Arrow schema to an Iceberg schema.
///
/// \param[in] schema The Arrow schema to convert.
/// \param[in] schema_id The schema ID of the Iceberg schema.
/// \return The Iceberg schema or an error if the conversion fails.
-expected<std::unique_ptr<Schema>, Error> FromArrowSchema(const ArrowSchema&
schema,
- int32_t schema_id);
+Result<std::unique_ptr<Schema>> FromArrowSchema(const ArrowSchema& schema,
+ int32_t schema_id);
/// \brief Convert a struct type to an Iceberg schema.
///
diff --git a/src/iceberg/sort_field.h b/src/iceberg/sort_field.h
index f02aef4..6037cec 100644
--- a/src/iceberg/sort_field.h
+++ b/src/iceberg/sort_field.h
@@ -28,9 +28,9 @@
#include <string_view>
#include <vector>
-#include "iceberg/error.h"
#include "iceberg/expected.h"
#include "iceberg/iceberg_export.h"
+#include "iceberg/result.h"
#include "iceberg/type_fwd.h"
#include "iceberg/util/formattable.h"
@@ -55,7 +55,7 @@ ICEBERG_EXPORT constexpr std::string_view
SortDirectionToString(SortDirection di
}
}
/// \brief Get the relative sort direction from name
-ICEBERG_EXPORT constexpr expected<SortDirection, Error>
SortDirectionFromString(
+ICEBERG_EXPORT constexpr Result<SortDirection> SortDirectionFromString(
std::string_view str) {
if (str == "asc") return SortDirection::kAscending;
if (str == "desc") return SortDirection::kDescending;
@@ -82,8 +82,7 @@ ICEBERG_EXPORT constexpr std::string_view
NullOrderToString(NullOrder null_order
}
}
/// \brief Get the relative null order from name
-ICEBERG_EXPORT constexpr expected<NullOrder, Error> NullOrderFromString(
- std::string_view str) {
+ICEBERG_EXPORT constexpr Result<NullOrder>
NullOrderFromString(std::string_view str) {
if (str == "nulls-first") return NullOrder::kFirst;
if (str == "nulls-last") return NullOrder::kLast;
return unexpected<Error>({.kind = ErrorKind::kInvalidArgument,
diff --git a/src/iceberg/table.h b/src/iceberg/table.h
index a62b41b..11a9fc9 100644
--- a/src/iceberg/table.h
+++ b/src/iceberg/table.h
@@ -19,14 +19,13 @@
#pragma once
-#include <map>
#include <memory>
#include <string>
+#include <unordered_map>
#include <vector>
-#include "iceberg/error.h"
-#include "iceberg/expected.h"
#include "iceberg/iceberg_export.h"
+#include "iceberg/result.h"
#include "iceberg/type_fwd.h"
namespace iceberg {
@@ -43,28 +42,30 @@ class ICEBERG_EXPORT Table {
virtual const std::string& uuid() const = 0;
/// \brief Refresh the current table metadata
- virtual expected<void, Error> Refresh() = 0;
+ virtual Status Refresh() = 0;
/// \brief Return the schema for this table
virtual const std::shared_ptr<Schema>& schema() const = 0;
/// \brief Return a map of schema for this table
- virtual const std::map<int32_t, std::shared_ptr<Schema>>& schemas() const =
0;
+ virtual const std::unordered_map<int32_t, std::shared_ptr<Schema>>&
schemas() const = 0;
/// \brief Return the partition spec for this table
virtual const std::shared_ptr<PartitionSpec>& spec() const = 0;
/// \brief Return a map of partition specs for this table
- virtual const std::map<int32_t, std::shared_ptr<PartitionSpec>>& specs()
const = 0;
+ virtual const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>&
specs()
+ const = 0;
/// \brief Return the sort order for this table
virtual const std::shared_ptr<SortOrder>& sort_order() const = 0;
/// \brief Return a map of sort order IDs to sort orders for this table
- virtual const std::map<int32_t, std::shared_ptr<SortOrder>>& sort_orders()
const = 0;
+ virtual const std::unordered_map<int32_t, std::shared_ptr<SortOrder>>&
sort_orders()
+ const = 0;
/// \brief Return a map of string properties for this table
- virtual const std::map<std::string, std::string>& properties() const = 0;
+ virtual const std::unordered_map<std::string, std::string>& properties()
const = 0;
/// \brief Return the table's base location
virtual const std::string& location() const = 0;
@@ -77,8 +78,7 @@ class ICEBERG_EXPORT Table {
///
/// \param snapshot_id the ID of the snapshot to get
/// \return the Snapshot with the given id
- virtual expected<std::shared_ptr<Snapshot>, Error> snapshot(
- int64_t snapshot_id) const = 0;
+ virtual Result<std::shared_ptr<Snapshot>> snapshot(int64_t snapshot_id)
const = 0;
/// \brief Get the snapshots of this table
virtual const std::vector<std::shared_ptr<Snapshot>>& snapshots() const = 0;
diff --git a/src/iceberg/transform.h b/src/iceberg/transform.h
index f948a45..4e8ecfc 100644
--- a/src/iceberg/transform.h
+++ b/src/iceberg/transform.h
@@ -25,9 +25,9 @@
#include <memory>
#include "iceberg/arrow_c_data.h"
-#include "iceberg/error.h"
#include "iceberg/expected.h"
#include "iceberg/iceberg_export.h"
+#include "iceberg/result.h"
#include "iceberg/type_fwd.h"
#include "iceberg/util/formattable.h"
diff --git a/test/matchers.h b/test/matchers.h
index eca3b6f..f04d4a5 100644
--- a/test/matchers.h
+++ b/test/matchers.h
@@ -22,7 +22,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-#include "iceberg/error.h"
+#include "iceberg/result.h"
/*
* \brief Define custom matchers for expected<T, Error> values