Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/demo_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "iceberg/arrow/arrow_file_io.h"
#include "iceberg/avro/avro_register.h"
#include "iceberg/catalog/in_memory_catalog.h"
#include "iceberg/catalog/memory/in_memory_catalog.h"
#include "iceberg/parquet/parquet_register.h"
#include "iceberg/table.h"
#include "iceberg/table_scan.h"
Expand Down
2 changes: 1 addition & 1 deletion src/iceberg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
set(ICEBERG_INCLUDES "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>")
set(ICEBERG_SOURCES
catalog/in_memory_catalog.cc
catalog/memory/in_memory_catalog.cc
expression/expression.cc
expression/expressions.cc
expression/literal.cc
Expand Down
2 changes: 2 additions & 0 deletions src/iceberg/catalog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

iceberg_install_all_headers(iceberg/catalog)
Copy link
Contributor

@WillAyd WillAyd Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI since the in_memory_catalog.h header was moved, this no longer installs anything. Maybe worth removing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!


add_subdirectory(memory)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
add_subdirectory(memory)
add_subdirectory(memory)


if(ICEBERG_BUILD_REST)
add_subdirectory(rest)
endif()
18 changes: 18 additions & 0 deletions src/iceberg/catalog/memory/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

iceberg_install_all_headers(iceberg/catalog/memory)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

#include "iceberg/catalog/in_memory_catalog.h"
#include "iceberg/catalog/memory/in_memory_catalog.h"

#include <algorithm>
#include <iterator> // IWYU pragma: keep
Expand Down
18 changes: 17 additions & 1 deletion src/iceberg/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@
# specific language governing permissions and limitations
# under the License.

fetchcontent_declare(cpp-httplib
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WillAyd Do you have any comment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming this is in the context of Meson then no - this package is available in the wrapdb so it's easy to integrate

GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git
GIT_TAG 89c932f313c6437c38f2982869beacc89c2f2246 #release-0.26.0
)

fetchcontent_declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG b514bdc898e2951020cbdca1304b75f5950d1f59 # release-1.15.2
FIND_PACKAGE_ARGS
NAMES
GTest)
fetchcontent_makeavailable(googletest)

if(ICEBERG_BUILD_REST)
fetchcontent_makeavailable(cpp-httplib googletest)
else()
fetchcontent_makeavailable(googletest)
endif()

set(ICEBERG_TEST_RESOURCES "${CMAKE_SOURCE_DIR}/src/iceberg/test/resources")

Expand Down Expand Up @@ -136,3 +146,9 @@ if(ICEBERG_BUILD_BUNDLE)
add_iceberg_test(scan_test USE_BUNDLE SOURCES file_scan_task_test.cc)

endif()

if(ICEBERG_BUILD_REST)
add_iceberg_test(rest_catalog_test SOURCES rest_catalog_test.cc)
target_link_libraries(rest_catalog_test PRIVATE iceberg_rest_static)
target_include_directories(rest_catalog_test PRIVATE ${cpp-httplib_SOURCE_DIR})
endif()
2 changes: 1 addition & 1 deletion src/iceberg/test/in_memory_catalog_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

#include "iceberg/catalog/in_memory_catalog.h"
#include "iceberg/catalog/memory/in_memory_catalog.h"

#include <filesystem>

Expand Down
111 changes: 111 additions & 0 deletions src/iceberg/test/rest_catalog_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include "iceberg/catalog/rest/rest_catalog.h"

#include <httplib.h>

#include <memory>
#include <thread>

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <nlohmann/json.hpp>

namespace iceberg::catalog::rest {

class RestCatalogIntegrationTest : public ::testing::Test {
protected:
void SetUp() override {
server_ = std::make_unique<httplib::Server>();
port_ = server_->bind_to_any_port("127.0.0.1");

server_thread_ = std::thread([this]() { server_->listen_after_bind(); });
}

void TearDown() override {
server_->stop();
if (server_thread_.joinable()) {
server_thread_.join();
}
}

std::unique_ptr<httplib::Server> server_;
int port_ = -1;
std::thread server_thread_;
};

TEST_F(RestCatalogIntegrationTest, GetConfigSuccessfully) {
server_->Get("/v1/config", [](const httplib::Request&, httplib::Response& res) {
res.status = 200;
res.set_content(R"({"warehouse": "s3://test-bucket"})", "application/json");
});

std::string base_uri = "http://127.0.0.1:" + std::to_string(port_);
RestCatalog catalog(base_uri);
cpr::Response response = catalog.GetConfig();

ASSERT_EQ(response.error.code, cpr::ErrorCode::OK);
ASSERT_EQ(response.status_code, 200);

auto json_body = nlohmann::json::parse(response.text);
EXPECT_EQ(json_body["warehouse"], "s3://test-bucket");
}

TEST_F(RestCatalogIntegrationTest, ListNamespacesReturnsMultipleResults) {
server_->Get("/v1/namespaces", [](const httplib::Request&, httplib::Response& res) {
res.status = 200;
res.set_content(R"({
"namespaces": [
["accounting", "db"],
["production", "db"]
]
})",
"application/json");
});

std::string base_uri = "http://127.0.0.1:" + std::to_string(port_);
RestCatalog catalog(base_uri);
cpr::Response response = catalog.ListNamespaces();

ASSERT_EQ(response.error.code, cpr::ErrorCode::OK);
ASSERT_EQ(response.status_code, 200);

auto json_body = nlohmann::json::parse(response.text);
ASSERT_TRUE(json_body.contains("namespaces"));
EXPECT_EQ(json_body["namespaces"].size(), 2);
EXPECT_THAT(json_body["namespaces"][0][0], "accounting");
}

TEST_F(RestCatalogIntegrationTest, HandlesServerError) {
server_->Get("/v1/config", [](const httplib::Request&, httplib::Response& res) {
res.status = 500;
res.set_content("Internal Server Error", "text/plain");
});

std::string base_uri = "http://127.0.0.1:" + std::to_string(port_);
RestCatalog catalog(base_uri);
cpr::Response response = catalog.GetConfig();

ASSERT_EQ(response.error.code, cpr::ErrorCode::OK);
ASSERT_EQ(response.status_code, 500);
ASSERT_EQ(response.text, "Internal Server Error");
}

} // namespace iceberg::catalog::rest
Loading