Skip to content

Commit 07dd257

Browse files
committed
Resolve some comments, and remove castFromDouble
1 parent 1eb9a9b commit 07dd257

File tree

2 files changed

+12
-32
lines changed

2 files changed

+12
-32
lines changed

src/iceberg/literal.cc

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@ Result<PrimitiveLiteral> PrimitiveLiteral::CastTo(
106106
case TypeId::kFloat:
107107
return CastFromFloat(target_type_id);
108108
case TypeId::kDouble:
109-
return CastFromDouble(target_type_id);
110109
case TypeId::kBoolean:
111110
case TypeId::kString:
112111
case TypeId::kBinary:
113-
// These types only support conversion to string (handled above)
114112
break;
115113
default:
116114
break;
@@ -173,25 +171,6 @@ Result<PrimitiveLiteral> PrimitiveLiteral::CastFromFloat(TypeId target_type_id)
173171
}
174172
}
175173

176-
Result<PrimitiveLiteral> PrimitiveLiteral::CastFromDouble(TypeId target_type_id) const {
177-
auto double_val = std::get<double>(value_);
178-
179-
switch (target_type_id) {
180-
case TypeId::kFloat: {
181-
if (double_val > std::numeric_limits<float>::max()) {
182-
return PrimitiveLiteral::AboveMaxLiteral(type_);
183-
}
184-
if (double_val < std::numeric_limits<float>::lowest()) {
185-
return PrimitiveLiteral::BelowMinLiteral(type_);
186-
}
187-
return PrimitiveLiteral::Float(static_cast<float>(double_val));
188-
}
189-
default:
190-
return NotSupported("Cast from Double to {} is not implemented",
191-
static_cast<int>(target_type_id));
192-
}
193-
}
194-
195174
// Three-way comparison operator
196175
std::partial_ordering PrimitiveLiteral::operator<=>(const PrimitiveLiteral& other) const {
197176
// If types are different, comparison is unordered

src/iceberg/literal.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030

3131
namespace iceberg {
3232

33-
/// \brief PrimitiveLiteral is owned literal of a primitive type.
33+
/// \brief PrimitiveLiteral is a literal value that is associated with a primitive type.
3434
class ICEBERG_EXPORT PrimitiveLiteral {
3535
private:
3636
/// \brief Exception type for values that are below the minimum allowed value for a
3737
/// primitive type.
3838
///
3939
/// When casting a value to a narrow primitive type, if the value exceeds the maximum of
40-
/// dest type, it might be above the maximum allowed value for that type.
40+
/// target type, it might be above the maximum allowed value for that type.
4141
struct BelowMin {
4242
bool operator==(const BelowMin&) const = default;
4343
std::strong_ordering operator<=>(const BelowMin&) const = default;
@@ -47,7 +47,7 @@ class ICEBERG_EXPORT PrimitiveLiteral {
4747
/// primitive type.
4848
///
4949
/// When casting a value to a narrow primitive type, if the value exceeds the maximum of
50-
/// dest type, it might be above the maximum allowed value for that type.
50+
/// target type, it might be above the maximum allowed value for that type.
5151
struct AboveMax {
5252
bool operator==(const AboveMax&) const = default;
5353
std::strong_ordering operator<=>(const AboveMax&) const = default;
@@ -74,18 +74,19 @@ class ICEBERG_EXPORT PrimitiveLiteral {
7474
static PrimitiveLiteral String(std::string value);
7575
static PrimitiveLiteral Binary(std::vector<uint8_t> value);
7676

77-
/// Create iceberg value from bytes.
77+
/// Create iceberg literal from bytes.
7878
///
7979
/// See [this spec](https://iceberg.apache.org/spec/#binary-single-value-serialization)
8080
/// for reference.
8181
static Result<PrimitiveLiteral> Deserialize(std::span<const uint8_t> data);
82-
/// Serialize iceberg value to bytes.
82+
83+
/// Serialize iceberg literal to bytes.
8384
///
8485
/// See [this spec](https://iceberg.apache.org/spec/#binary-single-value-serialization)
8586
/// for reference.
8687
Result<std::vector<uint8_t>> Serialize() const;
8788

88-
/// Get the Iceberg Type of the literal
89+
/// Get the Iceberg Type of the literal.
8990
const std::shared_ptr<PrimitiveType>& type() const;
9091

9192
/// Converts this literal to a literal of the given type.
@@ -99,11 +100,12 @@ class ICEBERG_EXPORT PrimitiveLiteral {
99100
///
100101
/// This method may return BelowMin or AboveMax when the target type is not as wide as
101102
/// the original type. These values indicate that the containing predicate can be
102-
/// simplified. For example, Integer.MAX_VALUE+1 converted to an int will result in
103-
/// AboveMax and can simplify a < Integer.MAX_VALUE+1 to always true.
103+
/// simplified. For example, std::numeric_limits<int>::max()+1 converted to an int will
104+
/// result in AboveMax and can simplify a < std::numeric_limits<int>::max()+1 to always
105+
/// true.
104106
///
105-
/// @param target_type A primitive PrimitiveType
106-
/// @return A Result containing a literal of the given type or an error if conversion
107+
/// \param target_type A primitive PrimitiveType
108+
/// \return A Result containing a literal of the given type or an error if conversion
107109
/// was not valid
108110
Result<PrimitiveLiteral> CastTo(
109111
const std::shared_ptr<PrimitiveType>& target_type) const;
@@ -127,7 +129,6 @@ class ICEBERG_EXPORT PrimitiveLiteral {
127129
Result<PrimitiveLiteral> CastFromInt(TypeId target_type_id) const;
128130
Result<PrimitiveLiteral> CastFromLong(TypeId target_type_id) const;
129131
Result<PrimitiveLiteral> CastFromFloat(TypeId target_type_id) const;
130-
Result<PrimitiveLiteral> CastFromDouble(TypeId target_type_id) const;
131132

132133
private:
133134
PrimitiveLiteralValue value_;

0 commit comments

Comments
 (0)