@@ -339,7 +339,8 @@ Result<int32_t> Literal::CompareTo(const Literal& other) const {
339339 case FieldType::BINARY : {
340340 std::string_view v1 (impl_->value_ .Buffer , impl_->size_ );
341341 std::string_view v2 (other.impl_ ->value_ .Buffer , other.impl_ ->size_ );
342- return (*this == other) ? 0 : (v1 < v2 ? -1 : 1 );
342+ int32_t cmp = v1.compare (v2);
343+ return cmp < 0 ? -1 : (cmp > 0 ? 1 : 0 );
343344 }
344345 case FieldType::TIMESTAMP :
345346 return impl_->value_ .TimestampVal == other.impl_ ->value_ .TimestampVal
@@ -361,65 +362,11 @@ bool Literal::operator==(const Literal& other) const {
361362 if (this == &other) {
362363 return true ;
363364 }
364- if (GetType () != other.GetType () || IsNull () != other.IsNull ()) {
365+ auto result = CompareTo (other);
366+ if (!result.ok ()) {
365367 return false ;
366368 }
367- if (IsNull ()) {
368- return true ;
369- }
370- if (GetType () != FieldType::FLOAT && GetType () != FieldType::DOUBLE &&
371- HashCode () != other.HashCode ()) {
372- return false ;
373- }
374- switch (GetType ()) {
375- case FieldType::BOOLEAN :
376- return impl_->value_ .BooleanVal == other.impl_ ->value_ .BooleanVal ;
377- case FieldType::TINYINT :
378- return impl_->value_ .TinyIntVal == other.impl_ ->value_ .TinyIntVal ;
379- case FieldType::SMALLINT :
380- return impl_->value_ .SmallIntVal == other.impl_ ->value_ .SmallIntVal ;
381- case FieldType::INT :
382- return impl_->value_ .IntVal == other.impl_ ->value_ .IntVal ;
383- case FieldType::BIGINT :
384- return impl_->value_ .BigIntVal == other.impl_ ->value_ .BigIntVal ;
385- case FieldType::FLOAT : {
386- if (std::isnan (impl_->value_ .FloatVal ) && std::isnan (other.impl_ ->value_ .FloatVal )) {
387- return true ;
388- }
389- if (impl_->value_ .FloatVal == INFINITY && other.impl_ ->value_ .FloatVal == INFINITY ) {
390- return true ;
391- }
392- if (impl_->value_ .FloatVal == -INFINITY && other.impl_ ->value_ .FloatVal == -INFINITY ) {
393- return true ;
394- }
395- return std::fabs (impl_->value_ .FloatVal - other.impl_ ->value_ .FloatVal ) < 1E-5 ;
396- }
397- case FieldType::DOUBLE : {
398- if (std::isnan (impl_->value_ .DoubleVal ) && std::isnan (other.impl_ ->value_ .DoubleVal )) {
399- return true ;
400- }
401- if (impl_->value_ .DoubleVal == INFINITY && other.impl_ ->value_ .DoubleVal == INFINITY ) {
402- return true ;
403- }
404- if (impl_->value_ .DoubleVal == -INFINITY &&
405- other.impl_ ->value_ .DoubleVal == -INFINITY ) {
406- return true ;
407- }
408- return std::fabs (impl_->value_ .DoubleVal - other.impl_ ->value_ .DoubleVal ) < 1E-5 ;
409- }
410- case FieldType::STRING :
411- case FieldType::BINARY :
412- return impl_->size_ == other.impl_ ->size_ &&
413- memcmp (impl_->value_ .Buffer , other.impl_ ->value_ .Buffer , impl_->size_ ) == 0 ;
414- case FieldType::TIMESTAMP :
415- return impl_->value_ .TimestampVal == other.impl_ ->value_ .TimestampVal ;
416- case FieldType::DECIMAL :
417- return impl_->value_ .DecimalVal == other.impl_ ->value_ .DecimalVal ;
418- case FieldType::DATE :
419- return impl_->value_ .IntVal == other.impl_ ->value_ .IntVal ;
420- default :
421- return false ;
422- }
369+ return result.value () == 0 ;
423370}
424371
425372bool Literal::operator !=(const Literal& r) const {
0 commit comments