Skip to content

Commit a6ff753

Browse files
authored
chore: refactor some obvious non optimal coding style (#440)
1 parent e62acea commit a6ff753

File tree

9 files changed

+17
-21
lines changed

9 files changed

+17
-21
lines changed

src/iceberg/json_internal.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,9 +787,9 @@ nlohmann::json ToJson(const TableMetadata& table_metadata) {
787787
// write properties map
788788
json[kProperties] = table_metadata.properties.configs();
789789

790-
if (std::ranges::find_if(table_metadata.snapshots, [&](const auto& snapshot) {
790+
if (std::ranges::any_of(table_metadata.snapshots, [&](const auto& snapshot) {
791791
return snapshot->snapshot_id == table_metadata.current_snapshot_id;
792-
}) != table_metadata.snapshots.cend()) {
792+
})) {
793793
json[kCurrentSnapshotId] = table_metadata.current_snapshot_id;
794794
} else {
795795
json[kCurrentSnapshotId] = nlohmann::json::value_t::null;

src/iceberg/manifest/manifest_reader.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ bool RequireStatsProjection(const std::shared_ptr<Expression>& row_filter,
570570
return false;
571571
}
572572
const std::unordered_set<std::string_view> selected(columns.cbegin(), columns.cend());
573-
if (selected.contains(ManifestReader::kAllColumns)) {
573+
if (selected.contains(Schema::kAllColumns)) {
574574
return false;
575575
}
576576
if (std::ranges::all_of(kStatsColumns, [&selected](const std::string& col) {
@@ -594,7 +594,7 @@ Result<std::shared_ptr<Schema>> ProjectSchema(std::shared_ptr<Schema> schema,
594594

595595
std::vector<std::string> ManifestReader::WithStatsColumns(
596596
const std::vector<std::string>& columns) {
597-
if (std::ranges::contains(columns, ManifestReader::kAllColumns)) {
597+
if (std::ranges::contains(columns, Schema::kAllColumns)) {
598598
return columns;
599599
} else {
600600
std::vector<std::string> updated_columns{columns};

src/iceberg/manifest/manifest_reader.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ namespace iceberg {
3636
/// \brief Read manifest entries from a manifest file.
3737
class ICEBERG_EXPORT ManifestReader {
3838
public:
39-
/// \brief Special value to select all columns from manifest files.
40-
static constexpr std::string_view kAllColumns = "*";
41-
4239
virtual ~ManifestReader() = default;
4340

4441
/// \brief Read all manifest entries in the manifest file.

src/iceberg/schema.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ Result<std::unique_ptr<StructLikeAccessor>> Schema::GetAccessorById(
163163

164164
Result<std::unique_ptr<Schema>> Schema::Select(std::span<const std::string> names,
165165
bool case_sensitive) const {
166-
const std::string kAllColumns = "*";
167166
if (std::ranges::find(names, kAllColumns) != names.end()) {
168167
auto struct_type = ToStructType(*this);
169168
return FromStructType(std::move(*struct_type), std::nullopt);

src/iceberg/schema.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class ICEBERG_EXPORT Schema : public StructType {
4848
static constexpr int32_t kInitialSchemaId = 0;
4949
static constexpr int32_t kInvalidColumnId = -1;
5050

51+
/// \brief Special value to select all columns from manifest files.
52+
static constexpr std::string_view kAllColumns = "*";
53+
5154
explicit Schema(std::vector<SchemaField> fields,
5255
std::optional<int32_t> schema_id = std::nullopt,
5356
std::vector<int32_t> identifier_field_ids = {});

src/iceberg/table_metadata.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,12 @@ Result<int32_t> TableMetadataBuilder::Impl::AddSortOrder(const SortOrder& order)
548548
// is now the last)
549549
bool is_new_order =
550550
last_added_order_id_.has_value() &&
551-
std::ranges::find_if(changes_, [new_order_id](const auto& change) {
551+
std::ranges::any_of(changes_, [new_order_id](const auto& change) {
552552
return change->kind() == TableUpdate::Kind::kAddSortOrder &&
553553
internal::checked_cast<const table::AddSortOrder&>(*change)
554554
.sort_order()
555555
->order_id() == new_order_id;
556-
}) != changes_.cend();
556+
});
557557
last_added_order_id_ = is_new_order ? std::make_optional(new_order_id) : std::nullopt;
558558
return new_order_id;
559559
}
@@ -613,12 +613,12 @@ Result<int32_t> TableMetadataBuilder::Impl::AddPartitionSpec(const PartitionSpec
613613
// is now the last)
614614
bool is_new_spec =
615615
last_added_spec_id_.has_value() &&
616-
std::ranges::find_if(changes_, [new_spec_id](const auto& change) {
616+
std::ranges::any_of(changes_, [new_spec_id](const auto& change) {
617617
return change->kind() == TableUpdate::Kind::kAddPartitionSpec &&
618618
internal::checked_cast<const table::AddPartitionSpec&>(*change)
619619
.spec()
620620
->spec_id() == new_spec_id;
621-
}) != changes_.cend();
621+
});
622622
last_added_spec_id_ = is_new_spec ? std::make_optional(new_spec_id) : std::nullopt;
623623
return new_spec_id;
624624
}

src/iceberg/util/snapshot_util.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Result<std::optional<std::shared_ptr<Snapshot>>> SnapshotUtil::OldestAncestorAft
124124
}
125125

126126
// the first ancestor after the given time can't be determined
127-
return NotFound("Cannot find snapshot older than {}", FormatTimestamp(timestamp_ms));
127+
return NotFound("Cannot find snapshot older than {}", FormatTimePointMs(timestamp_ms));
128128
}
129129

130130
Result<std::vector<int64_t>> SnapshotUtil::SnapshotIdsBetween(const Table& table,
@@ -232,7 +232,7 @@ Result<int64_t> SnapshotUtil::SnapshotIdAsOfTime(const Table& table,
232232
TimePointMs timestamp_ms) {
233233
auto snapshot_id = OptionalSnapshotIdAsOfTime(table, timestamp_ms);
234234
ICEBERG_CHECK(snapshot_id.has_value(), "Cannot find a snapshot older than {}",
235-
FormatTimestamp(timestamp_ms));
235+
FormatTimePointMs(timestamp_ms));
236236
return snapshot_id.value();
237237
}
238238

src/iceberg/util/timepoint.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,9 @@ int64_t UnixNsFromTimePointNs(TimePointNs time_point_ns) {
4545
.count();
4646
}
4747

48-
std::string FormatTimestamp(TimePointMs time_point_ns) {
49-
// Convert TimePointMs to system_clock::time_point
50-
auto unix_ms = UnixMsFromTimePointMs(time_point_ns);
51-
auto time_point =
52-
std::chrono::system_clock::time_point(std::chrono::milliseconds(unix_ms));
53-
auto time_t = std::chrono::system_clock::to_time_t(time_point);
48+
std::string FormatTimePointMs(TimePointMs time_point_ms) {
49+
auto unix_ms = UnixMsFromTimePointMs(time_point_ms);
50+
auto time_t = std::chrono::system_clock::to_time_t(time_point_ms);
5451

5552
// Format as ISO 8601-like string: YYYY-MM-DD HH:MM:SS
5653
std::ostringstream oss;

src/iceberg/util/timepoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ ICEBERG_EXPORT Result<TimePointNs> TimePointNsFromUnixNs(int64_t unix_ns);
4747
ICEBERG_EXPORT int64_t UnixNsFromTimePointNs(TimePointNs time_point_ns);
4848

4949
/// \brief Returns a human-readable string representation of a TimePointMs
50-
ICEBERG_EXPORT std::string FormatTimestamp(TimePointMs time_point_ns);
50+
ICEBERG_EXPORT std::string FormatTimePointMs(TimePointMs time_point_ms);
5151

5252
} // namespace iceberg

0 commit comments

Comments
 (0)