Skip to content

Commit f1b0711

Browse files
committed
fix: more review comments
1 parent 570060e commit f1b0711

2 files changed

Lines changed: 31 additions & 34 deletions

File tree

src/iceberg/type.cc

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -367,21 +367,21 @@ GeometryType::GeometryType(std::string crs) {
367367
}
368368

369369
std::string_view GeometryType::crs() const {
370-
return crs_.has_value() ? std::string_view(*crs_) : kDefaultCrs;
370+
return crs_.empty() ? kDefaultCrs : std::string_view(crs_);
371371
}
372372
TypeId GeometryType::type_id() const { return kTypeId; }
373373
std::string GeometryType::ToString() const {
374-
if (!crs_.has_value()) {
374+
if (crs_.empty()) {
375375
return "geometry";
376376
}
377-
return std::format("geometry({})", *crs_);
377+
return std::format("geometry({})", crs_);
378378
}
379379
bool GeometryType::Equals(const Type& other) const {
380380
if (other.type_id() != kTypeId) {
381381
return false;
382382
}
383383
const auto& geometry = static_cast<const GeometryType&>(other);
384-
return crs() == geometry.crs();
384+
return crs_ == geometry.crs_;
385385
}
386386

387387
GeographyType::GeographyType(std::string crs) {
@@ -400,18 +400,16 @@ GeographyType::GeographyType(std::string crs, EdgeAlgorithm algorithm)
400400
}
401401

402402
std::string_view GeographyType::crs() const {
403-
return crs_.has_value() ? std::string_view(*crs_) : kDefaultCrs;
404-
}
405-
EdgeAlgorithm GeographyType::algorithm() const {
406-
return algorithm_.value_or(kDefaultAlgorithm);
403+
return crs_.empty() ? kDefaultCrs : std::string_view(crs_);
407404
}
405+
EdgeAlgorithm GeographyType::algorithm() const { return algorithm_; }
408406
TypeId GeographyType::type_id() const { return kTypeId; }
409407
std::string GeographyType::ToString() const {
410-
if (algorithm_.has_value()) {
411-
return std::format("geography({}, {})", crs(), iceberg::ToString(*algorithm_));
408+
if (algorithm_ != kDefaultAlgorithm) {
409+
return std::format("geography({}, {})", crs(), iceberg::ToString(algorithm_));
412410
}
413-
if (crs_.has_value()) {
414-
return std::format("geography({})", *crs_);
411+
if (!crs_.empty()) {
412+
return std::format("geography({})", crs_);
415413
}
416414
return "geography";
417415
}
@@ -420,7 +418,7 @@ bool GeographyType::Equals(const Type& other) const {
420418
return false;
421419
}
422420
const auto& geography = static_cast<const GeographyType&>(other);
423-
return crs() == geography.crs() && algorithm() == geography.algorithm();
421+
return crs_ == geography.crs_ && algorithm_ == geography.algorithm_;
424422
}
425423

426424
FixedType::FixedType(int32_t length) : length_(length) {

src/iceberg/type.h

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ class ICEBERG_EXPORT Type : public iceberg::util::Formattable {
4646
~Type() override = default;
4747

4848
/// \brief Get the type ID.
49-
[[nodiscard]] virtual TypeId type_id() const = 0;
49+
virtual TypeId type_id() const = 0;
5050

5151
/// \brief Is this a primitive type (may not have child fields)?
52-
[[nodiscard]] virtual bool is_primitive() const = 0;
52+
virtual bool is_primitive() const = 0;
5353

5454
/// \brief Is this a nested type (may have child fields)?
55-
[[nodiscard]] virtual bool is_nested() const = 0;
55+
virtual bool is_nested() const = 0;
5656

5757
/// \brief Compare two types for equality.
5858
friend bool operator==(const Type& lhs, const Type& rhs) { return lhs.Equals(rhs); }
5959

6060
protected:
6161
/// \brief Compare two types for equality.
62-
[[nodiscard]] virtual bool Equals(const Type& other) const = 0;
62+
virtual bool Equals(const Type& other) const = 0;
6363
};
6464

6565
/// \brief A data type that does not have child fields.
@@ -76,28 +76,27 @@ class ICEBERG_EXPORT NestedType : public Type {
7676
bool is_nested() const override { return true; }
7777

7878
/// \brief Get a view of the child fields.
79-
[[nodiscard]] virtual std::span<const SchemaField> fields() const = 0;
79+
virtual std::span<const SchemaField> fields() const = 0;
8080
using SchemaFieldConstRef = std::reference_wrapper<const SchemaField>;
8181
/// \brief Get a field by field ID.
8282
///
8383
/// \note This is O(1) complexity.
84-
[[nodiscard]] virtual Result<std::optional<SchemaFieldConstRef>> GetFieldById(
84+
virtual Result<std::optional<SchemaFieldConstRef>> GetFieldById(
8585
int32_t field_id) const = 0;
8686
/// \brief Get a field by index.
8787
///
8888
/// \note This is O(1) complexity.
89-
[[nodiscard]] virtual Result<std::optional<SchemaFieldConstRef>> GetFieldByIndex(
89+
virtual Result<std::optional<SchemaFieldConstRef>> GetFieldByIndex(
9090
int32_t index) const = 0;
9191
/// \brief Get a field by name. Return an error Status if
9292
/// the field name is not unique; prefer GetFieldById or GetFieldByIndex
9393
/// when possible.
9494
///
9595
/// \note This is O(1) complexity.
96-
[[nodiscard]] virtual Result<std::optional<SchemaFieldConstRef>> GetFieldByName(
96+
virtual Result<std::optional<SchemaFieldConstRef>> GetFieldByName(
9797
std::string_view name, bool case_sensitive) const = 0;
9898
/// \brief Get a field by name (case-sensitive).
99-
[[nodiscard]] Result<std::optional<SchemaFieldConstRef>> GetFieldByName(
100-
std::string_view name) const;
99+
Result<std::optional<SchemaFieldConstRef>> GetFieldByName(std::string_view name) const;
101100
};
102101

103102
/// \defgroup type-nested Nested Types
@@ -324,10 +323,10 @@ class ICEBERG_EXPORT DecimalType : public PrimitiveType {
324323
~DecimalType() override = default;
325324

326325
/// \brief Get the precision (the number of decimal digits).
327-
[[nodiscard]] int32_t precision() const;
326+
int32_t precision() const;
328327
/// \brief Get the scale (essentially, the number of decimal digits after
329328
/// the decimal point; precisely, the value is scaled by $$10^{-s}$$.).
330-
[[nodiscard]] int32_t scale() const;
329+
int32_t scale() const;
331330

332331
TypeId type_id() const override;
333332
std::string ToString() const override;
@@ -377,9 +376,9 @@ class ICEBERG_EXPORT TimeType : public PrimitiveType {
377376
class ICEBERG_EXPORT TimestampBase : public PrimitiveType {
378377
public:
379378
/// \brief Is this type zoned or naive?
380-
[[nodiscard]] virtual bool is_zoned() const = 0;
379+
virtual bool is_zoned() const = 0;
381380
/// \brief The time resolution.
382-
[[nodiscard]] virtual TimeUnit time_unit() const = 0;
381+
virtual TimeUnit time_unit() const = 0;
383382
};
384383

385384
/// \brief A data type representing a timestamp in microseconds without
@@ -499,7 +498,7 @@ class ICEBERG_EXPORT FixedType : public PrimitiveType {
499498
~FixedType() override = default;
500499

501500
/// \brief The length (the number of bytes to store).
502-
[[nodiscard]] int32_t length() const;
501+
int32_t length() const;
503502

504503
TypeId type_id() const override;
505504
std::string ToString() const override;
@@ -552,7 +551,7 @@ class ICEBERG_EXPORT GeometryType : public PrimitiveType {
552551
explicit GeometryType(std::string crs);
553552
~GeometryType() override = default;
554553

555-
[[nodiscard]] std::string_view crs() const;
554+
std::string_view crs() const;
556555

557556
TypeId type_id() const override;
558557
std::string ToString() const override;
@@ -561,7 +560,7 @@ class ICEBERG_EXPORT GeometryType : public PrimitiveType {
561560
bool Equals(const Type& other) const override;
562561

563562
private:
564-
std::optional<std::string> crs_;
563+
std::string crs_;
565564
};
566565

567566
/// \brief A data type representing OGC geography in WKB format.
@@ -576,8 +575,8 @@ class ICEBERG_EXPORT GeographyType : public PrimitiveType {
576575
GeographyType(std::string crs, EdgeAlgorithm algorithm);
577576
~GeographyType() override = default;
578577

579-
[[nodiscard]] std::string_view crs() const;
580-
[[nodiscard]] EdgeAlgorithm algorithm() const;
578+
std::string_view crs() const;
579+
EdgeAlgorithm algorithm() const;
581580

582581
TypeId type_id() const override;
583582
std::string ToString() const override;
@@ -586,8 +585,8 @@ class ICEBERG_EXPORT GeographyType : public PrimitiveType {
586585
bool Equals(const Type& other) const override;
587586

588587
private:
589-
std::optional<std::string> crs_;
590-
std::optional<EdgeAlgorithm> algorithm_;
588+
std::string crs_;
589+
EdgeAlgorithm algorithm_ = kDefaultAlgorithm;
591590
};
592591

593592
/// @}

0 commit comments

Comments
 (0)