Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/iceberg/expression/literal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ bool Literal::operator==(const Literal& other) const { return (*this <=> other)
// Three-way comparison operator
std::partial_ordering Literal::operator<=>(const Literal& other) const {
// If types are different, comparison is unordered
if (*type_ != *other.type_) {
if (type_->type_id() != other.type_->type_id()) {
return std::partial_ordering::unordered;
}

Expand Down
9 changes: 7 additions & 2 deletions src/iceberg/expression/literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <variant>
#include <vector>

#include "iceberg/iceberg_export.h"
#include "iceberg/result.h"
#include "iceberg/type.h"
#include "iceberg/util/decimal.h"
Expand Down Expand Up @@ -129,8 +130,12 @@ class ICEBERG_EXPORT Literal : public util::Formattable {

bool operator==(const Literal& other) const;

/// \brief Compare two PrimitiveLiterals. Both literals must have the same type
/// and should not be AboveMax or BelowMin.
/// \brief Compare two literals of the same primitive type.
/// \param other The other literal to compare with.
/// \return The comparison result as std::partial_ordering. If either side is AboveMax,
/// BelowMin or Null, the result is unordered.
/// Note: This comparison cannot be used for sorting literals if any literal is
/// AboveMax, BelowMin or Null.
std::partial_ordering operator<=>(const Literal& other) const;

/// Check if this literal represents a value above the maximum allowed value
Expand Down
14 changes: 14 additions & 0 deletions src/iceberg/test/literal_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ INSTANTIATE_TEST_SUITE_P(
.small_literal = Literal::Decimal(123456, 6, 2),
.large_literal = Literal::Decimal(234567, 6, 2),
.equal_literal = Literal::Decimal(123456, 6, 2)},
ComparisonLiteralTestParam{.test_name = "DecimalDifferentScales",
.small_literal = Literal::Decimal(123456, 6, 2),
.large_literal = Literal::Decimal(1234567, 7, 3),
.equal_literal = Literal::Decimal(1234560, 7, 3)},
ComparisonLiteralTestParam{.test_name = "String",
.small_literal = Literal::String("apple"),
.large_literal = Literal::String("banana"),
Expand All @@ -620,11 +624,21 @@ INSTANTIATE_TEST_SUITE_P(
.small_literal = Literal::Binary(std::vector<uint8_t>{0x01, 0x02}),
.large_literal = Literal::Binary(std::vector<uint8_t>{0x01, 0x03}),
.equal_literal = Literal::Binary(std::vector<uint8_t>{0x01, 0x02})},
ComparisonLiteralTestParam{
.test_name = "BinaryDifferentLengths",
.small_literal = Literal::Binary(std::vector<uint8_t>{0x01, 0x02}),
.large_literal = Literal::Binary(std::vector<uint8_t>{0x01, 0x02, 0x03}),
.equal_literal = Literal::Binary(std::vector<uint8_t>{0x01, 0x02})},
ComparisonLiteralTestParam{
.test_name = "Fixed",
.small_literal = Literal::Fixed(std::vector<uint8_t>{0x01, 0x02}),
.large_literal = Literal::Fixed(std::vector<uint8_t>{0x01, 0x03}),
.equal_literal = Literal::Fixed(std::vector<uint8_t>{0x01, 0x02})},
ComparisonLiteralTestParam{
.test_name = "FixedDifferentLengths",
.small_literal = Literal::Fixed(std::vector<uint8_t>{0x01, 0x02}),
.large_literal = Literal::Fixed(std::vector<uint8_t>{0x01, 0x02, 0x03}),
.equal_literal = Literal::Fixed(std::vector<uint8_t>{0x01, 0x02})},
ComparisonLiteralTestParam{.test_name = "Date",
.small_literal = Literal::Date(100),
.large_literal = Literal::Date(200),
Expand Down
Loading