Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
LiBinfeng-01 committed Sep 19, 2024
1 parent 4ee3479 commit a9df5e8
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public String getStringValueInFe(FormatOptions options) {
String timeStr = getStringValue();
return timeStr.substring(1, timeStr.length() - 1);
} else {
if (Double.isInfinite(getValue())) {
return Double.toString(getValue());
}
return BigDecimal.valueOf(getValue()).toPlainString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static Expression abs(FloatLiteral literal) {

@ExecFunction(name = "abs")
public static Expression abs(DoubleLiteral literal) {
return new DoubleLiteral(Math.abs(literal.getValue()));
return filterNanResult(new DoubleLiteral(Math.abs(literal.getValue())));
}

@ExecFunction(name = "abs")
Expand Down Expand Up @@ -248,7 +248,7 @@ public static Expression addLargeIntLargeInt(LargeIntLiteral first, LargeIntLite
@ExecFunction(name = "add")
public static Expression addDoubleDouble(DoubleLiteral first, DoubleLiteral second) {
double result = first.getValue() + second.getValue();
return new DoubleLiteral(result);
return filterNanResult(new DoubleLiteral(result));
}

@ExecFunction(name = "add")
Expand Down Expand Up @@ -419,7 +419,7 @@ public static Expression subtractLargeIntLargeInt(LargeIntLiteral first, LargeIn
@ExecFunction(name = "subtract")
public static Expression subtractDoubleDouble(DoubleLiteral first, DoubleLiteral second) {
double result = first.getValue() - second.getValue();
return new DoubleLiteral(result);
return filterNanResult(new DoubleLiteral(result));
}

@ExecFunction(name = "subtract")
Expand Down Expand Up @@ -590,7 +590,7 @@ public static Expression multiplyLargeIntLargeInt(LargeIntLiteral first, LargeIn
@ExecFunction(name = "multiply")
public static Expression multiplyDoubleDouble(DoubleLiteral first, DoubleLiteral second) {
double result = first.getValue() * second.getValue();
return new DoubleLiteral(result);
return filterNanResult(new DoubleLiteral(result));
}

@ExecFunction(name = "multiply")
Expand Down Expand Up @@ -621,7 +621,7 @@ public static Expression divideDouble(DoubleLiteral first, DoubleLiteral second)
return new NullLiteral(first.getDataType());
}
double result = first.getValue() / second.getValue();
return new DoubleLiteral(result);
return filterNanResult(new DoubleLiteral(result));
}

/**
Expand Down Expand Up @@ -667,6 +667,15 @@ public static Expression coalesce(Literal first, Literal... second) {
return first;
}

private static Expression filterNanResult(Literal input) {
if (input instanceof DoubleLiteral) {
if (((DoubleLiteral) input).getValue().isNaN()) {
return new NullLiteral(input.getDataType());
}
}
return input;
}

/**
* round
*/
Expand All @@ -680,9 +689,6 @@ public static Expression round(DecimalV3Literal first) {
*/
@ExecFunction(name = "round")
public static Expression round(DecimalV3Literal first, IntegerLiteral second) {
if (second.getValue() >= first.getValue().scale()) {
return first;
}
return first.round(second.getValue());
}

Expand All @@ -692,7 +698,7 @@ public static Expression round(DecimalV3Literal first, IntegerLiteral second) {
@ExecFunction(name = "round")
public static Expression round(DoubleLiteral first) {
DecimalV3Literal middleResult = new DecimalV3Literal(new BigDecimal(Double.toString(first.getValue())));
return new DoubleLiteral(middleResult.round(0).getDouble());
return filterNanResult(new DoubleLiteral(middleResult.round(0).getDouble()));
}

/**
Expand All @@ -701,10 +707,7 @@ public static Expression round(DoubleLiteral first) {
@ExecFunction(name = "round")
public static Expression round(DoubleLiteral first, IntegerLiteral second) {
DecimalV3Literal middleResult = new DecimalV3Literal(new BigDecimal(Double.toString(first.getValue())));
if (second.getValue() >= middleResult.getValue().scale()) {
return first;
}
return new DoubleLiteral(middleResult.round(second.getValue()).getDouble());
return filterNanResult(new DoubleLiteral(middleResult.round(second.getValue()).getDouble()));
}

/**
Expand All @@ -720,9 +723,6 @@ public static Expression ceil(DecimalV3Literal first) {
*/
@ExecFunction(name = "ceil")
public static Expression ceil(DecimalV3Literal first, IntegerLiteral second) {
if (second.getValue() >= first.getValue().scale()) {
return first;
}
return first.roundCeiling(second.getValue());
}

Expand All @@ -732,7 +732,7 @@ public static Expression ceil(DecimalV3Literal first, IntegerLiteral second) {
@ExecFunction(name = "ceil")
public static Expression ceil(DoubleLiteral first) {
DecimalV3Literal middleResult = new DecimalV3Literal(new BigDecimal(Double.toString(first.getValue())));
return new DoubleLiteral(middleResult.roundCeiling(0).getDouble());
return filterNanResult(new DoubleLiteral(middleResult.roundCeiling(0).getDouble()));
}

/**
Expand All @@ -741,10 +741,7 @@ public static Expression ceil(DoubleLiteral first) {
@ExecFunction(name = "ceil")
public static Expression ceil(DoubleLiteral first, IntegerLiteral second) {
DecimalV3Literal middleResult = new DecimalV3Literal(new BigDecimal(Double.toString(first.getValue())));
if (second.getValue() >= middleResult.getValue().scale()) {
return first;
}
return new DoubleLiteral(middleResult.roundCeiling(second.getValue()).getDouble());
return filterNanResult(new DoubleLiteral(middleResult.roundCeiling(second.getValue()).getDouble()));
}

/**
Expand All @@ -760,9 +757,6 @@ public static Expression floor(DecimalV3Literal first) {
*/
@ExecFunction(name = "floor")
public static Expression floor(DecimalV3Literal first, IntegerLiteral second) {
if (second.getValue() >= first.getValue().scale()) {
return first;
}
return first.roundFloor(second.getValue());
}

Expand All @@ -772,7 +766,7 @@ public static Expression floor(DecimalV3Literal first, IntegerLiteral second) {
@ExecFunction(name = "floor")
public static Expression floor(DoubleLiteral first) {
DecimalV3Literal middleResult = new DecimalV3Literal(new BigDecimal(Double.toString(first.getValue())));
return new DoubleLiteral(middleResult.roundFloor(0).getDouble());
return filterNanResult(new DoubleLiteral(middleResult.roundFloor(0).getDouble()));
}

/**
Expand All @@ -781,18 +775,15 @@ public static Expression floor(DoubleLiteral first) {
@ExecFunction(name = "floor")
public static Expression floor(DoubleLiteral first, IntegerLiteral second) {
DecimalV3Literal middleResult = new DecimalV3Literal(new BigDecimal(Double.toString(first.getValue())));
if (second.getValue() >= middleResult.getValue().scale()) {
return first;
}
return new DoubleLiteral(middleResult.roundFloor(second.getValue()).getDouble());
return filterNanResult(new DoubleLiteral(middleResult.roundFloor(second.getValue()).getDouble()));
}

/**
* exp
*/
@ExecFunction(name = "exp")
public static Expression exp(DoubleLiteral first) {
return new DoubleLiteral(Math.exp(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.exp(first.getValue())));
}

/**
Expand All @@ -803,7 +794,7 @@ public static Expression ln(DoubleLiteral first) {
if (first.getValue() <= 0) {
return new NullLiteral(first.getDataType());
}
return new DoubleLiteral(Math.log(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.log(first.getValue())));
}

/**
Expand All @@ -814,7 +805,7 @@ public static Expression log(DoubleLiteral first, DoubleLiteral second) {
if (first.getValue() <= 0) {
return new NullLiteral(first.getDataType());
}
return new DoubleLiteral(Math.log(first.getValue()) / Math.log(second.getValue()));
return filterNanResult(new DoubleLiteral(Math.log(first.getValue()) / Math.log(second.getValue())));
}

/**
Expand All @@ -825,7 +816,7 @@ public static Expression log2(DoubleLiteral first) {
if (first.getValue() <= 0) {
return new NullLiteral(first.getDataType());
}
return new DoubleLiteral(Math.log(first.getValue()) / Math.log(2.0));
return filterNanResult(new DoubleLiteral(Math.log(first.getValue()) / Math.log(2.0)));
}

/**
Expand All @@ -836,7 +827,7 @@ public static Expression log10(DoubleLiteral first) {
if (first.getValue() <= 0) {
return new NullLiteral(first.getDataType());
}
return new DoubleLiteral(Math.log10(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.log10(first.getValue())));
}

/**
Expand All @@ -847,39 +838,39 @@ public static Expression sqrt(DoubleLiteral first) {
if (first.getValue() < 0) {
return new NullLiteral(first.getDataType());
}
return new DoubleLiteral(Math.sqrt(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.sqrt(first.getValue())));
}

/**
* power
*/
@ExecFunction(name = "power")
public static Expression power(DoubleLiteral first, DoubleLiteral second) {
return new DoubleLiteral(Math.pow(first.getValue(), second.getValue()));
return filterNanResult(new DoubleLiteral(Math.pow(first.getValue(), second.getValue())));
}

/**
* sin
*/
@ExecFunction(name = "sin")
public static Expression sin(DoubleLiteral first) {
return new DoubleLiteral(Math.sin(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.sin(first.getValue())));
}

/**
* cos
*/
@ExecFunction(name = "cos")
public static Expression cos(DoubleLiteral first) {
return new DoubleLiteral(Math.cos(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.cos(first.getValue())));
}

/**
* tan
*/
@ExecFunction(name = "tan")
public static Expression tan(DoubleLiteral first) {
return new DoubleLiteral(Math.tan(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.tan(first.getValue())));
}

/**
Expand All @@ -890,7 +881,7 @@ public static Expression asin(DoubleLiteral first) {
if (Math.abs(first.getValue()) > 1) {
return new NullLiteral(first.getDataType());
}
return new DoubleLiteral(Math.asin(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.asin(first.getValue())));
}

/**
Expand All @@ -901,23 +892,23 @@ public static Expression acos(DoubleLiteral first) {
if (Math.abs(first.getValue()) > 1) {
return new NullLiteral(first.getDataType());
}
return new DoubleLiteral(Math.acos(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.acos(first.getValue())));
}

/**
* atan
*/
@ExecFunction(name = "atan")
public static Expression atan(DoubleLiteral first) {
return new DoubleLiteral(Math.atan(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.atan(first.getValue())));
}

/**
* atan2
*/
@ExecFunction(name = "atan2")
public static Expression atan2(DoubleLiteral first, DoubleLiteral second) {
return new DoubleLiteral(Math.atan2(first.getValue(), second.getValue()));
return filterNanResult(new DoubleLiteral(Math.atan2(first.getValue(), second.getValue())));
}

/**
Expand Down Expand Up @@ -1003,23 +994,23 @@ public static Expression bitLength(StringLiteral first) {
*/
@ExecFunction(name = "cbrt")
public static Expression cbrt(DoubleLiteral first) {
return new DoubleLiteral(Math.cbrt(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.cbrt(first.getValue())));
}

/**
* cosh
*/
@ExecFunction(name = "cosh")
public static Expression cosh(DoubleLiteral first) {
return new DoubleLiteral(Math.cosh(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.cosh(first.getValue())));
}

/**
* tanh
*/
@ExecFunction(name = "cosh")
public static Expression tanh(DoubleLiteral first) {
return new DoubleLiteral(Math.tanh(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.tanh(first.getValue())));
}

/**
Expand All @@ -1028,7 +1019,7 @@ public static Expression tanh(DoubleLiteral first) {
@ExecFunction(name = "dexp")
public static Expression dexp(DoubleLiteral first) {
double exp = Math.exp(first.getValue());
return new DoubleLiteral(exp);
return filterNanResult(new DoubleLiteral(exp));
}

/**
Expand All @@ -1039,7 +1030,7 @@ public static Expression dlog1(DoubleLiteral first) {
if (first.getValue() <= 0) {
return new NullLiteral(first.getDataType());
}
return new DoubleLiteral(Math.log1p(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.log1p(first.getValue())));
}

/**
Expand All @@ -1050,7 +1041,7 @@ public static Expression dlog10(DoubleLiteral first) {
if (first.getValue() <= 0) {
return new NullLiteral(first.getDataType());
}
return new DoubleLiteral(Math.log10(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.log10(first.getValue())));
}

/**
Expand All @@ -1061,23 +1052,23 @@ public static Expression dsqrt(DoubleLiteral first) {
if (first.getValue() < 0) {
return new NullLiteral(first.getDataType());
}
return new DoubleLiteral(Math.sqrt(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.sqrt(first.getValue())));
}

/**
* dpower
*/
@ExecFunction(name = "dpow")
public static Expression dpow(DoubleLiteral first, DoubleLiteral second) {
return new DoubleLiteral(Math.pow(first.getValue(), second.getValue()));
return filterNanResult(new DoubleLiteral(Math.pow(first.getValue(), second.getValue())));
}

/**
* fmod
*/
@ExecFunction(name = "fmod")
public static Expression fmod(DoubleLiteral first, DoubleLiteral second) {
return new DoubleLiteral(first.getValue() / second.getValue());
return filterNanResult(new DoubleLiteral(first.getValue() / second.getValue()));
}

/**
Expand All @@ -1093,23 +1084,23 @@ public static Expression fmod(FloatLiteral first, FloatLiteral second) {
*/
@ExecFunction(name = "fpow")
public static Expression fpow(DoubleLiteral first, DoubleLiteral second) {
return new DoubleLiteral(Math.pow(first.getValue(), second.getValue()));
return filterNanResult(new DoubleLiteral(Math.pow(first.getValue(), second.getValue())));
}

/**
* radians
*/
@ExecFunction(name = "radians")
public static Expression radians(DoubleLiteral first) {
return new DoubleLiteral(Math.toRadians(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.toRadians(first.getValue())));
}

/**
* degrees
*/
@ExecFunction(name = "degrees")
public static Expression degrees(DoubleLiteral first) {
return new DoubleLiteral(Math.toDegrees(first.getValue()));
return filterNanResult(new DoubleLiteral(Math.toDegrees(first.getValue())));
}

/**
Expand Down
Loading

0 comments on commit a9df5e8

Please sign in to comment.