Skip to content

Commit a51ffa7

Browse files
author
yuryalekseev
committed
YT-20113: Fix comparision of doubles when nans are present.
0adadb02b41252223fd3101d25ecbc969d523131
1 parent 5fe5402 commit a51ffa7

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

yt/yt/client/table_client/composite_compare.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,25 @@ i64 GetMinResultingSize(const TYsonItem& item, bool isInsideList)
215215

216216
} // namespace
217217

218+
int CompareDoubleValues(double lhs, double rhs)
219+
{
220+
if (lhs < rhs) {
221+
return -1;
222+
} else if (lhs > rhs) {
223+
return +1;
224+
} else if (std::isnan(lhs)) {
225+
if (std::isnan(rhs)) {
226+
return 0;
227+
} else {
228+
return 1;
229+
}
230+
} else if (std::isnan(rhs)) {
231+
return -1;
232+
}
233+
234+
return 0;
235+
}
236+
218237
int CompareYsonValues(TYsonStringBuf lhs, TYsonStringBuf rhs)
219238
{
220239
YT_ASSERT(lhs.GetType() == EYsonType::Node);

yt/yt/client/table_client/composite_compare.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace NYT::NTableClient {
1010

1111
////////////////////////////////////////////////////////////////////////////////
1212

13+
int CompareDoubleValues(double lhs, double rhs);
1314
int CompareYsonValues(NYson::TYsonStringBuf lhs, NYson::TYsonStringBuf rhs);
1415
TFingerprint CompositeFarmHash(NYson::TYsonStringBuf compositeValue);
1516

yt/yt/client/table_client/unversioned_row.cpp

+1-17
Original file line numberDiff line numberDiff line change
@@ -395,23 +395,7 @@ int CompareRowValues(const TUnversionedValue& lhs, const TUnversionedValue& rhs)
395395
}
396396

397397
case EValueType::Double: {
398-
double lhsValue = lhs.Data.Double;
399-
double rhsValue = rhs.Data.Double;
400-
if (lhsValue < rhsValue) {
401-
return -1;
402-
} else if (lhsValue > rhsValue) {
403-
return +1;
404-
} else if (std::isnan(lhsValue)) {
405-
if (std::isnan(rhsValue)) {
406-
return 0;
407-
} else {
408-
return 1;
409-
}
410-
} else if (std::isnan(rhsValue)) {
411-
return -1;
412-
} else {
413-
return 0;
414-
}
398+
return CompareDoubleValues(lhs.Data.Double, rhs.Data.Double);
415399
}
416400

417401
case EValueType::Boolean: {

0 commit comments

Comments
 (0)