diff --git a/be/src/runtime/raw-value.cc b/be/src/runtime/raw-value.cc index ffdc924..0316414 100644 --- a/be/src/runtime/raw-value.cc +++ b/be/src/runtime/raw-value.cc @@ -186,11 +186,17 @@ int RawValue::Compare(const void* v1, const void* v2, PrimitiveType type) { // TODO: can this be faster? (just returning the difference has underflow problems) f1 = *reinterpret_cast(v1); f2 = *reinterpret_cast(v2); + if (isnan(f1) && isnan(f2)) return 0; + if (isnan(f1)) return -1; + if (isnan(f2)) return 1; return f1 > f2 ? 1 : (f1 < f2 ? -1 : 0); case TYPE_DOUBLE: // TODO: can this be faster? d1 = *reinterpret_cast(v1); d2 = *reinterpret_cast(v2); + if (isnan(d1) && isnan(d2)) return 0; + if (isnan(d1)) return -1; + if (isnan(d2)) return 1; return d1 > d2 ? 1 : (d1 < d2 ? -1 : 0); case TYPE_STRING: string_value1 = reinterpret_cast(v1); diff --git a/testdata/workloads/functional-query/queries/QueryTest/top-n.test b/testdata/workloads/functional-query/queries/QueryTest/top-n.test index bdb28ea..69569de 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/top-n.test +++ b/testdata/workloads/functional-query/queries/QueryTest/top-n.test @@ -679,3 +679,35 @@ bigint ---- RESULTS NULL ==== +---- QUERY +# Test queries with divide by 0 +select if(id % 2 = 0, id, -id) / if(id < 5, 0, 1) as v +from alltypestiny order by v desc limit 100; +---- TYPES +DOUBLE +---- RESULTS +inf +inf +6 +-5 +-7 +-inf +-inf +-nan +==== +---- QUERY +# Test queries with divide by 0 +select if(id % 2 = 0, id, -id) / if(id < 5, 0, 1) as v +from alltypestiny order by v asc limit 100; +---- TYPES +DOUBLE +---- RESULTS +-nan +-inf +-inf +-7 +-5 +6 +inf +inf +====