Skip to content

Commit 67926a8

Browse files
committed
fix: clang-tidy and add testcase for as span
1 parent 5839cf8 commit 67926a8

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

src/iceberg/test/data_file_set_test.cc

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,43 @@ TEST_F(DataFileSetTest, AsSpan) {
113113
DataFileSet set;
114114
EXPECT_TRUE(set.as_span().empty());
115115

116+
// Single element
117+
auto file0 = CreateDataFile("/path/to/file0.parquet");
118+
set.insert(file0);
119+
{
120+
auto span = set.as_span();
121+
EXPECT_EQ(span.size(), 1);
122+
EXPECT_EQ(span[0]->file_path, "/path/to/file0.parquet");
123+
EXPECT_EQ(span[0], file0); // Same pointer, span is a view
124+
}
125+
126+
// Multiple elements
116127
auto file1 = CreateDataFile("/path/to/file1.parquet");
117128
auto file2 = CreateDataFile("/path/to/file2.parquet");
118129
set.insert(file1);
119130
set.insert(file2);
120131

121132
auto span = set.as_span();
122-
EXPECT_EQ(span.size(), 2);
123-
EXPECT_EQ(span[0]->file_path, "/path/to/file1.parquet");
124-
EXPECT_EQ(span[1]->file_path, "/path/to/file2.parquet");
133+
EXPECT_EQ(span.size(), 3);
134+
EXPECT_EQ(span[0]->file_path, "/path/to/file0.parquet");
135+
EXPECT_EQ(span[1]->file_path, "/path/to/file1.parquet");
136+
EXPECT_EQ(span[2]->file_path, "/path/to/file2.parquet");
137+
138+
// Span matches set iteration order and identity
139+
size_t i = 0;
140+
for (const auto& file : set) {
141+
EXPECT_EQ(span[i], file) << "Span element " << i << " should match set iterator";
142+
++i;
143+
}
144+
EXPECT_EQ(i, span.size());
145+
146+
// Span works with range-for
147+
i = 0;
148+
for (const auto& file : span) {
149+
EXPECT_EQ(file->file_path, span[i]->file_path);
150+
++i;
151+
}
152+
EXPECT_EQ(i, 3);
125153

126154
set.clear();
127155
EXPECT_TRUE(set.as_span().empty());

src/iceberg/util/data_file_set.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ class ICEBERG_EXPORT DataFileSet {
8181
const_iterator cend() const { return elements_.cend(); }
8282

8383
/// \brief Get a non-owning view of the data files in insertion order.
84-
std::span<const value_type> as_span() const {
85-
return std::span<const value_type>(elements_.data(), elements_.size());
86-
}
84+
std::span<const value_type> as_span() const { return elements_; }
8785

8886
private:
8987
std::pair<iterator, bool> InsertImpl(value_type file) {

0 commit comments

Comments
 (0)