@@ -558,8 +558,8 @@ case class Round(child: Expression, scale: Expression) extends Expression {
558558 return TypeCheckFailure (" ROUND scale argument out of allowed range" )
559559 }
560560 case Literal (_, _ : IntegralType ) | Literal (_, NullType ) => // satisfy requirement
561- case child =>
562- if (child.find { case _ : AttributeReference => true ; case _ => false } != None ) {
561+ case _ =>
562+ if (! scale.foldable ) {
563563 return TypeCheckFailure (" Only Integral Literal or Null Literal " +
564564 s " are allowed for ROUND scale arguments, got ${child.dataType}" )
565565 }
@@ -595,6 +595,21 @@ case class Round(child: Expression, scale: Expression) extends Expression {
595595 }
596596 }
597597
598+ private def round [T ](input : T , scale : Int )(implicit bdc : BigDecimalConverter [T ]): T = {
599+ input match {
600+ case f : Float if (f.isNaN || f.isInfinite) => return input
601+ case d : Double if (d.isNaN || d.isInfinite) => return input
602+ case _ =>
603+ }
604+ bdc.fromBigDecimal(bdc.toBigDecimal(input).setScale(scale, BigDecimal .RoundingMode .HALF_UP ))
605+ }
606+
607+ private def round (input : String , scale : Int ): Any = {
608+ try round(input.toDouble, scale) catch {
609+ case _ : NumberFormatException => null
610+ }
611+ }
612+
598613 override def genCode (ctx : CodeGenContext , ev : GeneratedExpressionCode ): String = {
599614 val ce = child.gen(ctx)
600615
@@ -672,19 +687,4 @@ case class Round(child: Expression, scale: Expression) extends Expression {
672687 }
673688 """
674689 }
675-
676- private def round [T ](input : T , scale : Int )(implicit bdc : BigDecimalConverter [T ]): T = {
677- input match {
678- case f : Float if (f.isNaN || f.isInfinite) => return input
679- case d : Double if (d.isNaN || d.isInfinite) => return input
680- case _ =>
681- }
682- bdc.fromBigDecimal(bdc.toBigDecimal(input).setScale(scale, BigDecimal .RoundingMode .HALF_UP ))
683- }
684-
685- private def round (input : String , scale : Int ): Any = {
686- try round(input.toDouble, scale) catch {
687- case _ : NumberFormatException => null
688- }
689- }
690690}
0 commit comments