Fix group by inf and nan duplicated (#2142 #2145) (#2401)

This commit is contained in:
yangzhg
2019-12-06 16:19:08 +08:00
committed by ZHAO Chun
parent 597a8b2146
commit 8e2277d997
2 changed files with 13 additions and 4 deletions

View File

@ -17,8 +17,7 @@
#include "exprs/cast_functions.h"
#include <math.h>
#include <boost/lexical_cast.hpp>
#include <cmath>
#include "exprs/anyval_util.h"
#include "runtime/datetime_value.h"
@ -113,7 +112,9 @@ CAST_FUNCTION(FloatVal, DoubleVal, double_val)
num_type ret; \
ret.val = StringParser::string_parser_fn<native_type>( \
reinterpret_cast<char*>(val.ptr), val.len, &result); \
if (UNLIKELY(result != StringParser::PARSE_SUCCESS)) return num_type::null(); \
if (UNLIKELY(result != StringParser::PARSE_SUCCESS || std::isnan(ret.val) || std::isinf(ret.val))) { \
return num_type::null(); \
} \
return ret; \
}

View File

@ -362,6 +362,9 @@ public class FEFunctions {
@FEFunction(name = "divide", argTypes = { "DOUBLE", "DOUBLE" }, returnType = "DOUBLE")
public static FloatLiteral divideDouble(LiteralExpr first, LiteralExpr second) throws AnalysisException {
if (second.getDoubleValue() == 0.0) {
return null;
}
double result = first.getDoubleValue() / second.getDoubleValue();
return new FloatLiteral(result, Type.DOUBLE);
}
@ -370,6 +373,9 @@ public class FEFunctions {
public static DecimalLiteral divideDecimal(LiteralExpr first, LiteralExpr second) throws AnalysisException {
BigDecimal left = new BigDecimal(first.getStringValue());
BigDecimal right = new BigDecimal(second.getStringValue());
if (right.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
BigDecimal result = left.divide(right);
return new DecimalLiteral(result);
}
@ -378,7 +384,9 @@ public class FEFunctions {
public static DecimalLiteral divideDecimalV2(LiteralExpr first, LiteralExpr second) throws AnalysisException {
BigDecimal left = new BigDecimal(first.getStringValue());
BigDecimal right = new BigDecimal(second.getStringValue());
if (right.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
BigDecimal result = left.divide(right);
return new DecimalLiteral(result);
}