Skip to content

Commit 15dc63c

Browse files
authored
Merge branch 'main' into add_table_metadata
2 parents 4229aca + 1531631 commit 15dc63c

File tree

11 files changed

+555
-5
lines changed

11 files changed

+555
-5
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: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ set(ICEBERG_SOURCES
2525
schema_internal.cc
2626
partition_field.cc
2727
partition_spec.cc
28+
sort_field.cc
29+
sort_order.cc
2830
statistics_file.cc
2931
table_metadata.cc
3032
transform.cc
@@ -35,10 +37,14 @@ set(ICEBERG_SHARED_BUILD_INTERFACE_LIBS)
3537
set(ICEBERG_STATIC_INSTALL_INTERFACE_LIBS)
3638
set(ICEBERG_SHARED_INSTALL_INTERFACE_LIBS)
3739

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

4349
add_iceberg_lib(iceberg
4450
SOURCES

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/sort_field.cc

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include "iceberg/sort_field.h"
21+
22+
#include <format>
23+
24+
#include "iceberg/transform.h"
25+
#include "iceberg/type.h"
26+
#include "iceberg/util/formatter.h"
27+
28+
namespace iceberg {
29+
30+
namespace {
31+
/// \brief Get the relative sort direction name
32+
constexpr std::string_view ToString(SortDirection direction) {
33+
switch (direction) {
34+
case SortDirection::kAscending:
35+
return "asc";
36+
case SortDirection::kDescending:
37+
return "desc";
38+
default:
39+
return "invalid";
40+
}
41+
}
42+
43+
/// \brief Get the relative null order name
44+
constexpr std::string_view ToString(NullOrder null_order) {
45+
switch (null_order) {
46+
case NullOrder::kFirst:
47+
return "nulls-first";
48+
case NullOrder::kLast:
49+
return "nulls-last";
50+
default:
51+
return "invalid";
52+
}
53+
}
54+
} // namespace
55+
56+
SortField::SortField(int32_t source_id, std::shared_ptr<TransformFunction> transform,
57+
SortDirection direction, NullOrder null_order)
58+
: source_id_(source_id),
59+
transform_(std::move(transform)),
60+
direction_(direction),
61+
null_order_(null_order) {}
62+
63+
int32_t SortField::source_id() const { return source_id_; }
64+
65+
std::shared_ptr<TransformFunction> const& SortField::transform() const {
66+
return transform_;
67+
}
68+
69+
SortDirection SortField::direction() const { return direction_; }
70+
71+
NullOrder SortField::null_order() const { return null_order_; }
72+
73+
std::string SortField::ToString() const {
74+
return std::format(
75+
"sort_field(source_id={}, transform={}, direction={}, null_order={})", source_id_,
76+
*transform_, iceberg::ToString(direction_), iceberg::ToString(null_order_));
77+
}
78+
79+
bool SortField::Equals(const SortField& other) const {
80+
return source_id_ == other.source_id_ && *transform_ == *other.transform_ &&
81+
direction_ == other.direction_ && null_order_ == other.null_order_;
82+
}
83+
84+
} // namespace iceberg

src/iceberg/sort_field.h

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
22+
/// \file iceberg/sort_field.h
23+
/// A sort field in a sort order
24+
25+
#include <cstdint>
26+
#include <memory>
27+
#include <string>
28+
#include <string_view>
29+
#include <vector>
30+
31+
#include "iceberg/iceberg_export.h"
32+
#include "iceberg/type_fwd.h"
33+
#include "iceberg/util/formattable.h"
34+
35+
namespace iceberg {
36+
37+
/// \brief Sort direction in a partition, either ascending or descending
38+
enum class SortDirection {
39+
/// Ascending
40+
kAscending,
41+
/// Descending
42+
kDescending,
43+
};
44+
45+
enum class NullOrder {
46+
/// Nulls are sorted first
47+
kFirst,
48+
/// Nulls are sorted last
49+
kLast,
50+
};
51+
52+
/// \brief a field with its transform.
53+
class ICEBERG_EXPORT SortField : public util::Formattable {
54+
public:
55+
/// \brief Construct a field.
56+
/// \param[in] source_id The source field ID.
57+
/// \param[in] transform The transform function.
58+
/// \param[in] direction The sort direction.
59+
/// \param[in] null_order The null order.
60+
SortField(int32_t source_id, std::shared_ptr<TransformFunction> transform,
61+
SortDirection direction, NullOrder null_order);
62+
63+
/// \brief Get the source field ID.
64+
int32_t source_id() const;
65+
66+
/// \brief Get the transform type.
67+
const std::shared_ptr<TransformFunction>& transform() const;
68+
69+
/// \brief Get the sort direction.
70+
SortDirection direction() const;
71+
72+
/// \brief Get the null order.
73+
NullOrder null_order() const;
74+
75+
std::string ToString() const override;
76+
77+
friend bool operator==(const SortField& lhs, const SortField& rhs) {
78+
return lhs.Equals(rhs);
79+
}
80+
81+
friend bool operator!=(const SortField& lhs, const SortField& rhs) {
82+
return !(lhs == rhs);
83+
}
84+
85+
private:
86+
/// \brief Compare two fields for equality.
87+
[[nodiscard]] bool Equals(const SortField& other) const;
88+
89+
int32_t source_id_;
90+
std::shared_ptr<TransformFunction> transform_;
91+
SortDirection direction_;
92+
NullOrder null_order_;
93+
};
94+
95+
} // namespace iceberg

src/iceberg/sort_order.cc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include "iceberg/sort_order.h"
21+
22+
#include <format>
23+
24+
#include "iceberg/util/formatter.h"
25+
26+
namespace iceberg {
27+
28+
SortOrder::SortOrder(int64_t order_id, std::vector<SortField> fields)
29+
: order_id_(order_id), fields_(std::move(fields)) {}
30+
31+
int64_t SortOrder::order_id() const { return order_id_; }
32+
33+
std::span<const SortField> SortOrder::fields() const { return fields_; }
34+
35+
std::string SortOrder::ToString() const {
36+
std::string repr = std::format("sort_order[order_id<{}>,\n", order_id_);
37+
for (const auto& field : fields_) {
38+
std::format_to(std::back_inserter(repr), " {}\n", field);
39+
}
40+
repr += "]";
41+
return repr;
42+
}
43+
44+
bool SortOrder::Equals(const SortOrder& other) const {
45+
return order_id_ == other.order_id_ && fields_ == other.fields_;
46+
}
47+
48+
} // namespace iceberg

0 commit comments

Comments
 (0)