Skip to content

Commit 1132ef5

Browse files
committed
Fix some logic for using datum
1 parent e1dd11d commit 1132ef5

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/iceberg/datum.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,12 @@ std::partial_ordering PrimitiveLiteral::operator<=>(const PrimitiveLiteral& othe
199199
return std::partial_ordering::unordered;
200200
}
201201

202-
// Same type comparison
202+
// If either value is AboveMax or BelowMin, comparison is unordered
203+
if (isAboveMax() || isBelowMin() || other.isAboveMax() || other.isBelowMin()) {
204+
return std::partial_ordering::unordered;
205+
}
206+
207+
// Same type comparison for normal values
203208
switch (type_->type_id()) {
204209
case TypeId::kBoolean: {
205210
auto this_val = std::get<bool>(value_);
@@ -303,4 +308,11 @@ std::string PrimitiveLiteral::ToString() const {
303308
}
304309
}
305310

311+
bool PrimitiveLiteral::isBelowMin() const {
312+
return std::holds_alternative<BelowMin>(value_);
313+
}
314+
315+
bool PrimitiveLiteral::isAboveMax() const {
316+
return std::holds_alternative<AboveMax>(value_);
317+
}
306318
} // namespace iceberg

src/iceberg/datum.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,33 @@ class ICEBERG_EXPORT PrimitiveLiteral {
8888
/// Get the Iceberg Type of the literal
8989
const std::shared_ptr<PrimitiveType>& type() const;
9090

91-
/// Cast the literal to a specific type
91+
/// Converts this literal to a literal of the given type.
92+
///
93+
/// When a predicate is bound to a concrete data column, literals are converted to match
94+
/// the bound column's type. This conversion process is more narrow than a cast and is
95+
/// only intended for cases where substituting one type is a common mistake (e.g. 34
96+
/// instead of 34L) or where this API avoids requiring a concrete class (e.g., dates).
97+
///
98+
/// If conversion to a target type is not supported, this method returns an error.
99+
///
100+
/// This method may return BelowMin or AboveMax when the target type is not as wide as
101+
/// 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.
104+
///
105+
/// @param target_type A primitive PrimitiveType
106+
/// @return A Result containing a literal of the given type or an error if conversion
107+
/// was not valid
92108
Result<PrimitiveLiteral> CastTo(
93109
const std::shared_ptr<PrimitiveType>& target_type) const;
94110

111+
/// Compare two PrimitiveLiterals. Both literals must have the same type
112+
/// and should not be AboveMax or BelowMin.
95113
std::partial_ordering operator<=>(const PrimitiveLiteral& other) const;
96114

115+
bool isAboveMax() const;
116+
bool isBelowMin() const;
117+
97118
std::string ToString() const;
98119

99120
private:

0 commit comments

Comments
 (0)