Skip to content

Commit 86f615e

Browse files
author
shuxu.li
committed
feat: static table metadata access support
1 parent 7933a27 commit 86f615e

File tree

5 files changed

+38
-35
lines changed

5 files changed

+38
-35
lines changed

src/iceberg/table.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#pragma once
2121

2222
#include <memory>
23+
#include <mutex>
2324
#include <string>
2425
#include <unordered_map>
2526
#include <vector>

test/CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ add_test(NAME schema_test COMMAND schema_test)
4646

4747
add_executable(table_test)
4848
target_include_directories(table_test PRIVATE "${CMAKE_BINARY_DIR}")
49-
target_sources(table_test PRIVATE table_test_helper.cc json_internal_test.cc table_test.cc
50-
schema_json_test.cc)
51-
target_link_libraries(table_test PRIVATE iceberg_static GTest::gtest_main
52-
GTest::gmock)
49+
target_sources(table_test PRIVATE table_test_helper.cc json_internal_test.cc
50+
table_test.cc schema_json_test.cc)
51+
target_link_libraries(table_test PRIVATE iceberg_static GTest::gtest_main GTest::gmock)
5352
add_test(NAME table_test COMMAND table_test)
5453

5554
add_executable(expression_test)
@@ -60,8 +59,8 @@ add_test(NAME expression_test COMMAND expression_test)
6059

6160
add_executable(json_serde_test)
6261
target_include_directories(json_serde_test PRIVATE "${CMAKE_BINARY_DIR}")
63-
target_sources(json_serde_test PRIVATE table_test_helper.cc json_internal_test.cc metadata_serde_test.cc
64-
schema_json_test.cc)
62+
target_sources(json_serde_test PRIVATE table_test_helper.cc json_internal_test.cc
63+
metadata_serde_test.cc schema_json_test.cc)
6564
target_link_libraries(json_serde_test PRIVATE iceberg_static GTest::gtest_main
6665
GTest::gmock)
6766
add_test(NAME json_serde_test COMMAND json_serde_test)

test/table_test.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* under the License.
1818
*/
1919

20+
#include "iceberg/table.h"
21+
2022
#include <filesystem>
2123
#include <fstream>
2224
#include <optional>
@@ -30,7 +32,6 @@
3032
#include "iceberg/schema.h"
3133
#include "iceberg/snapshot.h"
3234
#include "iceberg/table_metadata.h"
33-
#include "iceberg/table.h"
3435
#include "table_test_helper.h"
3536

3637
namespace iceberg {
@@ -46,7 +47,8 @@ class TableTest : public ::testing::Test {
4647

4748
TEST_F(TableTest, TableSchemaV1Test) {
4849
std::unique_ptr<TableMetadata> metadata;
49-
ASSERT_NO_FATAL_FAILURE(TableTestHelper::ReadTableMetadata("TableMetadataV1Valid.json", &metadata));
50+
ASSERT_NO_FATAL_FAILURE(
51+
TableTestHelper::ReadTableMetadata("TableMetadataV1Valid.json", &metadata));
5052

5153
StaticTable table("test_table_v1", std::move(metadata));
5254
ASSERT_EQ(table.name(), "test_table_v1");
@@ -75,7 +77,8 @@ TEST_F(TableTest, TableSchemaV1Test) {
7577

7678
TEST_F(TableTest, TableSchemaV2Test) {
7779
std::unique_ptr<TableMetadata> metadata;
78-
ASSERT_NO_FATAL_FAILURE(TableTestHelper::ReadTableMetadata("TableMetadataV2Valid.json", &metadata));
80+
ASSERT_NO_FATAL_FAILURE(
81+
TableTestHelper::ReadTableMetadata("TableMetadataV2Valid.json", &metadata));
7982

8083
StaticTable table("test_table_v2", std::move(metadata));
8184
ASSERT_EQ(table.name(), "test_table_v2");

test/table_test_helper.cc

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Licensed to the Apache Software Foundation (ASF) under one
2+
* Licensed to the Apache Software Foundation (ASF) under one
33
* or more contributor license agreements. See the NOTICE file
44
* distributed with this work for additional information
55
* regarding copyright ownership. The ASF licenses this file
@@ -19,6 +19,8 @@
1919

2020
#pragma once
2121

22+
#include "table_test_helper.h"
23+
2224
#include <filesystem>
2325
#include <fstream>
2426
#include <optional>
@@ -30,35 +32,33 @@
3032

3133
#include "iceberg/json_internal.h"
3234
#include "iceberg/test/test_config.h"
33-
#include "table_test_helper.h"
3435

3536
namespace iceberg {
3637

37-
std::string TableTestHelper::GetResourcePath(const std::string& file_name) {
38-
return std::string(ICEBERG_TEST_RESOURCES) + "/" + file_name;
39-
}
38+
std::string TableTestHelper::GetResourcePath(const std::string& file_name) {
39+
return std::string(ICEBERG_TEST_RESOURCES) + "/" + file_name;
40+
}
4041

41-
void TableTestHelper::ReadJsonFile(const std::string& file_name, std::string* content) {
42-
std::filesystem::path path{GetResourcePath(file_name)};
43-
ASSERT_TRUE(std::filesystem::exists(path))
44-
<< "File does not exist: " << path.string();
42+
void TableTestHelper::ReadJsonFile(const std::string& file_name, std::string* content) {
43+
std::filesystem::path path{GetResourcePath(file_name)};
44+
ASSERT_TRUE(std::filesystem::exists(path)) << "File does not exist: " << path.string();
4545

46-
std::ifstream file(path);
47-
std::stringstream buffer;
48-
buffer << file.rdbuf();
49-
*content = buffer.str();
50-
}
46+
std::ifstream file(path);
47+
std::stringstream buffer;
48+
buffer << file.rdbuf();
49+
*content = buffer.str();
50+
}
5151

52-
void TableTestHelper::ReadTableMetadata(const std::string& file_name,
53-
std::unique_ptr<TableMetadata>* metadata) {
54-
std::string json_content;
55-
ReadJsonFile(file_name, &json_content);
52+
void TableTestHelper::ReadTableMetadata(const std::string& file_name,
53+
std::unique_ptr<TableMetadata>* metadata) {
54+
std::string json_content;
55+
ReadJsonFile(file_name, &json_content);
5656

57-
nlohmann::json json = nlohmann::json::parse(json_content);
58-
auto result = TableMetadataFromJson(json);
59-
ASSERT_TRUE(result.has_value()) << "Failed to parse table metadata from " << file_name
60-
<< ": " << result.error().message;
61-
*metadata = std::move(result.value());
62-
}
57+
nlohmann::json json = nlohmann::json::parse(json_content);
58+
auto result = TableMetadataFromJson(json);
59+
ASSERT_TRUE(result.has_value()) << "Failed to parse table metadata from " << file_name
60+
<< ": " << result.error().message;
61+
*metadata = std::move(result.value());
62+
}
6363

64-
} // namespace
64+
} // namespace iceberg

test/table_test_helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ class TableTestHelper {
3333
std::unique_ptr<TableMetadata>* metadata);
3434
};
3535

36-
} // namespace iceberg
36+
} // namespace iceberg

0 commit comments

Comments
 (0)