Skip to content
Closed
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 @@ -232,9 +232,10 @@ case class Ceil(child: Expression) extends UnaryMathExpression(math.ceil, "CEIL"
}

override def inputTypes: Seq[AbstractDataType] =
Seq(TypeCollection(DoubleType, DecimalType))
Seq(TypeCollection(LongType, DoubleType, DecimalType))

protected override def nullSafeEval(input: Any): Any = child.dataType match {
case LongType => input.asInstanceOf[Long]
case DoubleType => f(input.asInstanceOf[Double]).toLong
case DecimalType.Fixed(precision, scale) => input.asInstanceOf[Decimal].ceil
}
Expand Down Expand Up @@ -347,9 +348,10 @@ case class Floor(child: Expression) extends UnaryMathExpression(math.floor, "FLO
}

override def inputTypes: Seq[AbstractDataType] =
Seq(TypeCollection(DoubleType, DecimalType))
Seq(TypeCollection(LongType, DoubleType, DecimalType))

protected override def nullSafeEval(input: Any): Any = child.dataType match {
case LongType => input.asInstanceOf[Long]
case DoubleType => f(input.asInstanceOf[Double]).toLong
case DecimalType.Fixed(precision, scale) => input.asInstanceOf[Decimal].floor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class AnalysisSuite extends AnalysisTest with ShouldMatchers {

val plan = testRelation2.select('c).orderBy(Floor('a).asc)
val expected = testRelation2.select(c, a)
.orderBy(Floor(Cast(a, DoubleType, Option(TimeZone.getDefault().getID))).asc).select(c)
.orderBy(Floor(Cast(a, LongType, Option(TimeZone.getDefault().getID))).asc).select(c)

checkAnalysis(plan, expected)
}
Expand Down
14 changes: 14 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/operators.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,17 @@ select cot(1);
select cot(null);
select cot(0);
select cot(-1);

-- ceil and ceiling
select ceiling(0);
select ceiling(1);
select ceil(1234567890123456);
select ceil(12345678901234567);
select ceiling(1234567890123456);
select ceiling(12345678901234567);

-- floor
select floor(0);
select floor(1);
select floor(1234567890123456);
select floor(12345678901234567);
80 changes: 80 additions & 0 deletions sql/core/src/test/resources/sql-tests/results/operators.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,83 @@ select cot(-1)
struct<COT(CAST(-1 AS DOUBLE)):double>
-- !query 37 output
-0.6420926159343306


-- !query 38
select ceiling(0)
-- !query 38 schema
struct<CEIL(CAST(0 AS BIGINT)):bigint>
-- !query 38 output
0


-- !query 39
select ceiling(1)
-- !query 39 schema
struct<CEIL(CAST(1 AS BIGINT)):bigint>
-- !query 39 output
1


-- !query 40
select ceil(1234567890123456)
-- !query 40 schema
struct<CEIL(1234567890123456):bigint>
-- !query 40 output
1234567890123456


-- !query 41
select ceil(12345678901234567)
-- !query 41 schema
struct<CEIL(12345678901234567):bigint>
-- !query 41 output
12345678901234567


-- !query 42
select ceiling(1234567890123456)
-- !query 42 schema
struct<CEIL(1234567890123456):bigint>
-- !query 42 output
1234567890123456


-- !query 43
select ceiling(12345678901234567)
-- !query 43 schema
struct<CEIL(12345678901234567):bigint>
-- !query 43 output
12345678901234567


-- !query 44
select floor(0)
-- !query 44 schema
struct<FLOOR(CAST(0 AS BIGINT)):bigint>
-- !query 44 output
0


-- !query 45
select floor(1)
-- !query 45 schema
struct<FLOOR(CAST(1 AS BIGINT)):bigint>
-- !query 45 output
1


-- !query 46
select floor(1234567890123456)
-- !query 46 schema
struct<FLOOR(1234567890123456):bigint>
-- !query 46 output
1234567890123456


-- !query 47
select floor(12345678901234567)
-- !query 47 schema
struct<FLOOR(12345678901234567):bigint>
-- !query 47 output
12345678901234567