Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -704,15 +704,16 @@ private static Expression castDecimalV3Literal(DecimalV3Literal literal, int pre
*/
@ExecFunction(name = "round")
public static Expression round(DecimalV3Literal first) {
return castDecimalV3Literal(first.round(0), first.getValue().precision());
return castDecimalV3Literal(first.round(0), ((DecimalV3Type) first.getDataType()).getPrecision());
}

/**
* round
*/
@ExecFunction(name = "round")
public static Expression round(DecimalV3Literal first, IntegerLiteral second) {
return castDecimalV3Literal(first.round(second.getValue()), first.getValue().precision());
return castDecimalV3Literal(first.round(second.getValue()),
((DecimalV3Type) first.getDataType()).getPrecision());
}

/**
Expand All @@ -738,15 +739,16 @@ public static Expression round(DoubleLiteral first, IntegerLiteral second) {
*/
@ExecFunction(name = "ceil")
public static Expression ceil(DecimalV3Literal first) {
return castDecimalV3Literal(first.roundCeiling(0), first.getValue().precision());
return castDecimalV3Literal(first.roundCeiling(0), ((DecimalV3Type) first.getDataType()).getPrecision());
}

/**
* ceil
*/
@ExecFunction(name = "ceil")
public static Expression ceil(DecimalV3Literal first, IntegerLiteral second) {
return castDecimalV3Literal(first.roundCeiling(second.getValue()), first.getValue().precision());
return castDecimalV3Literal(first.roundCeiling(second.getValue()),
((DecimalV3Type) first.getDataType()).getPrecision());
}

/**
Expand All @@ -772,15 +774,16 @@ public static Expression ceil(DoubleLiteral first, IntegerLiteral second) {
*/
@ExecFunction(name = "floor")
public static Expression floor(DecimalV3Literal first) {
return castDecimalV3Literal(first.roundFloor(0), first.getValue().precision());
return castDecimalV3Literal(first.roundFloor(0), ((DecimalV3Type) first.getDataType()).getPrecision());
}

/**
* floor
*/
@ExecFunction(name = "floor")
public static Expression floor(DecimalV3Literal first, IntegerLiteral second) {
return castDecimalV3Literal(first.roundFloor(second.getValue()), first.getValue().precision());
return castDecimalV3Literal(first.roundFloor(second.getValue()),
((DecimalV3Type) first.getDataType()).getPrecision());
}

/**
Expand Down Expand Up @@ -1142,9 +1145,11 @@ public static Expression truncate(DecimalV3Literal first, IntegerLiteral second)
if (first.getValue().compareTo(BigDecimal.ZERO) == 0) {
return first;
} else if (first.getValue().compareTo(BigDecimal.ZERO) < 0) {
return castDecimalV3Literal(first.roundCeiling(second.getValue()), first.getValue().precision());
return castDecimalV3Literal(first.roundCeiling(second.getValue()),
((DecimalV3Type) first.getDataType()).getPrecision());
} else {
return castDecimalV3Literal(first.roundFloor(second.getValue()), first.getValue().precision());
return castDecimalV3Literal(first.roundFloor(second.getValue()),
((DecimalV3Type) first.getDataType()).getPrecision());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,13 @@ test {
testFoldConst("with cte as (select round(300.343, -4) order by 1 limit 1) select * from cte")
testFoldConst("with cte as (select ceil(300.343, -4) order by 1 limit 1) select * from cte")
testFoldConst("with cte as (select truncate(300.343, -4) order by 1 limit 1) select * from cte")

testFoldConst("with cte as (select floor(3) order by 1 limit 1) select * from cte")
testFoldConst("with cte as (select round(3) order by 1 limit 1) select * from cte")
testFoldConst("with cte as (select ceil(3) order by 1 limit 1) select * from cte")

testFoldConst("with cte as (select floor(3, 2) order by 1 limit 1) select * from cte")
testFoldConst("with cte as (select round(3, 2) order by 1 limit 1) select * from cte")
testFoldConst("with cte as (select ceil(3, 2) order by 1 limit 1) select * from cte")
testFoldConst("with cte as (select truncate(3, 2) order by 1 limit 1) select * from cte")
}