Skip to content

Commit d191747

Browse files
committed
Merge remote-tracking branch 'origin/main' into expr
2 parents 68298ed + 0fc2a67 commit d191747

35 files changed

+2158
-65
lines changed

LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,30 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
227227
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
228228
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
229229
SOFTWARE.
230+
231+
--------------------------------------------------------------------------------
232+
233+
3rdparty dependency nlohmann-json is statically linked in certain binary
234+
distributions. nlohmann-json has the following license:
235+
236+
MIT License
237+
238+
Copyright (c) 2013-2022 Niels Lohmann
239+
240+
Permission is hereby granted, free of charge, to any person obtaining a copy
241+
of this software and associated documentation files (the "Software"), to deal
242+
in the Software without restriction, including without limitation the rights
243+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
244+
copies of the Software, and to permit persons to whom the Software is
245+
furnished to do so, subject to the following conditions:
246+
247+
The above copyright notice and this permission notice shall be included in all
248+
copies or substantial portions of the Software.
249+
250+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
251+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
252+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
253+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
254+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
255+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
256+
SOFTWARE.

cmake_modules/IcebergThirdpartyToolchain.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,36 @@ function(resolve_nanoarrow_dependency)
226226
endfunction()
227227

228228
resolve_nanoarrow_dependency()
229+
230+
# ----------------------------------------------------------------------
231+
# nlohmann-json
232+
233+
function(resolve_nlohmann_json_dependency)
234+
prepare_fetchcontent()
235+
236+
set(JSON_BuildTests
237+
OFF
238+
CACHE BOOL "" FORCE)
239+
240+
fetchcontent_declare(nlohmann_json
241+
${FC_DECLARE_COMMON_OPTIONS}
242+
URL "https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz"
243+
)
244+
fetchcontent_makeavailable(nlohmann_json)
245+
246+
set_target_properties(nlohmann_json
247+
PROPERTIES OUTPUT_NAME "iceberg_vendored_nlohmann_json"
248+
POSITION_INDEPENDENT_CODE ON)
249+
if(MSVC_TOOLCHAIN)
250+
set(NLOHMANN_NATVIS_FILE ${nlohmann_json_SOURCE_DIR}/nlohmann_json.natvis)
251+
install(FILES ${NLOHMANN_NATVIS_FILE} DESTINATION .)
252+
endif()
253+
254+
install(TARGETS nlohmann_json
255+
EXPORT iceberg_targets
256+
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
257+
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
258+
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
259+
endfunction()
260+
261+
resolve_nlohmann_json_dependency()

src/iceberg/CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ set(ICEBERG_SOURCES
2121
arrow_c_data_internal.cc
2222
demo.cc
2323
expression.cc
24+
json_internal.cc
2425
schema.cc
2526
schema_field.cc
2627
schema_internal.cc
2728
partition_field.cc
2829
partition_spec.cc
30+
sort_field.cc
31+
sort_order.cc
32+
statistics_file.cc
33+
table_metadata.cc
2934
transform.cc
3035
type.cc)
3136

@@ -34,10 +39,14 @@ set(ICEBERG_SHARED_BUILD_INTERFACE_LIBS)
3439
set(ICEBERG_STATIC_INSTALL_INTERFACE_LIBS)
3540
set(ICEBERG_SHARED_INSTALL_INTERFACE_LIBS)
3641

37-
list(APPEND ICEBERG_STATIC_BUILD_INTERFACE_LIBS nanoarrow::nanoarrow)
38-
list(APPEND ICEBERG_SHARED_BUILD_INTERFACE_LIBS nanoarrow::nanoarrow)
39-
list(APPEND ICEBERG_STATIC_INSTALL_INTERFACE_LIBS "Iceberg::nanoarrow")
40-
list(APPEND ICEBERG_SHARED_INSTALL_INTERFACE_LIBS "Iceberg::nanoarrow")
42+
list(APPEND ICEBERG_STATIC_BUILD_INTERFACE_LIBS nanoarrow::nanoarrow
43+
nlohmann_json::nlohmann_json)
44+
list(APPEND ICEBERG_SHARED_BUILD_INTERFACE_LIBS nanoarrow::nanoarrow
45+
nlohmann_json::nlohmann_json)
46+
list(APPEND ICEBERG_STATIC_INSTALL_INTERFACE_LIBS "Iceberg::nanoarrow"
47+
"Iceberg::nlohmann_json")
48+
list(APPEND ICEBERG_SHARED_INSTALL_INTERFACE_LIBS "Iceberg::nanoarrow"
49+
"Iceberg::nlohmann_json")
4150

4251
add_iceberg_lib(iceberg
4352
SOURCES

src/iceberg/arrow/arrow_error_transform_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#include <arrow/result.h>
2323
#include <arrow/status.h>
2424

25-
#include "iceberg/error.h"
2625
#include "iceberg/expected.h"
26+
#include "iceberg/result.h"
2727

2828
namespace iceberg::arrow {
2929

src/iceberg/arrow/arrow_fs_file_io.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
namespace iceberg::arrow {
2727

2828
/// \brief Read the content of the file at the given location.
29-
expected<std::string, Error> ArrowFileSystemFileIO::ReadFile(
30-
const std::string& file_location, std::optional<size_t> length) {
29+
Result<std::string> ArrowFileSystemFileIO::ReadFile(const std::string& file_location,
30+
std::optional<size_t> length) {
3131
::arrow::fs::FileInfo file_info(file_location);
3232
if (length.has_value()) {
3333
file_info.set_size(length.value());
@@ -52,8 +52,8 @@ expected<std::string, Error> ArrowFileSystemFileIO::ReadFile(
5252
}
5353

5454
/// \brief Write the given content to the file at the given location.
55-
expected<void, Error> ArrowFileSystemFileIO::WriteFile(const std::string& file_location,
56-
std::string_view content) {
55+
Status ArrowFileSystemFileIO::WriteFile(const std::string& file_location,
56+
std::string_view content) {
5757
ICEBERG_ARROW_ASSIGN_OR_RETURN(auto file, arrow_fs_->OpenOutputStream(file_location));
5858
ICEBERG_ARROW_RETURN_NOT_OK(file->Write(content.data(), content.size()));
5959
ICEBERG_ARROW_RETURN_NOT_OK(file->Flush());
@@ -62,8 +62,7 @@ expected<void, Error> ArrowFileSystemFileIO::WriteFile(const std::string& file_l
6262
}
6363

6464
/// \brief Delete a file at the given location.
65-
expected<void, Error> ArrowFileSystemFileIO::DeleteFile(
66-
const std::string& file_location) {
65+
Status ArrowFileSystemFileIO::DeleteFile(const std::string& file_location) {
6766
ICEBERG_ARROW_RETURN_NOT_OK(arrow_fs_->DeleteFile(file_location));
6867
return {};
6968
}

src/iceberg/arrow/arrow_fs_file_io.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ class ICEBERG_BUNDLE_EXPORT ArrowFileSystemFileIO : public FileIO {
3737
~ArrowFileSystemFileIO() override = default;
3838

3939
/// \brief Read the content of the file at the given location.
40-
expected<std::string, Error> ReadFile(const std::string& file_location,
41-
std::optional<size_t> length) override;
40+
Result<std::string> ReadFile(const std::string& file_location,
41+
std::optional<size_t> length) override;
4242

4343
/// \brief Write the given content to the file at the given location.
44-
expected<void, Error> WriteFile(const std::string& file_location,
45-
std::string_view content) override;
44+
Status WriteFile(const std::string& file_location, std::string_view content) override;
4645

4746
/// \brief Delete a file at the given location.
48-
expected<void, Error> DeleteFile(const std::string& file_location) override;
47+
Status DeleteFile(const std::string& file_location) override;
4948

5049
private:
5150
std::shared_ptr<::arrow::fs::FileSystem> arrow_fs_;

src/iceberg/arrow_c_data_internal.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <string>
2424
#include <utility>
2525

26+
#include <nlohmann/json.hpp>
27+
2628
namespace iceberg::internal {
2729

2830
std::pair<ArrowSchema, ArrowArray> CreateExampleArrowSchemaAndArrayByNanoarrow() {
@@ -73,4 +75,11 @@ std::pair<ArrowSchema, ArrowArray> CreateExampleArrowSchemaAndArrayByNanoarrow()
7375
return {out_schema, out_array};
7476
}
7577

78+
void TestNlohmannJsonCompile() {
79+
nlohmann::json j;
80+
j["name"] = "foo";
81+
j["age"] = 30;
82+
j["city"] = "New York";
83+
}
84+
7685
} // namespace iceberg::internal

src/iceberg/catalog.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919

2020
#pragma once
2121

22-
#include <map>
2322
#include <memory>
2423
#include <string>
2524
#include <string_view>
25+
#include <unordered_map>
2626
#include <vector>
2727

28-
#include "iceberg/error.h"
29-
#include "iceberg/expected.h"
28+
#include "iceberg/result.h"
3029
#include "iceberg/table_identifier.h"
3130
#include "iceberg/type_fwd.h"
3231

@@ -48,8 +47,7 @@ class ICEBERG_EXPORT Catalog {
4847
/// \param ns a namespace
4948
/// \return a list of identifiers for tables or ErrorKind::kNoSuchNamespace
5049
/// if the namespace does not exist
51-
virtual expected<std::vector<TableIdentifier>, Error> ListTables(
52-
const Namespace& ns) const = 0;
50+
virtual Result<std::vector<TableIdentifier>> ListTables(const Namespace& ns) const = 0;
5351

5452
/// \brief Create a table
5553
///
@@ -59,18 +57,18 @@ class ICEBERG_EXPORT Catalog {
5957
/// \param location a location for the table; leave empty if unspecified
6058
/// \param properties a string map of table properties
6159
/// \return a Table instance or ErrorKind::kAlreadyExists if the table already exists
62-
virtual expected<std::unique_ptr<Table>, Error> CreateTable(
60+
virtual Result<std::unique_ptr<Table>> CreateTable(
6361
const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
6462
const std::string& location,
65-
const std::map<std::string, std::string>& properties) = 0;
63+
const std::unordered_map<std::string, std::string>& properties) = 0;
6664

6765
/// \brief Update a table
6866
///
6967
/// \param identifier a table identifier
7068
/// \param requirements a list of table requirements
7169
/// \param updates a list of table updates
7270
/// \return a Table instance or ErrorKind::kAlreadyExists if the table already exists
73-
virtual expected<std::unique_ptr<Table>, Error> UpdateTable(
71+
virtual Result<std::unique_ptr<Table>> UpdateTable(
7472
const TableIdentifier& identifier,
7573
const std::vector<std::unique_ptr<UpdateRequirement>>& requirements,
7674
const std::vector<std::unique_ptr<MetadataUpdate>>& updates) = 0;
@@ -84,10 +82,10 @@ class ICEBERG_EXPORT Catalog {
8482
/// \param properties a string map of table properties
8583
/// \return a Transaction to create the table or ErrorKind::kAlreadyExists if the table
8684
/// already exists
87-
virtual expected<std::shared_ptr<Transaction>, Error> StageCreateTable(
85+
virtual Result<std::shared_ptr<Transaction>> StageCreateTable(
8886
const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
8987
const std::string& location,
90-
const std::map<std::string, std::string>& properties) = 0;
88+
const std::unordered_map<std::string, std::string>& properties) = 0;
9189

9290
/// \brief Check whether table exists
9391
///
@@ -110,15 +108,15 @@ class ICEBERG_EXPORT Catalog {
110108
/// \param identifier a table identifier
111109
/// \return instance of Table implementation referred to by identifier or
112110
/// ErrorKind::kNoSuchTable if the table does not exist
113-
virtual expected<std::shared_ptr<Table>, Error> LoadTable(
111+
virtual Result<std::shared_ptr<Table>> LoadTable(
114112
const TableIdentifier& identifier) const = 0;
115113

116114
/// \brief Register a table with the catalog if it does not exist
117115
///
118116
/// \param identifier a table identifier
119117
/// \param metadata_file_location the location of a metadata file
120118
/// \return a Table instance or ErrorKind::kAlreadyExists if the table already exists
121-
virtual expected<std::shared_ptr<Table>, Error> RegisterTable(
119+
virtual Result<std::shared_ptr<Table>> RegisterTable(
122120
const TableIdentifier& identifier, const std::string& metadata_file_location) = 0;
123121

124122
/// \brief Initialize a catalog given a custom name and a map of catalog properties
@@ -129,8 +127,9 @@ class ICEBERG_EXPORT Catalog {
129127
///
130128
/// \param name a custom name for the catalog
131129
/// \param properties catalog properties
132-
virtual void Initialize(const std::string& name,
133-
const std::map<std::string, std::string>& properties) = 0;
130+
virtual void Initialize(
131+
const std::string& name,
132+
const std::unordered_map<std::string, std::string>& properties) = 0;
134133

135134
/// \brief Instantiate a builder to either create a table or start a create/replace
136135
/// transaction
@@ -169,7 +168,7 @@ class ICEBERG_EXPORT Catalog {
169168
/// \param properties key/value properties
170169
/// \return this for method chaining
171170
virtual TableBuilder& WithProperties(
172-
const std::map<std::string, std::string>& properties) = 0;
171+
const std::unordered_map<std::string, std::string>& properties) = 0;
173172

174173
/// \brief Adds a key/value property to the table
175174
///

src/iceberg/file_io.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
#include <string>
2424
#include <string_view>
2525

26-
#include "iceberg/error.h"
27-
#include "iceberg/expected.h"
2826
#include "iceberg/iceberg_export.h"
27+
#include "iceberg/result.h"
2928

3029
namespace iceberg {
3130

@@ -50,8 +49,8 @@ class ICEBERG_EXPORT FileIO {
5049
/// the length to read, e.g. S3 `GetObject` has a Range parameter.
5150
/// \return The content of the file if the read succeeded, an error code if the read
5251
/// failed.
53-
virtual expected<std::string, Error> ReadFile(const std::string& file_location,
54-
std::optional<size_t> length) {
52+
virtual Result<std::string> ReadFile(const std::string& file_location,
53+
std::optional<size_t> length) {
5554
// We provide a default implementation to avoid Windows linker error LNK2019.
5655
return unexpected<Error>{
5756
{.kind = ErrorKind::kNotImplemented, .message = "ReadFile not implemented"}};
@@ -64,8 +63,7 @@ class ICEBERG_EXPORT FileIO {
6463
/// \param overwrite If true, overwrite the file if it exists. If false, fail if the
6564
/// file exists.
6665
/// \return void if the write succeeded, an error code if the write failed.
67-
virtual expected<void, Error> WriteFile(const std::string& file_location,
68-
std::string_view content) {
66+
virtual Status WriteFile(const std::string& file_location, std::string_view content) {
6967
return unexpected<Error>{
7068
{.kind = ErrorKind::kNotImplemented, .message = "WriteFile not implemented"}};
7169
}
@@ -74,7 +72,7 @@ class ICEBERG_EXPORT FileIO {
7472
///
7573
/// \param file_location The location of the file to delete.
7674
/// \return void if the delete succeeded, an error code if the delete failed.
77-
virtual expected<void, Error> DeleteFile(const std::string& file_location) {
75+
virtual Status DeleteFile(const std::string& file_location) {
7876
return unexpected<Error>{
7977
{.kind = ErrorKind::kNotImplemented, .message = "DeleteFile not implemented"}};
8078
}

0 commit comments

Comments
 (0)